mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
recognize more split("?") sanitizers
This commit is contained in:
@@ -51,9 +51,7 @@ module ClientSideUrlRedirect {
|
||||
exists(MethodCallExpr mce, string methodName |
|
||||
mce = queryAccess.asExpr() and mce.calls(nd.asExpr(), methodName)
|
||||
|
|
||||
methodName = "split" and
|
||||
// exclude `location.href.split('?')[0]`, which can never refer to the query string
|
||||
not exists(PropAccess pacc | mce = pacc.getBase() | pacc.getPropertyName() = "0")
|
||||
methodName = "split"
|
||||
or
|
||||
(methodName = "substring" or methodName = "substr" or methodName = "slice") and
|
||||
// exclude `location.href.substring(0, ...)` and similar, which can
|
||||
@@ -68,6 +66,23 @@ module ClientSideUrlRedirect {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A sanitizer that reads the first part a location split by "?", e.g. `location.href.split('?')[0]`.
|
||||
*/
|
||||
class QueryPrefixSanitizer extends Sanitizer {
|
||||
DataFlow::PropRead read;
|
||||
|
||||
QueryPrefixSanitizer() {
|
||||
this = read and
|
||||
read.getPropertyName() = "0" and
|
||||
exists(DataFlow::MethodCallNode splitCall | splitCall = read.getBase().getALocalSource() |
|
||||
splitCall.getMethodName() = "split" and
|
||||
splitCall.getArgument(0).mayHaveStringValue("?") and
|
||||
splitCall.getReceiver() = [DOM::locationRef(), DOM::locationRef().getAPropertyRead("href")]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A sink which is used to set the window location.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user