Skip to content

Commit 84234d5

Browse files
committed
JS: Fix: Ensure toSpliced with spread operator is flagged
1 parent 8512cb4 commit 84234d5

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
@@ -90,6 +90,11 @@ module ArrayTaintTracking {
9090
pred = call.getASpreadArgument() and
9191
succ.(DataFlow::SourceNode).getAMethodCall("splice") = call
9292
or
93+
// `array.toSpliced(i, del, ...e)`: if `e` is tainted, then so is the result of `toSpliced`, but not the original array.
94+
pred = call.getASpreadArgument() and
95+
call.(DataFlow::MethodCallNode).getMethodName() = "toSpliced" and
96+
succ = call
97+
or
9398
// `e = array.pop()`, `e = array.shift()`, or similar: if `array` is tainted, then so is `e`.
9499
call.(DataFlow::MethodCallNode)
95100
.calls(pred, ["pop", "shift", "slice", "splice", "at", "toSpliced"]) and

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ typeInferenceMismatch
2626
| array-mutation.js:43:36:43:43 | source() | array-mutation.js:45:8:45:15 | kSpliced |
2727
| array-mutation.js:48:25:48:32 | source() | array-mutation.js:49:8:49:8 | l |
2828
| array-mutation.js:68:21:68:28 | source() | array-mutation.js:69:8:69:8 | q |
29+
| array-mutation.js:72:39:72:46 | source() | array-mutation.js:73:8:73:15 | rSpliced |
30+
| array-mutation.js:75:28:75:35 | source() | array-mutation.js:76:8:76:8 | r |
2931
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:17:8:17:13 | arr[1] |
3032
| arrays-init.js:2:16:2:23 | source() | arrays-init.js:22:8:22:13 | arr[6] |
3133
| 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
@@ -70,8 +70,8 @@ function test(x, y) {
7070

7171
let r = [];
7272
let rSpliced = r.toSpliced(x, y, ...source());
73-
sink(rSpliced); // NOT OK -- This should flagged but it is not
73+
sink(rSpliced); // NOT OK
7474
sink(r); // OK
7575
r = r.toSpliced(x, y, ...source());
76-
sink(r); // NOT OK -- This should flagged but it is not
76+
sink(r); // NOT OK
7777
}

0 commit comments

Comments
 (0)