@@ -25,7 +25,10 @@ abstract class Sink extends ApiSinkExprNode { }
25
25
/**
26
26
* A sanitizer for uncontrolled data in path expression vulnerabilities.
27
27
*/
28
- abstract class Sanitizer extends DataFlow:: ExprNode { }
28
+ abstract class Sanitizer extends DataFlow:: ExprNode {
29
+ /** Holds if this is a sanitizer when the flow state is `state`. */
30
+ predicate isBarrier ( TaintedPathConfig:: FlowState state ) { any ( ) }
31
+ }
29
32
30
33
/** A path normalization step. */
31
34
private class PathNormalizationStep extends Unit {
@@ -141,7 +144,7 @@ class StreamWriterTaintedPathSink extends Sink {
141
144
}
142
145
143
146
/**
144
- * A weak guard that is insufficient to prevent path tampering.
147
+ * A weak guard that may be insufficient to prevent path tampering.
145
148
*/
146
149
private class WeakGuard extends Guard {
147
150
WeakGuard ( ) {
@@ -160,6 +163,14 @@ private class WeakGuard extends Guard {
160
163
or
161
164
this .( LogicalOperation ) .getAnOperand ( ) instanceof WeakGuard
162
165
}
166
+
167
+ predicate isBarrier ( TaintedPathConfig:: FlowState state ) {
168
+ state = TaintedPathConfig:: Normalized ( ) and
169
+ exists ( Method m | this .( MethodCall ) .getTarget ( ) = m |
170
+ m .getName ( ) = "StartsWith" or
171
+ m .getName ( ) = "EndsWith"
172
+ )
173
+ }
163
174
}
164
175
165
176
/**
@@ -168,12 +179,17 @@ private class WeakGuard extends Guard {
168
179
* A weak check is one that is insufficient to prevent path tampering.
169
180
*/
170
181
class PathCheck extends Sanitizer {
182
+ Guard g ;
183
+
171
184
PathCheck ( ) {
172
- // This expression is structurally replicated in a dominating guard which is not a "weak" check
173
- exists ( Guard g , AbstractValues:: BooleanValue v |
174
- g = this .( GuardedDataFlowNode ) .getAGuard ( _, v ) and
175
- not g instanceof WeakGuard
176
- )
185
+ // This expression is structurally replicated in a dominating guard
186
+ exists ( AbstractValues:: BooleanValue v | g = this .( GuardedDataFlowNode ) .getAGuard ( _, v ) )
187
+ }
188
+
189
+ override predicate isBarrier ( TaintedPathConfig:: FlowState state ) {
190
+ g .( WeakGuard ) .isBarrier ( state )
191
+ or
192
+ not g instanceof WeakGuard
177
193
}
178
194
}
179
195
0 commit comments