Skip to content

Commit 4e8ae77

Browse files
committed
cache more predicates
1 parent a7030c7 commit 4e8ae77

File tree

4 files changed

+60
-39
lines changed

4 files changed

+60
-39
lines changed

javascript/ql/src/semmle/javascript/PackageExports.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
*/
66

77
import javascript
8+
private import semmle.javascript.internal.CachedStages
89

910
/**
1011
* Gets a parameter that is a library input to a top-level package.
1112
*/
13+
cached
1214
DataFlow::ParameterNode getALibraryInputParameter() {
15+
Stages::Taint::ref() and
1316
exists(int bound, DataFlow::FunctionNode func |
1417
func = getAValueExportedByPackage().getABoundFunctionValue(bound) and
1518
result = func.getParameter(any(int arg | arg >= bound))

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ module DataFlow {
255255
* Holds if this node is annotated with the given named type,
256256
* or is declared as a subtype thereof, or is a union or intersection containing such a type.
257257
*/
258+
cached
258259
predicate hasUnderlyingType(string globalName) {
260+
Stages::TypeTracking::ref() and
259261
getType().hasUnderlyingType(globalName)
260262
or
261263
getFallbackTypeAnnotation().getAnUnderlyingType().hasQualifiedName(globalName)
@@ -265,7 +267,9 @@ module DataFlow {
265267
* Holds if this node is annotated with the given named type,
266268
* or is declared as a subtype thereof, or is a union or intersection containing such a type.
267269
*/
270+
cached
268271
predicate hasUnderlyingType(string moduleName, string typeName) {
272+
Stages::TypeTracking::ref() and
269273
getType().hasUnderlyingType(moduleName, typeName)
270274
or
271275
getFallbackTypeAnnotation().getAnUnderlyingType().hasQualifiedName(moduleName, typeName)

javascript/ql/src/semmle/javascript/dataflow/internal/StepSummary.qll

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,49 +53,11 @@ private module Cached {
5353
predicate step(DataFlow::SourceNode pred, DataFlow::SourceNode succ, StepSummary summary) {
5454
exists(DataFlow::Node mid | pred.flowsTo(mid) | StepSummary::smallstep(mid, succ, summary))
5555
}
56-
}
57-
58-
import Cached::Public
59-
60-
class OptionalPropertyName extends string {
61-
OptionalPropertyName() { this instanceof PropertyName or this = "" }
62-
}
63-
64-
/**
65-
* INTERNAL: Use `TypeTracker` or `TypeBackTracker` instead.
66-
*
67-
* A description of a step on an inter-procedural data flow path.
68-
*/
69-
class StepSummary extends TStepSummary {
70-
/** Gets a textual representation of this step summary. */
71-
string toString() {
72-
this instanceof LevelStep and result = "level"
73-
or
74-
this instanceof CallStep and result = "call"
75-
or
76-
this instanceof ReturnStep and result = "return"
77-
or
78-
exists(string prop | this = StoreStep(prop) | result = "store " + prop)
79-
or
80-
exists(string prop | this = LoadStep(prop) | result = "load " + prop)
81-
or
82-
exists(string prop | this = CopyStep(prop) | result = "copy " + prop)
83-
or
84-
exists(string fromProp, string toProp | this = LoadStoreStep(fromProp, toProp) |
85-
result = "load " + fromProp + " and store to " + toProp
86-
)
87-
}
88-
}
89-
90-
module StepSummary {
91-
/**
92-
* INTERNAL: Use `SourceNode.track()` or `SourceNode.backtrack()` instead.
93-
*/
94-
predicate step = Cached::step/3;
9556

9657
/**
9758
* INTERNAL: Use `TypeBackTracker.smallstep()` instead.
9859
*/
60+
cached
9961
predicate smallstep(DataFlow::Node pred, DataFlow::Node succ, StepSummary summary) {
10062
// Flow through properties of objects
10163
propertyFlowStep(pred, succ) and
@@ -194,3 +156,47 @@ module StepSummary {
194156
)
195157
}
196158
}
159+
160+
import Cached::Public
161+
162+
class OptionalPropertyName extends string {
163+
OptionalPropertyName() { this instanceof PropertyName or this = "" }
164+
}
165+
166+
/**
167+
* INTERNAL: Use `TypeTracker` or `TypeBackTracker` instead.
168+
*
169+
* A description of a step on an inter-procedural data flow path.
170+
*/
171+
class StepSummary extends TStepSummary {
172+
/** Gets a textual representation of this step summary. */
173+
string toString() {
174+
this instanceof LevelStep and result = "level"
175+
or
176+
this instanceof CallStep and result = "call"
177+
or
178+
this instanceof ReturnStep and result = "return"
179+
or
180+
exists(string prop | this = StoreStep(prop) | result = "store " + prop)
181+
or
182+
exists(string prop | this = LoadStep(prop) | result = "load " + prop)
183+
or
184+
exists(string prop | this = CopyStep(prop) | result = "copy " + prop)
185+
or
186+
exists(string fromProp, string toProp | this = LoadStoreStep(fromProp, toProp) |
187+
result = "load " + fromProp + " and store to " + toProp
188+
)
189+
}
190+
}
191+
192+
module StepSummary {
193+
/**
194+
* INTERNAL: Use `SourceNode.track()` or `SourceNode.backtrack()` instead.
195+
*/
196+
predicate step = Cached::step/3;
197+
198+
/**
199+
* INTERNAL: Use `TypeBackTracker.smallstep()` instead.
200+
*/
201+
predicate smallstep = Cached::smallstep/3;
202+
}

javascript/ql/src/semmle/javascript/internal/CachedStages.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ module Stages {
198198
exists(any(DataFlow::TypeBackTracker t).prepend(_))
199199
or
200200
DataFlow::functionForwardingStep(_, _)
201+
or
202+
any(DataFlow::Node node).hasUnderlyingType(_)
203+
or
204+
any(DataFlow::Node node).hasUnderlyingType(_, _)
201205
}
202206
}
203207

@@ -232,6 +236,8 @@ module Stages {
232236
*/
233237
cached
234238
module Taint {
239+
private import semmle.javascript.PackageExports as Exports
240+
235241
/**
236242
* Always holds.
237243
* Ensures that a predicate is evaluated as part of the Taint stage.
@@ -250,6 +256,8 @@ module Stages {
250256
TaintTracking::heapStep(_, _)
251257
or
252258
exists(RemoteFlowSource r)
259+
or
260+
exists(Exports::getALibraryInputParameter())
253261
}
254262
}
255263
}

0 commit comments

Comments
 (0)