Skip to content

Commit c02ad65

Browse files
committed
JS: Add: taint step for Map.groupBy function
1 parent 3786ad4 commit c02ad65

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

javascript/ql/lib/semmle/javascript/Collections.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,17 @@ private module CollectionDataFlow {
151151
)
152152
}
153153
}
154+
155+
/**
156+
* A step for a call to `groupBy` on an iterable object.
157+
*/
158+
private class GroupByTaintStep extends TaintTracking::SharedTaintStep {
159+
override predicate heapStep(DataFlow::Node pred, DataFlow::Node succ) {
160+
exists(DataFlow::MethodCallNode call |
161+
call = DataFlow::globalVarRef("Map").getAMemberCall("groupBy") and
162+
pred = call.getArgument(0) and
163+
succ = call
164+
)
165+
}
166+
}
154167
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ typeInferenceMismatch
244244
| tst.js:2:13:2:20 | source() | tst.js:66:10:66:16 | xSorted |
245245
| tst.js:2:13:2:20 | source() | tst.js:68:10:68:23 | x.toReversed() |
246246
| tst.js:2:13:2:20 | source() | tst.js:70:10:70:18 | xReversed |
247+
| tst.js:2:13:2:20 | source() | tst.js:72:10:72:31 | Map.gro ... z => z) |
247248
| xml.js:5:18:5:25 | source() | xml.js:8:14:8:17 | text |
248249
| xml.js:12:17:12:24 | source() | xml.js:13:14:13:19 | result |
249250
| xml.js:23:18:23:25 | source() | xml.js:20:14:20:17 | attr |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ function test() {
6969
const xReversed = x.toReversed();
7070
sink(xReversed) // NOT OK
7171

72-
sink(Map.groupBy(x, z => z)); // NOT OK -- This should be marked via taint step, but it is not.
72+
sink(Map.groupBy(x, z => z)); // NOT OK
7373
sink(Custom.groupBy(x, z => z)); // OK
7474
}

0 commit comments

Comments
 (0)