Skip to content

Commit 89ad737

Browse files
committed
JS: Add internal extension points sources of class objects/instances
1 parent b07c5c6 commit 89ad737

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import javascript
88
private import semmle.javascript.dependencies.Dependencies
99
private import internal.CallGraphs
1010
private import semmle.javascript.internal.CachedStages
11+
private import semmle.javascript.dataflow.internal.PreCallGraphStep
1112

1213
/**
1314
* A data flow node corresponding to an expression.
@@ -995,6 +996,9 @@ class ClassNode extends DataFlow::SourceNode instanceof ClassNode::Range {
995996
result.getAstNode().getFile() = this.getAstNode().getFile()
996997
)
997998
or
999+
t.start() and
1000+
PreCallGraphStep::classObjectSource(this, result)
1001+
or
9981002
result = this.getAClassReferenceRec(t)
9991003
}
10001004

@@ -1044,6 +1048,9 @@ class ClassNode extends DataFlow::SourceNode instanceof ClassNode::Range {
10441048
// Note that this also blocks flows into a property of the receiver,
10451049
// but the `localFieldStep` rule will often compensate for this.
10461050
not result = any(DataFlow::ClassNode cls).getAReceiverNode()
1051+
or
1052+
t.start() and
1053+
PreCallGraphStep::classInstanceSource(this, result)
10471054
}
10481055

10491056
pragma[noinline]

javascript/ql/lib/semmle/javascript/dataflow/internal/PreCallGraphStep.qll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ class PreCallGraphStep extends Unit {
4444
) {
4545
none()
4646
}
47+
48+
/**
49+
* Holds if `node` can hold an instance of `cls`.
50+
*/
51+
predicate classInstanceSource(DataFlow::ClassNode cls, DataFlow::Node node) { none() }
52+
53+
/**
54+
* Holds if `node` can hold an reference to the `cls` class itself.
55+
*/
56+
predicate classObjectSource(DataFlow::ClassNode cls, DataFlow::Node node) { none() }
4757
}
4858

4959
cached
@@ -90,6 +100,22 @@ module PreCallGraphStep {
90100
) {
91101
any(PreCallGraphStep s).loadStoreStep(pred, succ, loadProp, storeProp)
92102
}
103+
104+
/**
105+
* Holds if `node` can hold an instance of `cls`.
106+
*/
107+
cached
108+
predicate classInstanceSource(DataFlow::ClassNode cls, DataFlow::Node node) {
109+
any(PreCallGraphStep s).classInstanceSource(cls, node)
110+
}
111+
112+
/**
113+
* Holds if `node` can hold an reference to the `cls` class itself.
114+
*/
115+
cached
116+
predicate classObjectSource(DataFlow::ClassNode cls, DataFlow::Node node) {
117+
any(PreCallGraphStep s).classObjectSource(cls, node)
118+
}
93119
}
94120

95121
/**

0 commit comments

Comments
 (0)