Skip to content

Commit 6266dab

Browse files
authored
Merge pull request github#17951 from Napalys/napalys/reverse-support
JS: Added support for reverse function
2 parents ba26281 + 42f7f73 commit 6266dab

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added taint-steps for `Array.prototype.reverse`

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,4 +444,18 @@ private module ArrayLibraries {
444444
)
445445
}
446446
}
447+
448+
/**
449+
* A taint propagating data flow edge arising from in-place array manipulation operations.
450+
* The methods return the pointer to `this` array as well.
451+
*/
452+
private class ArrayInPlaceManipulationTaintStep extends TaintTracking::SharedTaintStep {
453+
override predicate heapStep(DataFlow::Node pred, DataFlow::Node succ) {
454+
exists(DataFlow::MethodCallNode call |
455+
call.getMethodName() in ["sort", "reverse"] and
456+
pred = call.getReceiver() and
457+
succ = call
458+
)
459+
}
460+
}
447461
}

javascript/ql/lib/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,6 @@ module TaintTracking {
869869
}
870870
}
871871

872-
/**
873-
* A taint propagating data flow edge arising from sorting.
874-
*/
875-
private class SortTaintStep extends SharedTaintStep {
876-
override predicate heapStep(DataFlow::Node pred, DataFlow::Node succ) {
877-
exists(DataFlow::MethodCallNode call |
878-
call.getMethodName() = "sort" and
879-
pred = call.getReceiver() and
880-
succ = call
881-
)
882-
}
883-
}
884-
885872
/**
886873
* A taint step through an exception constructor, such as `x` to `new Error(x)`.
887874
*/

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ typeInferenceMismatch
233233
| tst.js:2:13:2:20 | source() | tst.js:48:10:48:22 | new Buffer(x) |
234234
| tst.js:2:13:2:20 | source() | tst.js:51:10:51:31 | seriali ... ript(x) |
235235
| tst.js:2:13:2:20 | source() | tst.js:54:14:54:19 | unsafe |
236+
| tst.js:2:13:2:20 | source() | tst.js:61:10:61:20 | x.reverse() |
236237
| xml.js:5:18:5:25 | source() | xml.js:8:14:8:17 | text |
237238
| xml.js:12:17:12:24 | source() | xml.js:13:14:13:19 | result |
238239
| xml.js:23:18:23:25 | source() | xml.js:20:14:20:17 | attr |

javascript/ql/test/library-tests/TaintTracking/tst.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ function test() {
5757
}
5858

5959
tagged`foo ${"safe"} bar ${x} baz`;
60+
61+
sink(x.reverse()); // NOT OK
6062
}

0 commit comments

Comments
 (0)