Skip to content

Commit 298aa92

Browse files
authored
Merge pull request #1543 from xiemaisi/js/reflective-call-flow
Approved by asger-semmle
2 parents 40f7e6f + 91a718c commit 298aa92

File tree

9 files changed

+23
-0
lines changed

9 files changed

+23
-0
lines changed

javascript/ql/src/semmle/javascript/dataflow/DataFlow.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,9 @@ module DataFlow {
11631163
pred = TThisNode(thiz.getBindingContainer()) and
11641164
succ = valueNode(thiz)
11651165
)
1166+
or
1167+
// `f.call(...)` and `f.apply(...)` evaluate to the result of the reflective call they perform
1168+
pred = TReflectiveCallNode(succ.asExpr(), _)
11661169
}
11671170

11681171
/**

javascript/ql/test/library-tests/DataFlow/flowStep.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
| tst.js:111:23:111:25 | v2c | tst.js:111:6:111:38 | v2c |
141141
| tst.js:111:29:111:31 | o2c | tst.js:111:6:111:38 | v2c |
142142
| tst.js:111:36:111:38 | o2d | tst.js:111:6:111:32 | [v2a, v ... = o2c] |
143+
| tst.js:115:1:115:12 | reflective call | tst.js:115:1:115:12 | Array.call() |
143144
| tst.ts:1:1:1:1 | A | tst.ts:1:11:1:11 | A |
144145
| tst.ts:1:1:1:1 | A | tst.ts:7:1:7:0 | A |
145146
| tst.ts:1:1:5:1 | A | tst.ts:7:1:7:0 | A |

javascript/ql/test/library-tests/DataFlow/incomplete.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@
8282
| tst.js:111:23:111:25 | v2c | heap |
8383
| tst.js:111:29:111:31 | o2c | global |
8484
| tst.js:111:36:111:38 | o2d | global |
85+
| tst.js:115:1:115:5 | Array | global |
86+
| tst.js:115:1:115:10 | Array.call | global |
87+
| tst.js:115:1:115:10 | Array.call | heap |
88+
| tst.js:115:1:115:12 | Array.call() | call |
89+
| tst.js:115:1:115:12 | exceptional return of Array.call() | call |
8590
| tst.ts:2:14:2:19 | x | namespace |
8691
| tst.ts:3:3:3:8 | exceptional return of setX() | call |
8792
| tst.ts:3:3:3:8 | setX() | call |

javascript/ql/test/library-tests/DataFlow/sources.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
| tst.js:111:23:111:25 | v2c |
8686
| tst.js:111:29:111:31 | o2c |
8787
| tst.js:111:36:111:38 | o2d |
88+
| tst.js:115:1:115:5 | Array |
89+
| tst.js:115:1:115:10 | Array.call |
90+
| tst.js:115:1:115:12 | Array.call() |
91+
| tst.js:115:1:115:12 | reflective call |
8892
| tst.ts:1:1:1:0 | this |
8993
| tst.ts:3:3:3:8 | setX() |
9094
| tst.ts:7:1:7:0 | this |

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,7 @@ x ?? y; // flow through short-circuiting operator
111111
var [v2a, v2b = o2b, v2c = o2c] = o2d;
112112
v2a + v2b + v2c;
113113
});
114+
115+
Array.call() // flow from implicit call to `Array` to `Array.call`
116+
114117
// semmle-extractor-options: --experimental

javascript/ql/test/library-tests/InterProceduralFlow/DataFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
| tst2.js:6:24:6:37 | "also tainted" | tst2.js:10:15:10:24 | g(source1) |
4040
| tst2.js:6:24:6:37 | "also tainted" | tst2.js:11:15:11:24 | g(source2) |
4141
| tst6.mjs:12:14:12:21 | "source" | tst6.mjs:14:12:14:16 | a.m() |
42+
| tst6.mjs:16:15:16:23 | "source2" | tst6.mjs:18:13:18:24 | a.m.call(a2) |
4243
| tst.js:2:17:2:22 | "src1" | tst.js:39:17:39:17 | x |
4344
| tst.js:2:17:2:22 | "src1" | tst.js:41:19:41:19 | x |
4445
| tst.js:2:17:2:22 | "src1" | tst.js:45:17:45:17 | x |

javascript/ql/test/library-tests/InterProceduralFlow/GermanFlow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
| tst2.js:6:24:6:37 | "also tainted" | tst2.js:10:15:10:24 | g(source1) |
4141
| tst2.js:6:24:6:37 | "also tainted" | tst2.js:11:15:11:24 | g(source2) |
4242
| tst6.mjs:12:14:12:21 | "source" | tst6.mjs:14:12:14:16 | a.m() |
43+
| tst6.mjs:16:15:16:23 | "source2" | tst6.mjs:18:13:18:24 | a.m.call(a2) |
4344
| tst.js:2:17:2:22 | "src1" | tst.js:39:17:39:17 | x |
4445
| tst.js:2:17:2:22 | "src1" | tst.js:41:19:41:19 | x |
4546
| tst.js:2:17:2:22 | "src1" | tst.js:45:17:45:17 | x |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
| tst4.js:2:16:2:24 | "tainted" | tst4.js:16:15:16:28 | p.also_tainted |
5050
| tst4.js:2:16:2:24 | "tainted" | tst4.js:17:15:17:28 | substr(source) |
5151
| tst6.mjs:12:14:12:21 | "source" | tst6.mjs:14:12:14:16 | a.m() |
52+
| tst6.mjs:16:15:16:23 | "source2" | tst6.mjs:18:13:18:24 | a.m.call(a2) |
5253
| tst.js:2:17:2:22 | "src1" | tst.js:3:15:3:29 | String(source1) |
5354
| tst.js:2:17:2:22 | "src1" | tst.js:4:15:4:29 | RegExp(source1) |
5455
| tst.js:2:17:2:22 | "src1" | tst.js:5:15:5:33 | new String(source1) |

javascript/ql/test/library-tests/InterProceduralFlow/tst6.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ class A {
1212
var source = "source";
1313
var a = new A(source);
1414
var sink = a.m();
15+
16+
var source2 = "source2";
17+
var a2 = new A(source2);
18+
var sink2 = a.m.call(a2);

0 commit comments

Comments
 (0)