@@ -140,20 +140,24 @@ class LocalUrlSanitizer extends Sanitizer {
140
140
}
141
141
142
142
/**
143
- * A argument to a call to `List.Contains()` that is a sanitizer for URL redirects.
143
+ * An argument to a call to `List.Contains()` that is a sanitizer for URL redirects.
144
144
*/
145
145
private predicate isContainsUrlSanitizer ( Guard guard , Expr e , AbstractValue v ) {
146
- exists ( MethodCall method | method = guard |
147
- exists ( Method m | m = method .getTarget ( ) |
148
- m .hasName ( "Contains" ) and
149
- e = method .getArgument ( 0 )
150
- ) and
151
- v .( AbstractValues:: BooleanValue ) .getValue ( ) = true
152
- )
146
+ guard =
147
+ any ( MethodCall method |
148
+ exists ( Method m | m = method .getTarget ( ) |
149
+ m .hasName ( "Contains" ) and
150
+ e = method .getArgument ( 0 )
151
+ ) and
152
+ v .( AbstractValues:: BooleanValue ) .getValue ( ) = true
153
+ )
153
154
}
154
155
155
156
/**
156
- * A URL argument to a call to `List.Contains()` that is a sanitizer for URL redirects.
157
+ * An URL argument to a call to `.Contains()` that is a sanitizer for URL redirects.
158
+ *
159
+ * This `Contains` method is usually called on a list, but the sanitizer matches any call to a method
160
+ * called `Contains`, so other methods with the same name will also be considered sanitizers.
157
161
*/
158
162
class ContainsUrlSanitizer extends Sanitizer {
159
163
ContainsUrlSanitizer ( ) {
@@ -165,12 +169,12 @@ class ContainsUrlSanitizer extends Sanitizer {
165
169
* A check that the URL is relative, and therefore safe for URL redirects.
166
170
*/
167
171
private predicate isRelativeUrlSanitizer ( Guard guard , Expr e , AbstractValue v ) {
168
- exists ( PropertyAccess access | access = guard |
169
- access . getProperty ( ) . getName ( ) = "IsAbsoluteUri" and
170
- access .getQualifier ( ) .getType ( ) . getFullyQualifiedName ( ) = "System. Uri" and
171
- e = access .getQualifier ( ) and
172
- v .( AbstractValues:: BooleanValue ) .getValue ( ) = false
173
- )
172
+ guard =
173
+ any ( PropertyAccess access |
174
+ access .getProperty ( ) .hasFullyQualifiedName ( "System" , " Uri", "IsAbsoluteUri" ) and
175
+ e = access .getQualifier ( ) and
176
+ v .( AbstractValues:: BooleanValue ) .getValue ( ) = false
177
+ )
174
178
}
175
179
176
180
/**
@@ -187,16 +191,16 @@ class RelativeUrlSanitizer extends Sanitizer {
187
191
* E.g. `url.Host == "example.org"`
188
192
*/
189
193
private predicate isHostComparisonSanitizer ( Guard guard , Expr e , AbstractValue v ) {
190
- exists ( EqualityOperation comparison | comparison = guard |
191
- exists ( PropertyAccess access | access = comparison . getAnOperand ( ) |
192
- access . getProperty ( ) . getName ( ) = "Host" and
193
- access .getQualifier ( ) .getType ( ) . getFullyQualifiedName ( ) = "System. Uri" and
194
- e = access .getQualifier ( )
195
- ) and
196
- if comparison instanceof EQExpr
197
- then v .( AbstractValues:: BooleanValue ) .getValue ( ) = true
198
- else v .( AbstractValues:: BooleanValue ) .getValue ( ) = false
199
- )
194
+ guard =
195
+ any ( EqualityOperation comparison |
196
+ exists ( PropertyAccess access | access = comparison . getAnOperand ( ) |
197
+ access .getProperty ( ) .hasFullyQualifiedName ( "System" , " Uri", "Host" ) and
198
+ e = access .getQualifier ( )
199
+ ) and
200
+ if comparison instanceof EQExpr
201
+ then v .( AbstractValues:: BooleanValue ) .getValue ( ) = true
202
+ else v .( AbstractValues:: BooleanValue ) .getValue ( ) = false
203
+ )
200
204
}
201
205
202
206
/**
0 commit comments