Skip to content

Commit b97c09a

Browse files
committed
use tuples to simplify arrayFunctionTaintStep
1 parent bb97829 commit b97c09a

File tree

1 file changed

+13
-34
lines changed

1 file changed

+13
-34
lines changed

javascript/ql/src/semmle/javascript/Arrays.qll

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@ module ArrayTaintTracking {
2424
predicate arrayFunctionTaintStep(DataFlow::Node pred, DataFlow::Node succ, DataFlow::CallNode call) {
2525
// `array.map(function (elt, i, ary) { ... })`: if `array` is tainted, then so are
2626
// `elt` and `ary`; similar for `forEach`
27-
exists(string name, Function f, int i |
28-
(name = "map" or name = "forEach") and
29-
(i = 0 or i = 2) and
27+
exists(Function f |
3028
call.getArgument(0).analyze().getAValue().(AbstractFunction).getFunction() = f and
31-
call.(DataFlow::MethodCallNode).getMethodName() = name and
29+
call.(DataFlow::MethodCallNode).getMethodName() = ["map", "forEach"] and
3230
pred = call.getReceiver() and
33-
succ = DataFlow::parameterNode(f.getParameter(i))
31+
succ = DataFlow::parameterNode(f.getParameter([0, 2]))
3432
)
3533
or
3634
// `array.map` with tainted return value in callback
@@ -47,41 +45,22 @@ module ArrayTaintTracking {
4745
succ = call
4846
or
4947
// `array.push(e)`, `array.unshift(e)`: if `e` is tainted, then so is `array`.
50-
exists(string name |
51-
name = "push" or
52-
name = "unshift"
53-
|
54-
pred = call.getAnArgument() and
55-
succ.(DataFlow::SourceNode).getAMethodCall(name) = call
56-
)
48+
pred = call.getAnArgument() and
49+
succ.(DataFlow::SourceNode).getAMethodCall(["push", "unshift"]) = call
5750
or
5851
// `array.push(...e)`, `array.unshift(...e)`: if `e` is tainted, then so is `array`.
59-
exists(string name |
60-
name = "push" or
61-
name = "unshift"
62-
|
63-
pred = call.getASpreadArgument() and
64-
// Make sure we handle reflective calls
65-
succ = call.getReceiver().getALocalSource() and
66-
call.getCalleeName() = name
67-
)
52+
pred = call.getASpreadArgument() and
53+
// Make sure we handle reflective calls
54+
succ = call.getReceiver().getALocalSource() and
55+
call.getCalleeName() = ["push", "unshift"]
6856
or
6957
// `array.splice(i, del, e)`: if `e` is tainted, then so is `array`.
70-
exists(string name | name = "splice" |
71-
pred = call.getArgument(2) and
72-
succ.(DataFlow::SourceNode).getAMethodCall(name) = call
73-
)
58+
pred = call.getArgument(2) and
59+
succ.(DataFlow::SourceNode).getAMethodCall("splice") = call
7460
or
7561
// `e = array.pop()`, `e = array.shift()`, or similar: if `array` is tainted, then so is `e`.
76-
exists(string name |
77-
name = "pop" or
78-
name = "shift" or
79-
name = "slice" or
80-
name = "splice"
81-
|
82-
call.(DataFlow::MethodCallNode).calls(pred, name) and
83-
succ = call
84-
)
62+
call.(DataFlow::MethodCallNode).calls(pred, ["pop", "shift", "slice", "splice"]) and
63+
succ = call
8564
or
8665
// `e = Array.from(x)`: if `x` is tainted, then so is `e`.
8766
call = DataFlow::globalVarRef("Array").getAPropertyRead("from").getACall() and

0 commit comments

Comments
 (0)