Skip to content

Commit 445552d

Browse files
committed
Added tests for regex sanitization to identify false positives matchAll
1 parent 5e8b1b0 commit 445552d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

javascript/ql/test/experimental/Security/CWE-918/check-regex.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ app.get('/check-with-axios', req => {
2525
} else {
2626
axios.get(baseURL + req.params.tainted); // OK
2727
}
28-
28+
2929
// Blacklists are not safe
3030
if (!req.query.tainted.match(/^[/\.%]+$/)) {
3131
axios.get("test.com/" + req.query.tainted); // SSRF
@@ -39,6 +39,13 @@ app.get('/check-with-axios', req => {
3939
}
4040

4141
axios.get("test.com/" + req.query.tainted); // OK - False Positive
42+
43+
if (req.query.tainted.matchAll(/^[0-9a-z]+$/g)) { // letters and numbers
44+
axios.get("test.com/" + req.query.tainted); // OK
45+
}
46+
if (req.query.tainted.matchAll(/^[0-9a-z\-_]+$/g)) { // letters, numbers, - and _
47+
axios.get("test.com/" + req.query.tainted); // OK
48+
}
4249
});
4350

4451
const isValidPath = path => path.match(/^[0-9a-z]+$/);

0 commit comments

Comments
 (0)