Skip to content

Commit 8390846

Browse files
committed
JS: more taint steps through array manipulation
1 parent d3a880e commit 8390846

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

javascript/ql/src/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,23 @@ module TaintTracking {
290290
succ.(DataFlow::SourceNode).getAMethodCall(name) = call
291291
)
292292
or
293+
// `array.push(...e)`, `array.unshift(...e)`: if `e` is tainted, then so is `array`.
294+
exists(string name |
295+
name = "push" or
296+
name = "unshift"
297+
|
298+
pred = call.asExpr().(InvokeExpr).getAnArgument().(SpreadElement).getOperand().flow() and
299+
succ.(DataFlow::SourceNode).getAMethodCall(name) = call
300+
)
301+
or
302+
// `array.splice(i, del, e)`: if `e` is tainted, then so is `array`.
303+
exists(string name |
304+
name = "splice"
305+
|
306+
pred = call.getArgument(2) and
307+
succ.(DataFlow::SourceNode).getAMethodCall(name) = call
308+
)
309+
or
293310
// `e = array.pop()`, `e = array.shift()`, or similar: if `array` is tainted, then so is `e`.
294311
exists(string name |
295312
name = "pop" or

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ typeInferenceMismatch
99
| addexpr.js:11:15:11:22 | source() | addexpr.js:21:8:21:12 | value |
1010
| advanced-callgraph.js:2:13:2:20 | source() | advanced-callgraph.js:6:22:6:22 | v |
1111
| array-callback.js:2:23:2:30 | source() | array-callback.js:4:10:4:10 | x |
12+
| array-mutation.js:19:18:19:25 | source() | array-mutation.js:20:8:20:8 | e |
13+
| array-mutation.js:23:13:23:20 | source() | array-mutation.js:24:8:24:8 | f |
14+
| array-mutation.js:27:16:27:23 | source() | array-mutation.js:28:8:28:8 | g |
1215
| booleanOps.js:2:11:2:18 | source() | booleanOps.js:4:8:4:8 | x |
1316
| booleanOps.js:2:11:2:18 | source() | booleanOps.js:13:10:13:10 | x |
1417
| booleanOps.js:2:11:2:18 | source() | booleanOps.js:19:10:19:10 | x |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function test(x, y) {
2+
let a = [];
3+
a.splice(source(), x);
4+
sink(a); // OK
5+
6+
let b = [];
7+
b.splice(x, source());
8+
sink(b); // OK
9+
10+
let c = [];
11+
c.splice(source(), x, y);
12+
sink(c); // OK
13+
14+
let d = [];
15+
d.splice(x, source(), y);
16+
sink(d); // OK
17+
18+
let e = [];
19+
e.splice(x, y, source());
20+
sink(e); // NOT OK
21+
22+
let f = [];
23+
f.push(...source());
24+
sink(f); // NOT OK
25+
26+
let g = [];
27+
g.unshift(...source());
28+
sink(g); // NOT OK
29+
}

0 commit comments

Comments
 (0)