Skip to content

Commit 4106663

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

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

javascript/ql/test/experimental/Security/CWE-918/SSRF.expected

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ nodes
5151
| check-regex.js:41:13:41:43 | "test.c ... tainted |
5252
| check-regex.js:41:27:41:43 | req.query.tainted |
5353
| check-regex.js:41:27:41:43 | req.query.tainted |
54+
| check-regex.js:44:15:44:45 | "test.c ... tainted |
55+
| check-regex.js:44:15:44:45 | "test.c ... tainted |
56+
| check-regex.js:44:29:44:45 | req.query.tainted |
57+
| check-regex.js:44:29:44:45 | req.query.tainted |
58+
| check-regex.js:47:15:47:45 | "test.c ... tainted |
59+
| check-regex.js:47:15:47:45 | "test.c ... tainted |
60+
| check-regex.js:47:29:47:45 | req.query.tainted |
61+
| check-regex.js:47:29:47:45 | req.query.tainted |
5462
| check-validator.js:15:15:15:45 | "test.c ... tainted |
5563
| check-validator.js:15:15:15:45 | "test.c ... tainted |
5664
| check-validator.js:15:29:15:45 | req.query.tainted |
@@ -127,6 +135,14 @@ edges
127135
| check-regex.js:41:27:41:43 | req.query.tainted | check-regex.js:41:13:41:43 | "test.c ... tainted |
128136
| check-regex.js:41:27:41:43 | req.query.tainted | check-regex.js:41:13:41:43 | "test.c ... tainted |
129137
| check-regex.js:41:27:41:43 | req.query.tainted | check-regex.js:41:13:41:43 | "test.c ... tainted |
138+
| check-regex.js:44:29:44:45 | req.query.tainted | check-regex.js:44:15:44:45 | "test.c ... tainted |
139+
| check-regex.js:44:29:44:45 | req.query.tainted | check-regex.js:44:15:44:45 | "test.c ... tainted |
140+
| check-regex.js:44:29:44:45 | req.query.tainted | check-regex.js:44:15:44:45 | "test.c ... tainted |
141+
| check-regex.js:44:29:44:45 | req.query.tainted | check-regex.js:44:15:44:45 | "test.c ... tainted |
142+
| check-regex.js:47:29:47:45 | req.query.tainted | check-regex.js:47:15:47:45 | "test.c ... tainted |
143+
| check-regex.js:47:29:47:45 | req.query.tainted | check-regex.js:47:15:47:45 | "test.c ... tainted |
144+
| check-regex.js:47:29:47:45 | req.query.tainted | check-regex.js:47:15:47:45 | "test.c ... tainted |
145+
| check-regex.js:47:29:47:45 | req.query.tainted | check-regex.js:47:15:47:45 | "test.c ... tainted |
130146
| check-validator.js:15:29:15:45 | req.query.tainted | check-validator.js:15:15:15:45 | "test.c ... tainted |
131147
| check-validator.js:15:29:15:45 | req.query.tainted | check-validator.js:15:15:15:45 | "test.c ... tainted |
132148
| check-validator.js:15:29:15:45 | req.query.tainted | check-validator.js:15:15:15:45 | "test.c ... tainted |
@@ -166,6 +182,8 @@ edges
166182
| check-regex.js:31:15:31:45 | "test.c ... tainted | check-regex.js:31:29:31:45 | req.query.tainted | check-regex.js:31:15:31:45 | "test.c ... tainted | The URL of this request depends on a user-provided value. |
167183
| check-regex.js:34:15:34:42 | baseURL ... tainted | check-regex.js:34:25:34:42 | req.params.tainted | check-regex.js:34:15:34:42 | baseURL ... tainted | The URL of this request depends on a user-provided value. |
168184
| check-regex.js:41:13:41:43 | "test.c ... tainted | check-regex.js:41:27:41:43 | req.query.tainted | check-regex.js:41:13:41:43 | "test.c ... tainted | The URL of this request depends on a user-provided value. |
185+
| check-regex.js:44:15:44:45 | "test.c ... tainted | check-regex.js:44:29:44:45 | req.query.tainted | check-regex.js:44:15:44:45 | "test.c ... tainted | The URL of this request depends on a user-provided value. |
186+
| check-regex.js:47:15:47:45 | "test.c ... tainted | check-regex.js:47:29:47:45 | req.query.tainted | check-regex.js:47:15:47:45 | "test.c ... tainted | The URL of this request depends on a user-provided value. |
169187
| check-validator.js:15:15:15:45 | "test.c ... tainted | check-validator.js:15:29:15:45 | req.query.tainted | check-validator.js:15:15:15:45 | "test.c ... tainted | The URL of this request depends on a user-provided value. |
170188
| check-validator.js:27:15:27:45 | "test.c ... tainted | check-validator.js:27:29:27:45 | req.query.tainted | check-validator.js:27:15:27:45 | "test.c ... tainted | The URL of this request depends on a user-provided value. |
171189
| check-validator.js:50:15:50:45 | "test.c ... tainted | check-validator.js:50:29:50:45 | req.query.tainted | check-validator.js:50:15:50:45 | "test.c ... tainted | The URL of this request depends on a user-provided value. |

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)