File tree Expand file tree Collapse file tree 2 files changed +36
-13
lines changed
lib/semmle/code/java/dataflow/internal Expand file tree Collapse file tree 2 files changed +36
-13
lines changed Original file line number Diff line number Diff line change @@ -304,6 +304,33 @@ class ContentSet instanceof Content {
304
304
}
305
305
}
306
306
307
+ /**
308
+ * Holds if the guard `g` validates the expression `e` upon evaluating to `branch`.
309
+ *
310
+ * The expression `e` is expected to be a syntactic part of the guard `g`.
311
+ * For example, the guard `g` might be a call `isSafe(x)` and the expression `e`
312
+ * the argument `x`.
313
+ */
314
+ signature predicate guardChecksSig ( Guard g , Expr e , boolean branch ) ;
315
+
316
+ /**
317
+ * Provides a set of barrier nodes for a guard that validates an expression.
318
+ *
319
+ * This is expected to be used in `isBarrier`/`isSanitizer` definitions
320
+ * in data flow and taint tracking.
321
+ */
322
+ module BarrierGuard< guardChecksSig / 3 guardChecks> {
323
+ /** Gets a node that is safely guarded by the given guard check. */
324
+ Node getABarrierNode ( ) {
325
+ exists ( Guard g , SsaVariable v , boolean branch , RValue use |
326
+ guardChecks ( g , v .getAUse ( ) , branch ) and
327
+ use = v .getAUse ( ) and
328
+ g .controls ( use .getBasicBlock ( ) , branch ) and
329
+ result .asExpr ( ) = use
330
+ )
331
+ }
332
+ }
333
+
307
334
/**
308
335
* A guard that validates some expression.
309
336
*
Original file line number Diff line number Diff line change @@ -19,15 +19,13 @@ import semmle.code.java.security.PathCreation
19
19
import DataFlow:: PathGraph
20
20
import TaintedPathCommon
21
21
22
- class ContainsDotDotSanitizer extends DataFlow:: BarrierGuard {
23
- ContainsDotDotSanitizer ( ) {
24
- this .( MethodAccess ) .getMethod ( ) .hasName ( "contains" ) and
25
- this .( MethodAccess ) .getAnArgument ( ) .( StringLiteral ) .getValue ( ) = ".."
26
- }
27
-
28
- override predicate checks ( Expr e , boolean branch ) {
29
- e = this .( MethodAccess ) .getQualifier ( ) and branch = false
30
- }
22
+ predicate containsDotDotSanitizer ( Guard g , Expr e , boolean branch ) {
23
+ exists ( MethodAccess contains | g = contains |
24
+ contains .getMethod ( ) .hasName ( "contains" ) and
25
+ contains .getAnArgument ( ) .( StringLiteral ) .getValue ( ) = ".." and
26
+ e = contains .getQualifier ( ) and
27
+ branch = false
28
+ )
31
29
}
32
30
33
31
class TaintedPathConfig extends TaintTracking:: Configuration {
@@ -41,10 +39,8 @@ class TaintedPathConfig extends TaintTracking::Configuration {
41
39
42
40
override predicate isSanitizer ( DataFlow:: Node node ) {
43
41
exists ( Type t | t = node .getType ( ) | t instanceof BoxedType or t instanceof PrimitiveType )
44
- }
45
-
46
- override predicate isSanitizerGuard ( DataFlow:: BarrierGuard guard ) {
47
- guard instanceof ContainsDotDotSanitizer
42
+ or
43
+ node = DataFlow:: BarrierGuard< containsDotDotSanitizer / 3 > :: getABarrierNode ( )
48
44
}
49
45
}
50
46
You can’t perform that action at this time.
0 commit comments