Skip to content

Java/C++/C#: Add support for BarrierGuards.#1718

Merged
yh-semmle merged 4 commits intogithub:masterfrom
aschackmull:java/barrierguard
Aug 13, 2019
Merged

Java/C++/C#: Add support for BarrierGuards.#1718
yh-semmle merged 4 commits intogithub:masterfrom
aschackmull:java/barrierguard

Conversation

@aschackmull
Copy link
Contributor

This adds support for BarrierGuards similar to the JavaScript dataflow library. Currently the C# and C++ classes are just stubs, so BarrierGuards won't work there just yet.
This doesn't add any new functionality to dataflow, but makes it easier to specify barriers/sanitizers that arise from guards. In particular it is unnecessary to know about things like SSA variables or the concept of a guard controlling a basicblock.
As an example, the TaintedPath query has been supplied with a !var.contains("..") sanitizer.

@aschackmull
Copy link
Contributor Author

This PR also fixes #1416.

jbj
jbj previously approved these changes Aug 9, 2019
* characteristic predicate precisely specifying the guard, and override
* `checks` to specify what is being validated and in which branch.
*
* It is important that all extending classes in scope are disjoint.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xiemaisi Did you know about this issue? It should affect JavaScript too, but we couldn't find a non-contrived example where it would make a difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The worst we could come up with was something like this:

var.regexMatches(safePattern)
var.regexMatches(patternToFindBadStuff)

If the two BarrierGuards describing those two case were sufficiently loosely described in the charpreds, such that there might exist regex patterns that fell into both, then you'd get into trouble when using either as a sanitizer if both were in scope (say from some barrier guard library).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I hadn't previously considered it, and it hasn't caused us any problems, but we should probably call it out in our API docs as well. Thanks for flagging it up.

Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small comments.

import PathsCommon
import DataFlow::PathGraph

class ContainsDotDotSanitizer extends DataFlow::BarrierGuard {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not extend MethodAccess?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did initially, but then you get a couple of methods like getEnclosingCallable() that are ambiguously inherited, which means that we'll have to add additional overrides to the class.
Now if only QL allowed us to declare membership of a class without affecting dispatch...

/** Holds if this guard validates `e` upon evaluating to `branch`. */
abstract predicate checks(Expr e, boolean branch);

/** Gets a node guarded by this. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this -> this guard? (Same for other languages.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, why not.

hvitved
hvitved previously approved these changes Aug 12, 2019
yh-semmle
yh-semmle previously approved these changes Aug 12, 2019
@yh-semmle
Copy link
Contributor

Perhaps add a release note for #1416, since this was a user-reported FP?

@aschackmull aschackmull dismissed stale reviews from yh-semmle and hvitved via c99d0e7 August 13, 2019 15:00
@aschackmull
Copy link
Contributor Author

Added change note for the java/path-injection improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants