Skip to content

Commit ec18786

Browse files
committed
JS: Provide better model for Array.splice
1 parent 54a0e6d commit ec18786

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ module ArrayTaintTracking {
7777
succ = call.getReceiver().getALocalSource() and
7878
call.getCalleeName() = ["push", "unshift"]
7979
or
80-
// `array.splice(i, del, e)`: if `e` is tainted, then so is `array`.
81-
pred = call.getArgument(2) and
80+
// `array.splice(i, del, ...items)`: if any item is tainted, then so is `array`.
81+
pred = call.getArgument(any(int i | i >= 2)) and
8282
succ.(DataFlow::SourceNode).getAMethodCall("splice") = call
8383
or
8484
// `e = array.pop()`, `e = array.shift()`, or similar: if `array` is tainted, then so is `e`.
@@ -274,14 +274,14 @@ private module ArrayDataFlow {
274274

275275
/**
276276
* A step modeling that `splice` can insert elements into an array.
277-
* For example in `array.splice(i, del, e)`: if `e` is tainted, then so is `array
277+
* For example in `array.splice(i, del, ...items)`: if any item is tainted, then so is `array`
278278
*/
279279
private class ArraySpliceStep extends PreCallGraphStep {
280280
override predicate storeStep(DataFlow::Node element, DataFlow::SourceNode obj, string prop) {
281281
exists(DataFlow::MethodCallNode call |
282282
call.getMethodName() = "splice" and
283283
prop = arrayElement() and
284-
element = call.getArgument(2) and
284+
element = call.getArgument(any(int i | i >= 2)) and
285285
call = obj.getAMethodCall()
286286
)
287287
}

javascript/ql/test/library-tests/Arrays/DataFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
| arrays.js:29:21:29:28 | "source" | arrays.js:38:8:38:17 | arr5.pop() |
2020
| arrays.js:29:21:29:28 | "source" | arrays.js:40:8:40:26 | arr5.slice(2).pop() |
2121
| arrays.js:29:21:29:28 | "source" | arrays.js:46:8:46:17 | arr6.pop() |
22+
| arrays.js:33:37:33:44 | "source" | arrays.js:35:8:35:25 | arr4_variant.pop() |
2223
| arrays.js:49:4:49:11 | "source" | arrays.js:50:10:50:18 | ary.pop() |

javascript/ql/test/library-tests/Arrays/TaintFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
| arrays.js:29:21:29:28 | "source" | arrays.js:38:8:38:17 | arr5.pop() |
2121
| arrays.js:29:21:29:28 | "source" | arrays.js:40:8:40:26 | arr5.slice(2).pop() |
2222
| arrays.js:29:21:29:28 | "source" | arrays.js:46:8:46:17 | arr6.pop() |
23+
| arrays.js:33:37:33:44 | "source" | arrays.js:35:8:35:25 | arr4_variant.pop() |
2324
| arrays.js:49:4:49:11 | "source" | arrays.js:50:10:50:18 | ary.pop() |
2425
| arrays.js:49:4:49:11 | "source" | arrays.js:51:10:51:12 | ary |
2526
| arrays.js:91:9:91:16 | "source" | arrays.js:91:8:91:34 | ["sourc ... ) => x) |

0 commit comments

Comments
 (0)