Skip to content

Commit 2df3d1b

Browse files
committed
JS: Fix: Ensure toSpliced is flagged by taint tracking in test suite (ed44358)
1 parent ed44358 commit 2df3d1b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ module ArrayTaintTracking {
8181
pred = call.getArgument(any(int i | i >= 2)) and
8282
succ.(DataFlow::SourceNode).getAMethodCall("splice") = call
8383
or
84+
// `array.toSpliced(x, y, source())`: if `source()` is tainted, then so is the result of `toSpliced`, but not the original array.
85+
call.(DataFlow::MethodCallNode).getMethodName() = "toSpliced" and
86+
pred = call.getArgument(any(int i | i >= 2)) and
87+
succ = call
88+
or
8489
// `array.splice(i, del, ...e)`: if `e` is tainted, then so is `array`.
8590
pred = call.getASpreadArgument() and
8691
succ.(DataFlow::SourceNode).getAMethodCall("splice") = call

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ typeInferenceMismatch
2323
| array-mutation.js:31:33:31:40 | source() | array-mutation.js:32:8:32:8 | h |
2424
| array-mutation.js:35:36:35:43 | source() | array-mutation.js:36:8:36:8 | i |
2525
| array-mutation.js:39:17:39:24 | source() | array-mutation.js:40:8:40:8 | j |
26+
| array-mutation.js:43:36:43:43 | source() | array-mutation.js:45:8:45:15 | kSpliced |
27+
| array-mutation.js:48:25:48:32 | source() | array-mutation.js:49:8:49:8 | l |
2628
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:17:8:17:13 | arr[1] |
2729
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:22:8:22:13 | arr[6] |
2830
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:27:8:27:13 | arr[0] |

javascript/ql/test/library-tests/TaintTracking/array-mutation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ function test(x, y) {
4242
let k = [];
4343
let kSpliced = k.toSpliced(x, y, source());
4444
sink(k); // OK
45-
sink(kSpliced); // NOT OK -- This should be caught, but it is not
45+
sink(kSpliced); // NOT OK
4646

4747
let l = [];
4848
l = l.toSpliced(x, y, source());
49-
sink(l); // NOT OK -- This should be caught, but it is not
49+
sink(l); // NOT OK
5050

5151
let m = [];
5252
m = m.toSpliced(q, source(), y);

0 commit comments

Comments
 (0)