File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
lib/semmle/code/csharp/security/dataflow
test/query-tests/Security Features/CWE-601/UrlRedirect Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,28 @@ class LocalUrlSanitizer extends Sanitizer {
139
139
LocalUrlSanitizer ( ) { this = DataFlow:: BarrierGuard< isLocalUrlSanitizer / 3 > :: getABarrierNode ( ) }
140
140
}
141
141
142
+ /**
143
+ * A argument to a call to `List.Contains()` that is a sanitizer for URL redirects.
144
+ */
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
+ )
153
+ }
154
+
155
+ /**
156
+ * A URL argument to a call to `List.Contains()` that is a sanitizer for URL redirects.
157
+ */
158
+ class ContainsUrlSanitizer extends Sanitizer {
159
+ ContainsUrlSanitizer ( ) {
160
+ this = DataFlow:: BarrierGuard< isContainsUrlSanitizer / 3 > :: getABarrierNode ( )
161
+ }
162
+ }
163
+
142
164
/**
143
165
* A call to the getter of the RawUrl property, whose value is considered to be safe for URL
144
166
* redirects.
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ public void ProcessRequest(HttpContext ctx)
14
14
ctx . Response . Redirect ( ctx . Request . QueryString [ "page" ] ) ;
15
15
16
16
List < string > VALID_REDIRECTS = new List < string > { "http://cwe.mitre.org/data/definitions/601.html" , "http://cwe.mitre.org/data/definitions/79.html" } ;
17
+ var redirectUrl = ctx . Request . QueryString [ "page" ] ;
18
+ if ( VALID_REDIRECTS . Contains ( redirectUrl ) )
19
+ {
20
+ // GOOD: the request parameter is validated against set of known fixed strings
21
+ ctx . Response . Redirect ( redirectUrl ) ;
22
+ }
17
23
18
24
}
19
25
}
You can’t perform that action at this time.
0 commit comments