Skip to content

Commit dc2f39c

Browse files
committed
JS: Add model of Map#groupBy
1 parent de5e6dd commit dc2f39c

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

javascript/ql/lib/semmle/javascript/internal/flow_summaries/Maps.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,23 @@ class MapSet extends SummarizedCallable {
118118
)
119119
}
120120
}
121+
122+
class MapGroupBy extends SummarizedCallable {
123+
MapGroupBy() { this = "Map#groupBy" }
124+
125+
override DataFlow::CallNode getACallSimple() {
126+
result = mapConstructorRef().getAMemberCall("groupBy") and
127+
result.getNumArgument() = 2
128+
}
129+
130+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
131+
preservesValue = true and
132+
(
133+
input = "Argument[0].ArrayElement" and
134+
output = ["Argument[1].Parameter[0]", "ReturnValue.MapValue.ArrayElement"]
135+
or
136+
input = "Argument[1].ReturnValue" and
137+
output = "ReturnValue.MapKey"
138+
)
139+
}
140+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ legacyDataFlowDifference
3535
| spread.js:4:15:4:22 | source() | spread.js:18:8:18:8 | y | only flow with NEW data flow library |
3636
| spread.js:4:15:4:22 | source() | spread.js:24:8:24:8 | y | only flow with NEW data flow library |
3737
| tst.js:2:13:2:20 | source() | tst.js:17:10:17:10 | a | only flow with OLD data flow library |
38-
| tst.js:82:23:82:30 | source() | tst.js:83:58:83:61 | item | only flow with OLD data flow library |
3938
| tst.js:82:23:82:30 | source() | tst.js:84:14:84:20 | grouped | only flow with OLD data flow library |
4039
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x | only flow with NEW data flow library |
4140
consistencyIssue
@@ -321,6 +320,7 @@ flow
321320
| tst.js:2:13:2:20 | source() | tst.js:102:10:102:14 | xWith |
322321
| tst.js:75:22:75:29 | source() | tst.js:75:10:75:52 | Map.gro ... (item)) |
323322
| tst.js:75:22:75:29 | source() | tst.js:75:47:75:50 | item |
323+
| tst.js:82:23:82:30 | source() | tst.js:83:58:83:61 | item |
324324
| tst.js:87:22:87:29 | source() | tst.js:90:14:90:25 | taintedValue |
325325
| tst.js:93:22:93:29 | source() | tst.js:96:14:96:25 | taintedValue |
326326
| tst.js:93:22:93:29 | source() | tst.js:97:14:97:26 | map.get(true) |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ legacyDataFlowDifference
2727
| spread.js:4:15:4:22 | source() | spread.js:24:8:24:8 | y | only flow with NEW data flow library |
2828
| tst.js:2:13:2:20 | source() | tst.js:35:14:35:16 | ary | only flow with NEW data flow library |
2929
| tst.js:2:13:2:20 | source() | tst.js:41:14:41:16 | ary | only flow with NEW data flow library |
30+
| tst.js:82:23:82:30 | source() | tst.js:83:58:83:61 | item | only flow with NEW data flow library |
3031
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x | only flow with NEW data flow library |
3132
flow
3233
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:4:8:4:12 | obj.x |
@@ -190,6 +191,7 @@ flow
190191
| tst.js:2:13:2:20 | source() | tst.js:35:14:35:16 | ary |
191192
| tst.js:2:13:2:20 | source() | tst.js:41:14:41:16 | ary |
192193
| tst.js:2:13:2:20 | source() | tst.js:54:14:54:19 | unsafe |
194+
| tst.js:82:23:82:30 | source() | tst.js:83:58:83:61 | item |
193195
| tst.js:93:22:93:29 | source() | tst.js:96:14:96:25 | taintedValue |
194196
| tst.js:93:22:93:29 | source() | tst.js:97:14:97:26 | map.get(true) |
195197
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function test() {
8080
}
8181
{
8282
const list = [source()];
83-
const grouped = Map.groupBy(list, (item) => sink(item)); // NOT OK [INCONSISTENCY]
83+
const grouped = Map.groupBy(list, (item) => sink(item)); // NOT OK
8484
sink(grouped); // NOT OK [INCONSISTENCY]
8585
}
8686
{

0 commit comments

Comments
 (0)