Skip to content

Commit e543c6c

Browse files
committed
add a js/client-side-unvalidated-url-redirection sink for the history library
1 parent ffad65b commit e543c6c

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,21 @@ module ClientSideUrlRedirect {
191191
}
192192
}
193193

194+
/**
195+
* A write to the location using the [history](https://npmjs.com/package/history) library
196+
*/
197+
class HistoryWriteUrlSink extends ScriptUrlSink {
198+
HistoryWriteUrlSink() {
199+
this =
200+
API::moduleImport("history")
201+
.getMember(["createBrowserHistory", "createHashHistory"])
202+
.getReturn()
203+
.getMember(["push", "replace"])
204+
.getACall()
205+
.getArgument(0)
206+
}
207+
}
208+
194209
/**
195210
* A call to change the current url with a Next.js router.
196211
*/

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ nodes
129129
| tst13.js:52:34:52:34 | e |
130130
| tst13.js:53:28:53:28 | e |
131131
| tst13.js:53:28:53:28 | e |
132+
| tst13.js:59:9:59:52 | payload |
133+
| tst13.js:59:19:59:42 | documen ... .search |
134+
| tst13.js:59:19:59:42 | documen ... .search |
135+
| tst13.js:59:19:59:52 | documen ... bstr(1) |
136+
| tst13.js:61:18:61:24 | payload |
137+
| tst13.js:61:18:61:24 | payload |
132138
| tst.js:2:19:2:69 | /.*redi ... n.href) |
133139
| tst.js:2:19:2:72 | /.*redi ... ref)[1] |
134140
| tst.js:2:19:2:72 | /.*redi ... ref)[1] |
@@ -306,6 +312,11 @@ edges
306312
| tst13.js:52:34:52:34 | e | tst13.js:53:28:53:28 | e |
307313
| tst13.js:52:34:52:34 | e | tst13.js:53:28:53:28 | e |
308314
| tst13.js:52:34:52:34 | e | tst13.js:53:28:53:28 | e |
315+
| tst13.js:59:9:59:52 | payload | tst13.js:61:18:61:24 | payload |
316+
| tst13.js:59:9:59:52 | payload | tst13.js:61:18:61:24 | payload |
317+
| tst13.js:59:19:59:42 | documen ... .search | tst13.js:59:19:59:52 | documen ... bstr(1) |
318+
| tst13.js:59:19:59:42 | documen ... .search | tst13.js:59:19:59:52 | documen ... bstr(1) |
319+
| tst13.js:59:19:59:52 | documen ... bstr(1) | tst13.js:59:9:59:52 | payload |
309320
| tst.js:2:19:2:69 | /.*redi ... n.href) | tst.js:2:19:2:72 | /.*redi ... ref)[1] |
310321
| tst.js:2:19:2:69 | /.*redi ... n.href) | tst.js:2:19:2:72 | /.*redi ... ref)[1] |
311322
| tst.js:2:47:2:63 | document.location | tst.js:2:47:2:68 | documen ... on.href |
@@ -397,6 +408,7 @@ edges
397408
| tst13.js:44:14:44:20 | payload | tst13.js:2:19:2:42 | documen ... .search | tst13.js:44:14:44:20 | payload | Untrusted URL redirection due to $@. | tst13.js:2:19:2:42 | documen ... .search | user-provided value |
398409
| tst13.js:50:23:50:23 | e | tst13.js:49:32:49:32 | e | tst13.js:50:23:50:23 | e | Untrusted URL redirection due to $@. | tst13.js:49:32:49:32 | e | user-provided value |
399410
| tst13.js:53:28:53:28 | e | tst13.js:52:34:52:34 | e | tst13.js:53:28:53:28 | e | Untrusted URL redirection due to $@. | tst13.js:52:34:52:34 | e | user-provided value |
411+
| tst13.js:61:18:61:24 | payload | tst13.js:59:19:59:42 | documen ... .search | tst13.js:61:18:61:24 | payload | Untrusted URL redirection due to $@. | tst13.js:59:19:59:42 | documen ... .search | user-provided value |
400412
| tst.js:2:19:2:72 | /.*redi ... ref)[1] | tst.js:2:47:2:63 | document.location | tst.js:2:19:2:72 | /.*redi ... ref)[1] | Untrusted URL redirection due to $@. | tst.js:2:47:2:63 | document.location | user-provided value |
401413
| tst.js:2:19:2:72 | /.*redi ... ref)[1] | tst.js:2:47:2:68 | documen ... on.href | tst.js:2:19:2:72 | /.*redi ... ref)[1] | Untrusted URL redirection due to $@. | tst.js:2:47:2:68 | documen ... on.href | user-provided value |
402414
| tst.js:6:20:6:59 | indirec ... ref)[1] | tst.js:6:34:6:50 | document.location | tst.js:6:20:6:59 | indirec ... ref)[1] | Untrusted URL redirection due to $@. | tst.js:6:34:6:50 | document.location | user-provided value |

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@ function foo() {
5353
self.importScripts(e); // NOT OK
5454
}
5555
})();
56+
57+
const history = require('history').createBrowserHistory();
58+
function bar() {
59+
var payload = document.location.search.substr(1);
60+
61+
history.push(payload); // NOT OK
62+
}

0 commit comments

Comments
 (0)