Skip to content

Commit abea019

Browse files
authored
Merge pull request github#18412 from asgerf/jss/perf-fixes
JS: Fix a few perf issues
2 parents 7e4fbe2 + 0cdda87 commit abea019

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ predicate nodeIsHidden(Node node) {
612612
or
613613
node instanceof FlowSummaryIntermediateAwaitStoreNode
614614
or
615+
node instanceof FlowSummaryDefaultExceptionalReturn
616+
or
615617
node instanceof CaptureNode
616618
or
617619
// Hide function expressions, as capture-flow causes them to appear in unhelpful ways

javascript/ql/lib/semmle/javascript/security/dataflow/ExceptionXssQuery.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ module ExceptionXssConfig implements DataFlow::StateConfigSig {
153153
canThrowSensitiveInformation(node1) and
154154
node2 = getExceptionTarget(node1)
155155
}
156+
157+
int accessPathLimit() { result = 1 }
156158
}
157159

158160
/**

javascript/ql/lib/semmle/javascript/security/dataflow/UnvalidatedDynamicMethodCallCustomizations.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ module UnvalidatedDynamicMethodCall {
182182
exists(InvokeExpr invk |
183183
this = invk.getCallee().flow() and
184184
// don't flag invocations inside a try-catch
185-
not invk.getASuccessor() instanceof CatchClause
185+
not invk.getASuccessor() instanceof CatchClause and
186+
// Filter out `foo.bar()` calls as they usually aren't interesting.
187+
// Technically this could be reachable if preceded by `foo.bar = obj[taint]`
188+
// but such sinks are more likely to be FPs and also slow down the query.
189+
not invk.getCallee() instanceof DotExpr
186190
)
187191
}
188192

javascript/ql/lib/semmle/javascript/security/dataflow/UnvalidatedDynamicMethodCallQuery.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ deprecated private class ConcreteMaybeFromProto extends MaybeFromProto {
2424
ConcreteMaybeFromProto() { this = this }
2525
}
2626

27+
/** Gets a data flow node referring to an instance of `Map`. */
28+
private DataFlow::SourceNode mapObject(DataFlow::TypeTracker t) {
29+
t.start() and
30+
result = DataFlow::globalVarRef("Map").getAnInstantiation()
31+
or
32+
exists(DataFlow::TypeTracker t2 | result = mapObject(t2).track(t2, t))
33+
}
34+
35+
/** Gets a data flow node referring to an instance of `Map`. */
36+
private DataFlow::SourceNode mapObject() { result = mapObject(DataFlow::TypeTracker::end()) }
37+
2738
/**
2839
* A taint-tracking configuration for reasoning about unvalidated dynamic method calls.
2940
*/
@@ -67,7 +78,9 @@ module UnvalidatedDynamicMethodCallConfig implements DataFlow::StateConfigSig {
6778
not PropertyInjection::hasUnsafeMethods(read.getBase().getALocalSource())
6879
)
6980
or
70-
exists(DataFlow::SourceNode base, DataFlow::CallNode get | get = base.getAMethodCall("get") |
81+
exists(DataFlow::CallNode get |
82+
get = mapObject().getAMethodCall("get") and
83+
get.getNumArgument() = 1 and
7184
node1 = get.getArgument(0) and
7285
node2 = get
7386
) and

javascript/ql/src/Security/CWE-915/PrototypePollutingFunction.ql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,12 @@ module PropNameTrackingConfig implements DataFlow::StateConfigSig {
277277
node instanceof DataFlow::VarAccessBarrier or
278278
node = DataFlow::MakeBarrierGuard<BarrierGuard>::getABarrierNode()
279279
}
280+
281+
int accessPathLimit() {
282+
// Speed up the query. For the pattern we're looking for the value rarely
283+
// flows through any contents, apart from a capture content.
284+
result = 1
285+
}
280286
}
281287

282288
class FlowState = PropNameTrackingConfig::FlowState;

0 commit comments

Comments
 (0)