Skip to content

Commit b546172

Browse files
committed
JS: Allow comma-separated indices in Argument[..] and Parameter[..]
1 parent 7c023d6 commit b546172

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

javascript/ql/lib/semmle/javascript/frameworks/data/internal/Shared.qll

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
* 3. The `path` column API-graph-like edges to follow starting at the node selected by `package` and `type`.
2525
* It is a `.`-separated list of tokens of form:
2626
* - Member[x] : a property named `x`. May be a comma-separated list of named.
27-
* - Argument[n]: the n-th argument to a call. May be a range of form `x-y` (inclusive).
28-
* - Parameter[n]: the n-th parameter of a callback. May be a range of form `x-y` (inclusive).
27+
* - Argument[n]: the n-th argument to a call. May be a range of form `x-y` (inclusive) and/or a comma-separated list.
28+
* - Parameter[n]: the n-th parameter of a callback. May be a range of form `x-y` (inclusive) and/or a comma-separated list.
2929
* - ReturnValue: the value returned by a function call
3030
* - Instance: the value returned by a constructor call
3131
* - Awaited: the value from a resolved promise/future-like object
@@ -383,20 +383,20 @@ private string getApiGraphLabelFromPathToken(string token) {
383383
// use-node represents be an argument, and an edge originating from a def-node represents a parameter.
384384
// We just map both to the same thing.
385385
token = ["Argument[" + arg + "]", "Parameter[" + arg + "]"] and
386-
result = API::EdgeLabel::parameterByStringIndex(arg)
386+
exists(string part | part = arg.splitAt(",") |
387+
result = API::EdgeLabel::parameterByStringIndex(part)
388+
or
389+
exists(string lo, string hi |
390+
lo = part.regexpCapture("(\\d+)-(\\d+)", 1) and
391+
hi = part.regexpCapture("(\\d+)-(\\d+)", 2) and
392+
result = API::EdgeLabel::parameter([lo.toInt() .. hi.toInt()])
393+
)
394+
)
387395
or
388396
token = "Member[" + arg + "]" and
389397
result = API::EdgeLabel::member(arg.splitAt(","))
390398
)
391399
or
392-
exists(string lo, string hi, string regexp |
393-
// For tokens like Argument[1-5] we just enumerate the whole range of corresponding edge labels
394-
regexp = "(?:Argument|Parameter)\\[(\\d+)-(\\d+)\\]" and
395-
lo = token.regexpCapture(regexp, 1) and
396-
hi = token.regexpCapture(regexp, 2) and
397-
result = API::EdgeLabel::parameter([lo.toInt() .. hi.toInt()])
398-
)
399-
or
400400
token = "ReturnValue" and
401401
result = API::EdgeLabel::return()
402402
or

javascript/ql/test/library-tests/frameworks/data/test.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ taintFlow
55
| test.js:7:41:7:48 | source() | test.js:7:8:7:49 | require ... urce()) |
66
| test.js:13:29:13:36 | source() | test.js:14:10:14:10 | y |
77
| test.js:19:29:19:36 | source() | test.js:20:10:20:10 | y |
8+
| test.js:28:38:28:45 | source() | test.js:28:8:28:55 | testlib ... , 1, 1) |
9+
| test.js:30:44:30:51 | source() | test.js:30:8:30:55 | testlib ... e(), 1) |

javascript/ql/test/library-tests/frameworks/data/test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ function testTaintIntoCallback(x) {
2323
sink(y); // OK - only callback 1-2 receive taint
2424
});
2525
}
26+
27+
function testPreserveArgZeroAndTwo() {
28+
sink(testlib.preserveArgZeroAndTwo(source(), 1, 1, 1)); // NOT OK
29+
sink(testlib.preserveArgZeroAndTwo(1, source(), 1, 1)); // OK
30+
sink(testlib.preserveArgZeroAndTwo(1, 1, source(), 1)); // NOT OK
31+
sink(testlib.preserveArgZeroAndTwo(1, 1, 1, source())); // OK
32+
}

javascript/ql/test/library-tests/frameworks/data/test.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class Steps extends ModelInput::SummaryModelCsv {
77
row =
88
[
99
"testlib;;Member[preserveTaint];Argument[0];ReturnValue;taint",
10-
"testlib;;Member[taintIntoCallback];Argument[0];Argument[1-2].Parameter[0];taint"
10+
"testlib;;Member[taintIntoCallback];Argument[0];Argument[1-2].Parameter[0];taint",
11+
"testlib;;Member[preserveArgZeroAndTwo];Argument[0,2];ReturnValue;taint",
1112
]
1213
}
1314
}

0 commit comments

Comments
 (0)