Skip to content

Commit 1717d17

Browse files
committed
add flow step for Array.prototype.at
1 parent fc25d14 commit 1717d17

File tree

6 files changed

+129
-90
lines changed

6 files changed

+129
-90
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module ArrayTaintTracking {
7575
succ.(DataFlow::SourceNode).getAMethodCall("splice") = call
7676
or
7777
// `e = array.pop()`, `e = array.shift()`, or similar: if `array` is tainted, then so is `e`.
78-
call.(DataFlow::MethodCallNode).calls(pred, ["pop", "shift", "slice", "splice"]) and
78+
call.(DataFlow::MethodCallNode).calls(pred, ["pop", "shift", "slice", "splice", "at"]) and
7979
succ = call
8080
or
8181
// `e = Array.from(x)`: if `x` is tainted, then so is `e`.
@@ -199,13 +199,13 @@ private module ArrayDataFlow {
199199
}
200200

201201
/**
202-
* A step for retrieving an element from an array using `.pop()` or `.shift()`.
202+
* A step for retrieving an element from an array using `.pop()`, `.shift()`, or `.at()`.
203203
* E.g. `array.pop()`.
204204
*/
205205
private class ArrayPopStep extends DataFlow::SharedFlowStep {
206206
override predicate loadStep(DataFlow::Node obj, DataFlow::Node element, string prop) {
207207
exists(DataFlow::MethodCallNode call |
208-
call.getMethodName() = ["pop", "shift"] and
208+
call.getMethodName() = ["pop", "shift", "at"] and
209209
prop = arrayElement() and
210210
obj = call.getReceiver() and
211211
element = call

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
| arrays.js:2:16:2:23 | "source" | arrays.js:74:8:74:29 | arr.fin ... llback) |
1212
| arrays.js:2:16:2:23 | "source" | arrays.js:77:8:77:35 | arrayFi ... llback) |
1313
| arrays.js:2:16:2:23 | "source" | arrays.js:81:10:81:10 | x |
14+
| arrays.js:2:16:2:23 | "source" | arrays.js:84:8:84:17 | arr.at(-1) |
1415
| arrays.js:18:22:18:29 | "source" | arrays.js:18:50:18:50 | e |
1516
| arrays.js:22:15:22:22 | "source" | arrays.js:23:8:23:17 | arr2.pop() |
1617
| arrays.js:25:15:25:22 | "source" | arrays.js:26:8:26:17 | arr3.pop() |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@
8080
for (const x of uniq(arr)) {
8181
sink(x); // NOT OK
8282
}
83+
84+
sink(arr.at(-1)); // NOT OK
8385
});

0 commit comments

Comments
 (0)