Skip to content

Commit ab3d365

Browse files
authored
Merge pull request #9535 from github/js-array-filter-taint-step
Tests for rebased 7010
2 parents b5d6258 + da44340 commit ab3d365

File tree

5 files changed

+232
-92
lines changed

5 files changed

+232
-92
lines changed

javascript/ql/lib/semmle/javascript/Arrays.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,18 @@ module ArrayTaintTracking {
3636
succ = call
3737
)
3838
or
39-
// `array.filter(x => x)` keeps the taint
39+
// `array.filter(x => x)` and `array.filter(x => !!x)` keeps the taint
4040
call.(DataFlow::MethodCallNode).getMethodName() = "filter" and
4141
pred = call.getReceiver() and
4242
succ = call and
43-
exists(DataFlow::FunctionNode callback | callback = call.getArgument(0).getAFunctionValue() |
44-
callback.getParameter(0).getALocalUse() = callback.getAReturn()
43+
exists(DataFlow::FunctionNode callback, DataFlow::Node param, DataFlow::Node ret |
44+
callback = call.getArgument(0).getAFunctionValue() and
45+
param = callback.getParameter(0).getALocalUse() and
46+
ret = callback.getAReturn()
47+
|
48+
param = ret
49+
or
50+
param = DataFlow::exprNode(ret.asExpr().(LogNotExpr).getOperand().(LogNotExpr).getOperand())
4551
)
4652
or
4753
// `array.reduce` with tainted value in callback
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
| arrays.js:2:16:2:23 | "source" | arrays.js:5:8:5:14 | obj.foo |
2+
| arrays.js:2:16:2:23 | "source" | arrays.js:11:10:11:15 | arr[i] |
3+
| arrays.js:2:16:2:23 | "source" | arrays.js:15:27:15:27 | e |
4+
| arrays.js:2:16:2:23 | "source" | arrays.js:16:23:16:23 | e |
5+
| arrays.js:2:16:2:23 | "source" | arrays.js:20:8:20:16 | arr.pop() |
6+
| arrays.js:2:16:2:23 | "source" | arrays.js:49:8:49:13 | arr[0] |
7+
| arrays.js:2:16:2:23 | "source" | arrays.js:52:10:52:10 | x |
8+
| arrays.js:2:16:2:23 | "source" | arrays.js:56:10:56:10 | x |
9+
| arrays.js:2:16:2:23 | "source" | arrays.js:60:10:60:10 | x |
10+
| arrays.js:2:16:2:23 | "source" | arrays.js:66:10:66:10 | x |
11+
| arrays.js:2:16:2:23 | "source" | arrays.js:71:10:71:10 | x |
12+
| arrays.js:2:16:2:23 | "source" | arrays.js:74:8:74:29 | arr.fin ... llback) |
13+
| arrays.js:2:16:2:23 | "source" | arrays.js:77:8:77:35 | arrayFi ... llback) |
14+
| arrays.js:2:16:2:23 | "source" | arrays.js:81:10:81:10 | x |
15+
| arrays.js:2:16:2:23 | "source" | arrays.js:84:8:84:17 | arr.at(-1) |
16+
| arrays.js:18:22:18:29 | "source" | arrays.js:18:50:18:50 | e |
17+
| arrays.js:22:15:22:22 | "source" | arrays.js:23:8:23:17 | arr2.pop() |
18+
| arrays.js:25:15:25:22 | "source" | arrays.js:26:8:26:17 | arr3.pop() |
19+
| arrays.js:29:21:29:28 | "source" | arrays.js:30:8:30:17 | arr4.pop() |
20+
| arrays.js:29:21:29:28 | "source" | arrays.js:33:8:33:17 | arr5.pop() |
21+
| arrays.js:29:21:29:28 | "source" | arrays.js:35:8:35:26 | arr5.slice(2).pop() |
22+
| arrays.js:29:21:29:28 | "source" | arrays.js:41:8:41:17 | arr6.pop() |
23+
| arrays.js:44:4:44:11 | "source" | arrays.js:45:10:45:18 | ary.pop() |
24+
| arrays.js:44:4:44:11 | "source" | arrays.js:46:10:46:12 | ary |
25+
| arrays.js:86:9:86:16 | "source" | arrays.js:86:8:86:34 | ["sourc ... ) => x) |
26+
| arrays.js:87:9:87:16 | "source" | arrays.js:87:8:87:36 | ["sourc ... => !!x) |
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import javascript
2+
3+
class ArrayTaintFlowConfig extends TaintTracking::Configuration {
4+
ArrayTaintFlowConfig() { this = "ArrayTaintFlowConfig" }
5+
6+
override predicate isSource(DataFlow::Node source) { source.asExpr().getStringValue() = "source" }
7+
8+
override predicate isSink(DataFlow::Node sink) {
9+
sink = any(DataFlow::CallNode call | call.getCalleeName() = "sink").getAnArgument()
10+
}
11+
}
12+
13+
from ArrayTaintFlowConfig config, DataFlow::Node src, DataFlow::Node snk
14+
where config.hasFlow(src, snk)
15+
select src, snk

javascript/ql/test/library-tests/Arrays/arrays.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,7 @@
8282
}
8383

8484
sink(arr.at(-1)); // NOT OK
85+
86+
sink(["source"].filter((x) => x)); // NOT OK
87+
sink(["source"].filter((x) => !!x)); // NOT OK
8588
});

0 commit comments

Comments
 (0)