Skip to content

Commit 945fe45

Browse files
committed
all split()[0] are safe for url-redirect
1 parent a3fb138 commit 945fe45

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/ClientSideUrlRedirectCustomizations.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ module ClientSideUrlRedirect {
5353
exists(MethodCallExpr mce, string methodName |
5454
mce = queryAccess.asExpr() and mce.calls(nd.asExpr(), methodName)
5555
|
56-
methodName = "split"
56+
methodName = "split" and
57+
// exclude all splits where only the prefix is accessed, which is safe for url-redirects.
58+
not exists(PropAccess pacc | mce = pacc.getBase() | pacc.getPropertyName() = "0")
5759
or
5860
(methodName = "substring" or methodName = "substr" or methodName = "slice") and
5961
// exclude `location.href.substring(0, ...)` and similar, which can

javascript/ql/test/query-tests/Security/CWE-601/ClientSideUrlRedirect/tst11.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ function foo() {
33
var urlParts = document.location.href.split('?');
44
var loc = urlParts[0] + "?" + boxes.value;
55
window.location = loc
6+
7+
// Also OK.
8+
window.location.replace(window.location.href.split("#")[0] + "#mappage");
69
}

0 commit comments

Comments
 (0)