Skip to content

Commit 43abc72

Browse files
committed
JS: Add TypeModel.isTypeUsed
f
1 parent 358c741 commit 43abc72

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
private import javascript
8+
private import semmle.javascript.frameworks.data.ModelsAsData
89

910
/**
1011
* The raw data type underlying `DataFlow::Node`.
@@ -33,4 +34,10 @@ newtype TNode =
3334
TExceptionalInvocationReturnNode(InvokeExpr e) or
3435
TGlobalAccessPathRoot() or
3536
TTemplatePlaceholderTag(Templating::TemplatePlaceholderTag tag) or
36-
TReflectiveParametersNode(Function f)
37+
TReflectiveParametersNode(Function f) or
38+
TForbiddenRecursionGuard() {
39+
none() and
40+
// We want to prune irrelevant models before materialising data flow nodes, so types contributed
41+
// directly from CodeQL must expose their pruning info without depending on data flow nodes.
42+
(any(ModelInput::TypeModel tm).isTypeUsed("") implies any())
43+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,20 @@ module ModelInput {
168168
* A unit class for adding additional type model rows from CodeQL models.
169169
*/
170170
class TypeModel extends Unit {
171+
/**
172+
* Holds if any of the other predicates in this class might have a result
173+
* for the given `type`.
174+
*
175+
* The implementation of this predicate should not depend on `DataFlow::Node`.
176+
*/
177+
bindingset[type]
178+
predicate isTypeUsed(string type) { none() }
179+
171180
/**
172181
* Gets a data-flow node that is a source of the given `type`.
173182
*
183+
* Note that `type` should also be included in `isTypeUsed`.
184+
*
174185
* This must not depend on API graphs, but ensures that an API node is generated for
175186
* the source.
176187
*/
@@ -180,6 +191,8 @@ module ModelInput {
180191
* Gets a data-flow node that is a sink of the given `type`,
181192
* usually because it is an argument passed to a parameter of that type.
182193
*
194+
* Note that `type` should also be included in `isTypeUsed`.
195+
*
183196
* This must not depend on API graphs, but ensures that an API node is generated for
184197
* the sink.
185198
*/
@@ -188,6 +201,8 @@ module ModelInput {
188201
/**
189202
* Gets an API node that is a source or sink of the given `type`.
190203
*
204+
* Note that `type` should also be included in `isTypeUsed`.
205+
*
191206
* Unlike `getASource` and `getASink`, this may depend on API graphs.
192207
*/
193208
API::Node getAnApiNode(string type) { none() }
@@ -367,6 +382,8 @@ predicate isRelevantType(string type) {
367382
(
368383
Specific::isTypeUsed(type)
369384
or
385+
any(TypeModel model).isTypeUsed(type)
386+
or
370387
exists(TestAllModels t)
371388
)
372389
or

0 commit comments

Comments
 (0)