add a sanitizer for List.Contains() in url-redirect

This commit is contained in:
erik-krogh
2024-02-13 12:45:07 +01:00
parent 59792808d4
commit 3f8de82ea3
2 changed files with 28 additions and 0 deletions

View File

@@ -139,6 +139,28 @@ class LocalUrlSanitizer extends Sanitizer {
LocalUrlSanitizer() { this = DataFlow::BarrierGuard<isLocalUrlSanitizer/3>::getABarrierNode() }
}
/**
* A argument to a call to `List.Contains()` that is a sanitizer for URL redirects.
*/
private predicate isContainsUrlSanitizer(Guard guard, Expr e, AbstractValue v) {
exists(MethodCall method | method = guard |
exists(Method m | m = method.getTarget() |
m.hasName("Contains") and
e = method.getArgument(0)
) and
v.(AbstractValues::BooleanValue).getValue() = true
)
}
/**
* A URL argument to a call to `List.Contains()` that is a sanitizer for URL redirects.
*/
class ContainsUrlSanitizer extends Sanitizer {
ContainsUrlSanitizer() {
this = DataFlow::BarrierGuard<isContainsUrlSanitizer/3>::getABarrierNode()
}
}
/**
* A call to the getter of the RawUrl property, whose value is considered to be safe for URL
* redirects.

View File

@@ -14,6 +14,12 @@ public class UrlRedirectHandler2 : IHttpHandler
ctx.Response.Redirect(ctx.Request.QueryString["page"]);
List<string> VALID_REDIRECTS = new List<string>{ "http://cwe.mitre.org/data/definitions/601.html", "http://cwe.mitre.org/data/definitions/79.html" };
var redirectUrl = ctx.Request.QueryString["page"];
if (VALID_REDIRECTS.Contains(redirectUrl))
{
// GOOD: the request parameter is validated against set of known fixed strings
ctx.Response.Redirect(redirectUrl);
}
}
}