Skip to content

Commit 7427a24

Browse files
committed
Added test case for Array.prototype.toReversed, which is currently not flagged as a taint sink.
1 parent 3215967 commit 7427a24

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ private module ArrayLibraries {
466466
private class ImmutableArrayTransformStep extends TaintTracking::SharedTaintStep {
467467
override predicate heapStep(DataFlow::Node pred, DataFlow::Node succ) {
468468
exists(DataFlow::MethodCallNode call |
469-
call.getMethodName() = "toSorted" and
469+
call.getMethodName() in ["toSorted", "toReversed"] and
470470
pred = call.getReceiver() and
471471
succ = call
472472
)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ typeInferenceMismatch
236236
| tst.js:2:13:2:20 | source() | tst.js:61:10:61:20 | x.reverse() |
237237
| tst.js:2:13:2:20 | source() | tst.js:63:10:63:21 | x.toSorted() |
238238
| tst.js:2:13:2:20 | source() | tst.js:65:10:65:16 | xSorted |
239+
| tst.js:2:13:2:20 | source() | tst.js:67:10:67:23 | x.toReversed() |
240+
| tst.js:2:13:2:20 | source() | tst.js:69:10:69:18 | xReversed |
239241
| xml.js:5:18:5:25 | source() | xml.js:8:14:8:17 | text |
240242
| xml.js:12:17:12:24 | source() | xml.js:13:14:13:19 | result |
241243
| xml.js:23:18:23:25 | source() | xml.js:20:14:20:17 | attr |

javascript/ql/test/query-tests/NodeJS/DubiousImport/externs.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,15 @@ Array.prototype.push = function(var_args) {};
333333
*/
334334
Array.prototype.reverse = function() {};
335335

336+
/**
337+
* Returns a new array with the elements in reversed order.
338+
*
339+
* @this {{length: number}}
340+
* @template T
341+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed
342+
*/
343+
Array.prototype.toReversed = function() {};
344+
336345
/**
337346
* Removes the first element from an array and returns that element. This
338347
* method changes the length of the array.

0 commit comments

Comments
 (0)