@@ -31,7 +31,28 @@ module TaintedPath {
3131 /**
3232 * A barrier guard for tainted-path vulnerabilities.
3333 */
34- abstract class BarrierGuardNode extends DataFlow:: LabeledBarrierGuardNode { }
34+ abstract class BarrierGuard extends DataFlow:: Node {
35+ /**
36+ * Holds if this node acts as a barrier for data flow, blocking further flow from `e` if `this` evaluates to `outcome`.
37+ */
38+ predicate blocksExpr ( boolean outcome , Expr e ) { none ( ) }
39+
40+ /**
41+ * Holds if this node acts as a barrier for `label`, blocking further flow from `e` if `this` evaluates to `outcome`.
42+ */
43+ predicate blocksExpr ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) { none ( ) }
44+ }
45+
46+ /** A subclass of `BarrierGuard` that is used for backward compatibility with the old data flow library. */
47+ abstract class BarrierGuardLegacy extends BarrierGuard , TaintTracking:: SanitizerGuardNode {
48+ override predicate sanitizes ( boolean outcome , Expr e ) { this .blocksExpr ( outcome , e ) }
49+
50+ override predicate sanitizes ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
51+ this .blocksExpr ( outcome , e , label )
52+ }
53+ }
54+
55+ deprecated class BarrierGuardNode = BarrierGuard ;
3556
3657 module Label {
3758 /**
@@ -345,10 +366,10 @@ module TaintedPath {
345366 *
346367 * This is relevant for paths that are known to be normalized.
347368 */
348- class StartsWithDotDotSanitizer extends BarrierGuardNode instanceof StringOps:: StartsWith {
369+ class StartsWithDotDotSanitizer extends BarrierGuard instanceof StringOps:: StartsWith {
349370 StartsWithDotDotSanitizer ( ) { isDotDotSlashPrefix ( super .getSubstring ( ) ) }
350371
351- override predicate blocks ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
372+ override predicate blocksExpr ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
352373 // Sanitize in the false case for:
353374 // .startsWith(".")
354375 // .startsWith("..")
@@ -365,12 +386,12 @@ module TaintedPath {
365386 /**
366387 * A check of the form `whitelist.includes(x)` or equivalent, which sanitizes `x` in its "then" branch.
367388 */
368- class MembershipTestBarrierGuard extends BarrierGuardNode {
389+ class MembershipTestBarrierGuard extends BarrierGuard {
369390 MembershipCandidate candidate ;
370391
371392 MembershipTestBarrierGuard ( ) { this = candidate .getTest ( ) }
372393
373- override predicate blocks ( boolean outcome , Expr e ) {
394+ override predicate blocksExpr ( boolean outcome , Expr e ) {
374395 candidate = e .flow ( ) and
375396 candidate .getTestPolarity ( ) = outcome
376397 }
@@ -380,7 +401,7 @@ module TaintedPath {
380401 * A check of form `x.startsWith(dir)` that sanitizes normalized absolute paths, since it is then
381402 * known to be in a subdirectory of `dir`.
382403 */
383- class StartsWithDirSanitizer extends BarrierGuardNode {
404+ class StartsWithDirSanitizer extends BarrierGuard {
384405 StringOps:: StartsWith startsWith ;
385406
386407 StartsWithDirSanitizer ( ) {
@@ -390,7 +411,7 @@ module TaintedPath {
390411 not startsWith .getSubstring ( ) .getStringValue ( ) = "/"
391412 }
392413
393- override predicate blocks ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
414+ override predicate blocksExpr ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
394415 outcome = startsWith .getPolarity ( ) and
395416 e = startsWith .getBaseString ( ) .asExpr ( ) and
396417 exists ( Label:: PosixPath posixPath | posixPath = label |
@@ -404,7 +425,7 @@ module TaintedPath {
404425 * A call to `path.isAbsolute` as a sanitizer for relative paths in true branch,
405426 * and a sanitizer for absolute paths in the false branch.
406427 */
407- class IsAbsoluteSanitizer extends BarrierGuardNode {
428+ class IsAbsoluteSanitizer extends BarrierGuard {
408429 DataFlow:: Node operand ;
409430 boolean polarity ;
410431 boolean negatable ;
@@ -425,7 +446,7 @@ module TaintedPath {
425446 ) // !x.startsWith("/home") does not guarantee that x is not absolute
426447 }
427448
428- override predicate blocks ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
449+ override predicate blocksExpr ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
429450 e = operand .asExpr ( ) and
430451 exists ( Label:: PosixPath posixPath | posixPath = label |
431452 outcome = polarity and posixPath .isRelative ( )
@@ -440,10 +461,10 @@ module TaintedPath {
440461 /**
441462 * An expression of form `x.includes("..")` or similar.
442463 */
443- class ContainsDotDotSanitizer extends BarrierGuardNode instanceof StringOps:: Includes {
464+ class ContainsDotDotSanitizer extends BarrierGuard instanceof StringOps:: Includes {
444465 ContainsDotDotSanitizer ( ) { isDotDotSlashPrefix ( super .getSubstring ( ) ) }
445466
446- override predicate blocks ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
467+ override predicate blocksExpr ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
447468 e = super .getBaseString ( ) .asExpr ( ) and
448469 outcome = super .getPolarity ( ) .booleanNot ( ) and
449470 label .( Label:: PosixPath ) .canContainDotDotSlash ( ) // can still be bypassed by normalized absolute path
@@ -453,10 +474,10 @@ module TaintedPath {
453474 /**
454475 * An expression of form `x.matches(/\.\./)` or similar.
455476 */
456- class ContainsDotDotRegExpSanitizer extends BarrierGuardNode instanceof StringOps:: RegExpTest {
477+ class ContainsDotDotRegExpSanitizer extends BarrierGuard instanceof StringOps:: RegExpTest {
457478 ContainsDotDotRegExpSanitizer ( ) { super .getRegExp ( ) .getAMatchedString ( ) = [ "." , ".." , "../" ] }
458479
459- override predicate blocks ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
480+ override predicate blocksExpr ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
460481 e = super .getStringOperand ( ) .asExpr ( ) and
461482 outcome = super .getPolarity ( ) .booleanNot ( ) and
462483 label .( Label:: PosixPath ) .canContainDotDotSlash ( ) // can still be bypassed by normalized absolute path
@@ -484,7 +505,7 @@ module TaintedPath {
484505 * }
485506 * ```
486507 */
487- class RelativePathStartsWithSanitizer extends BarrierGuardNode {
508+ class RelativePathStartsWithSanitizer extends BarrierGuard {
488509 StringOps:: StartsWith startsWith ;
489510 DataFlow:: CallNode pathCall ;
490511 string member ;
@@ -506,7 +527,7 @@ module TaintedPath {
506527 ( not member = "relative" or isDotDotSlashPrefix ( startsWith .getSubstring ( ) ) )
507528 }
508529
509- override predicate blocks ( boolean outcome , Expr e ) {
530+ override predicate blocksExpr ( boolean outcome , Expr e ) {
510531 member = "relative" and
511532 e = this .maybeGetPathSuffix ( pathCall .getArgument ( 1 ) ) .asExpr ( ) and
512533 outcome = startsWith .getPolarity ( ) .booleanNot ( )
@@ -542,7 +563,7 @@ module TaintedPath {
542563 * An expression of form `isInside(x, y)` or similar, where `isInside` is
543564 * a library check for the relation between `x` and `y`.
544565 */
545- class IsInsideCheckSanitizer extends BarrierGuardNode {
566+ class IsInsideCheckSanitizer extends BarrierGuard {
546567 DataFlow:: Node checked ;
547568 boolean onlyNormalizedAbsolutePaths ;
548569
@@ -558,7 +579,7 @@ module TaintedPath {
558579 )
559580 }
560581
561- override predicate blocks ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
582+ override predicate blocksExpr ( boolean outcome , Expr e , DataFlow:: FlowLabel label ) {
562583 (
563584 onlyNormalizedAbsolutePaths = true and
564585 label .( Label:: PosixPath ) .isNormalized ( ) and
@@ -750,8 +771,6 @@ module TaintedPath {
750771 )
751772 )
752773 or
753- TaintTracking:: promiseStep ( src , dst ) and srclabel = dstlabel
754- or
755774 TaintTracking:: persistentStorageStep ( src , dst ) and srclabel = dstlabel
756775 or
757776 exists ( DataFlow:: PropRead read | read = dst |
0 commit comments