Skip to content

Commit ab53f3b

Browse files
committed
add array.filter() as a taint-step
1 parent 390ee3a commit ab53f3b

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

javascript/ql/src/semmle/javascript/Arrays.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ module ArrayTaintTracking {
3636
succ = call
3737
)
3838
or
39+
// `array.filter` keeps the taint
40+
call.(DataFlow::MethodCallNode).getMethodName() = "filter" and
41+
pred = call.getReceiver() and
42+
succ = call
43+
or
3944
// `array.reduce` with tainted value in callback
4045
call.(DataFlow::MethodCallNode).getMethodName() = "reduce" and
4146
pred = call.getArgument(0).(DataFlow::FunctionNode).getAReturn() and // Require the argument to be a closure to avoid spurious call/return flow

javascript/ql/test/query-tests/Security/CWE-730/RegExpInjection.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ nodes
3939
| RegExpInjection.js:47:22:47:26 | input |
4040
| RegExpInjection.js:50:46:50:50 | input |
4141
| RegExpInjection.js:50:46:50:50 | input |
42+
| RegExpInjection.js:54:14:54:16 | key |
43+
| RegExpInjection.js:54:14:54:27 | key.split(".") |
44+
| RegExpInjection.js:54:14:54:42 | key.spl ... x => x) |
45+
| RegExpInjection.js:54:14:54:52 | key.spl ... in("-") |
46+
| RegExpInjection.js:54:14:54:52 | key.spl ... in("-") |
4247
| tst.js:1:46:1:46 | e |
4348
| tst.js:1:46:1:46 | e |
4449
| tst.js:2:9:2:21 | data |
@@ -53,6 +58,7 @@ edges
5358
| RegExpInjection.js:5:7:5:28 | key | RegExpInjection.js:19:19:19:21 | key |
5459
| RegExpInjection.js:5:7:5:28 | key | RegExpInjection.js:21:19:21:21 | key |
5560
| RegExpInjection.js:5:7:5:28 | key | RegExpInjection.js:33:12:33:14 | key |
61+
| RegExpInjection.js:5:7:5:28 | key | RegExpInjection.js:54:14:54:16 | key |
5662
| RegExpInjection.js:5:13:5:28 | req.param("key") | RegExpInjection.js:5:7:5:28 | key |
5763
| RegExpInjection.js:5:13:5:28 | req.param("key") | RegExpInjection.js:5:7:5:28 | key |
5864
| RegExpInjection.js:5:31:5:56 | input | RegExpInjection.js:40:19:40:23 | input |
@@ -89,6 +95,10 @@ edges
8995
| RegExpInjection.js:29:21:29:21 | s | RegExpInjection.js:31:23:31:23 | s |
9096
| RegExpInjection.js:33:12:33:14 | key | RegExpInjection.js:29:21:29:21 | s |
9197
| RegExpInjection.js:34:12:34:19 | getKey() | RegExpInjection.js:29:21:29:21 | s |
98+
| RegExpInjection.js:54:14:54:16 | key | RegExpInjection.js:54:14:54:27 | key.split(".") |
99+
| RegExpInjection.js:54:14:54:27 | key.split(".") | RegExpInjection.js:54:14:54:42 | key.spl ... x => x) |
100+
| RegExpInjection.js:54:14:54:42 | key.spl ... x => x) | RegExpInjection.js:54:14:54:52 | key.spl ... in("-") |
101+
| RegExpInjection.js:54:14:54:42 | key.spl ... x => x) | RegExpInjection.js:54:14:54:52 | key.spl ... in("-") |
92102
| tst.js:1:46:1:46 | e | tst.js:2:16:2:16 | e |
93103
| tst.js:1:46:1:46 | e | tst.js:2:16:2:16 | e |
94104
| tst.js:2:9:2:21 | data | tst.js:3:21:3:24 | data |
@@ -111,4 +121,5 @@ edges
111121
| RegExpInjection.js:46:23:46:27 | input | RegExpInjection.js:5:39:5:56 | req.param("input") | RegExpInjection.js:46:23:46:27 | input | This regular expression is constructed from a $@. | RegExpInjection.js:5:39:5:56 | req.param("input") | user-provided value |
112122
| RegExpInjection.js:47:22:47:26 | input | RegExpInjection.js:5:39:5:56 | req.param("input") | RegExpInjection.js:47:22:47:26 | input | This regular expression is constructed from a $@. | RegExpInjection.js:5:39:5:56 | req.param("input") | user-provided value |
113123
| RegExpInjection.js:50:46:50:50 | input | RegExpInjection.js:5:39:5:56 | req.param("input") | RegExpInjection.js:50:46:50:50 | input | This regular expression is constructed from a $@. | RegExpInjection.js:5:39:5:56 | req.param("input") | user-provided value |
124+
| RegExpInjection.js:54:14:54:52 | key.spl ... in("-") | RegExpInjection.js:5:13:5:28 | req.param("key") | RegExpInjection.js:54:14:54:52 | key.spl ... in("-") | This regular expression is constructed from a $@. | RegExpInjection.js:5:13:5:28 | req.param("key") | user-provided value |
114125
| tst.js:3:16:3:35 | "^"+ data.name + "$" | tst.js:1:46:1:46 | e | tst.js:3:16:3:35 | "^"+ data.name + "$" | This regular expression is constructed from a $@. | tst.js:1:46:1:46 | e | user-provided value |

javascript/ql/test/query-tests/Security/CWE-730/RegExpInjection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ app.get('/findKey', function(req, res) {
5151
URI(`${protocol}://${host}${path}`).search(input).href(); // OK
5252
unknown.search(input).unknown; // OK
5353

54+
new RegExp(key.split(".").filter(x => x).join("-")); // NOT OK
5455
});
5556

5657
import * as Search from './search';

0 commit comments

Comments
 (0)