Skip to content

Commit a1f9fe3

Browse files
authored
Merge pull request #1573 from asger-semmle/restrict-receiver-type
Approved by xiemaisi
2 parents e087b6c + badca07 commit a1f9fe3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,15 @@ class ClassNode extends DataFlow::SourceNode {
715715
t.start() and
716716
result = getAReceiverNode()
717717
or
718+
result = getAnInstanceReferenceAux(t) and
719+
// Avoid tracking into the receiver of other classes.
720+
// Note that this also blocks flows into a property of the receiver,
721+
// but the `localFieldStep` rule will often compensate for this.
722+
not result = any(DataFlow::ClassNode cls).getAReceiverNode()
723+
}
724+
725+
pragma[noinline]
726+
private DataFlow::SourceNode getAnInstanceReferenceAux(DataFlow::TypeTracker t) {
718727
exists(DataFlow::TypeTracker t2 |
719728
result = getAnInstanceReference(t2).track(t2, t)
720729
)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'dummy';
2+
3+
class Foo {
4+
a() {
5+
/** calls:Foo.b */
6+
this.b();
7+
}
8+
9+
/** name:Foo.b */
10+
b() {}
11+
}
12+
13+
class Bar {
14+
a() {
15+
/** calls:Bar.b */
16+
this.b();
17+
}
18+
19+
/** name:Bar.b */
20+
b() {}
21+
}
22+
23+
function callA(x) {
24+
x.a();
25+
}
26+
callA(new Foo);
27+
callB(new Bar);

0 commit comments

Comments
 (0)