File tree Expand file tree Collapse file tree
lib/semmle/code/csharp/security/dataflow
test/query-tests/Security Features/CWE-601/UrlRedirect Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,6 +139,28 @@ class LocalUrlSanitizer extends Sanitizer {
139139 LocalUrlSanitizer ( ) { this = DataFlow:: BarrierGuard< isLocalUrlSanitizer / 3 > :: getABarrierNode ( ) }
140140}
141141
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+
142164/**
143165 * A call to the getter of the RawUrl property, whose value is considered to be safe for URL
144166 * redirects.
Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ public void ProcessRequest(HttpContext ctx)
1414 ctx . Response . Redirect ( ctx . Request . QueryString [ "page" ] ) ;
1515
1616 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+ }
1723
1824 }
1925}
You can’t perform that action at this time.
0 commit comments