File tree Expand file tree Collapse file tree 2 files changed +30
-1
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 +30
-1
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,31 @@ class RelativeUrlSanitizer extends Sanitizer {
182
182
}
183
183
}
184
184
185
+ /**
186
+ * A comparison on the `Host` property of a url, that is a sanitizer for URL redirects.
187
+ * E.g. `url.Host == "example.org"`
188
+ */
189
+ 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
+ e = access .getQualifier ( )
194
+ ) and
195
+ if comparison instanceof EQExpr
196
+ then v .( AbstractValues:: BooleanValue ) .getValue ( ) = true
197
+ else v .( AbstractValues:: BooleanValue ) .getValue ( ) = false
198
+ )
199
+ }
200
+
201
+ /**
202
+ * A comparison on the `Host` property of a url, that is a sanitizer for URL redirects.
203
+ */
204
+ class HostComparisonSanitizer extends Sanitizer {
205
+ HostComparisonSanitizer ( ) {
206
+ this = DataFlow:: BarrierGuard< isHostComparisonSanitizer / 3 > :: getABarrierNode ( )
207
+ }
208
+ }
209
+
185
210
/**
186
211
* A call to the getter of the RawUrl property, whose value is considered to be safe for URL
187
212
* redirects.
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ public void ProcessRequest(HttpContext ctx)
26
26
// GOOD: The redirect is to a relative URL
27
27
ctx . Response . Redirect ( url . ToString ( ) ) ;
28
28
}
29
-
29
+
30
+ if ( url . Host == "example.org" ) {
31
+ // GOOD: The redirect is to a known host
32
+ ctx . Response . Redirect ( url . ToString ( ) ) ;
33
+ }
30
34
}
31
35
}
You can’t perform that action at this time.
0 commit comments