@@ -2,42 +2,48 @@ import javascript
22import semmle.javascript.security.dataflow.RequestForgeryCustomizations
33import semmle.javascript.security.dataflow.UrlConcatenation
44
5- class Configuration extends TaintTracking:: Configuration {
6- Configuration ( ) { this = "SSRF" }
7-
8- override predicate isSource ( DataFlow:: Node source ) { source instanceof RequestForgery:: Source }
5+ module SsrfConfig implements DataFlow:: ConfigSig {
6+ predicate isSource ( DataFlow:: Node source ) { source instanceof RequestForgery:: Source }
97
10- override predicate isSink ( DataFlow:: Node sink ) { sink instanceof RequestForgery:: Sink }
8+ predicate isSink ( DataFlow:: Node sink ) { sink instanceof RequestForgery:: Sink }
119
12- override predicate isSanitizer ( DataFlow:: Node node ) {
13- super .isSanitizer ( node ) or
14- node instanceof RequestForgery:: Sanitizer
10+ predicate isBarrier ( DataFlow:: Node node ) {
11+ node instanceof RequestForgery:: Sanitizer or node = Guards:: getABarrierNode ( )
1512 }
1613
1714 private predicate hasSanitizingSubstring ( DataFlow:: Node nd ) {
1815 nd .getStringValue ( ) .regexpMatch ( ".*[?#].*" )
1916 or
20- this . hasSanitizingSubstring ( StringConcatenation:: getAnOperand ( nd ) )
17+ hasSanitizingSubstring ( StringConcatenation:: getAnOperand ( nd ) )
2118 or
22- this . hasSanitizingSubstring ( nd .getAPredecessor ( ) )
19+ hasSanitizingSubstring ( nd .getAPredecessor ( ) )
2320 }
2421
2522 private predicate strictSanitizingPrefixEdge ( DataFlow:: Node source , DataFlow:: Node sink ) {
2623 exists ( DataFlow:: Node operator , int n |
2724 StringConcatenation:: taintStep ( source , sink , operator , n ) and
28- this . hasSanitizingSubstring ( StringConcatenation:: getOperand ( operator , [ 0 .. n - 1 ] ) )
25+ hasSanitizingSubstring ( StringConcatenation:: getOperand ( operator , [ 0 .. n - 1 ] ) )
2926 )
3027 }
3128
32- override predicate isSanitizerOut ( DataFlow:: Node node ) {
33- this .strictSanitizingPrefixEdge ( node , _)
34- }
29+ predicate isBarrierOut ( DataFlow:: Node node ) { strictSanitizingPrefixEdge ( node , _) }
3530
36- override predicate isSanitizerGuard ( TaintTracking :: SanitizerGuardNode nd ) {
31+ private predicate isBarrierGuard ( DataFlow :: BarrierGuardNode nd ) {
3732 nd instanceof IntegerCheck or
3833 nd instanceof ValidatorCheck or
3934 nd instanceof TernaryOperatorSanitizerGuard
4035 }
36+
37+ private module Guards = DataFlow:: MakeLegacyBarrierGuard< isBarrierGuard / 1 > ;
38+ }
39+
40+ module SsrfFlow = TaintTracking:: Global< SsrfConfig > ;
41+
42+ /**
43+ * DEPRECATED. Use the `SsrfFlow` module instead.
44+ */
45+ deprecated class Configuration extends TaintTracking:: Configuration {
46+ Configuration ( ) { this = "SSRF" }
4147}
4248
4349/**
@@ -104,7 +110,9 @@ class TernaryOperatorSanitizerGuard extends TaintTracking::SanitizerGuardNode {
104110 not this .asExpr ( ) instanceof LogicalBinaryExpr
105111 }
106112
107- override predicate sanitizes ( boolean outcome , Expr e ) {
113+ override predicate sanitizes ( boolean outcome , Expr e ) { this .blocksExpr ( outcome , e ) }
114+
115+ predicate blocksExpr ( boolean outcome , Expr e ) {
108116 not this .asExpr ( ) instanceof LogNotExpr and
109117 originalGuard .sanitizes ( outcome , e )
110118 or
@@ -126,7 +134,9 @@ class TernaryOperatorSanitizerGuard extends TaintTracking::SanitizerGuardNode {
126134class IntegerCheck extends TaintTracking:: SanitizerGuardNode , DataFlow:: CallNode {
127135 IntegerCheck ( ) { this = DataFlow:: globalVarRef ( "Number" ) .getAMemberCall ( "isInteger" ) }
128136
129- override predicate sanitizes ( boolean outcome , Expr e ) {
137+ override predicate sanitizes ( boolean outcome , Expr e ) { this .blocksExpr ( outcome , e ) }
138+
139+ predicate blocksExpr ( boolean outcome , Expr e ) {
130140 outcome = true and
131141 e = this .getArgument ( 0 ) .asExpr ( )
132142 }
@@ -149,7 +159,9 @@ class ValidatorCheck extends TaintTracking::SanitizerGuardNode, DataFlow::CallNo
149159 )
150160 }
151161
152- override predicate sanitizes ( boolean outcome , Expr e ) {
162+ override predicate sanitizes ( boolean outcome , Expr e ) { this .blocksExpr ( outcome , e ) }
163+
164+ predicate blocksExpr ( boolean outcome , Expr e ) {
153165 outcome = true and
154166 e = this .getArgument ( 0 ) .asExpr ( )
155167 }
0 commit comments