Skip to content

Commit

Permalink
Merge pull request #18412 from asgerf/jss/perf-fixes
Browse files Browse the repository at this point in the history
JS: Fix a few perf issues
  • Loading branch information
asgerf authored Jan 7, 2025
2 parents 7e4fbe2 + 0cdda87 commit abea019
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,8 @@ predicate nodeIsHidden(Node node) {
or
node instanceof FlowSummaryIntermediateAwaitStoreNode
or
node instanceof FlowSummaryDefaultExceptionalReturn
or
node instanceof CaptureNode
or
// Hide function expressions, as capture-flow causes them to appear in unhelpful ways
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ module ExceptionXssConfig implements DataFlow::StateConfigSig {
canThrowSensitiveInformation(node1) and
node2 = getExceptionTarget(node1)
}

int accessPathLimit() { result = 1 }
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ module UnvalidatedDynamicMethodCall {
exists(InvokeExpr invk |
this = invk.getCallee().flow() and
// don't flag invocations inside a try-catch
not invk.getASuccessor() instanceof CatchClause
not invk.getASuccessor() instanceof CatchClause and
// Filter out `foo.bar()` calls as they usually aren't interesting.
// Technically this could be reachable if preceded by `foo.bar = obj[taint]`
// but such sinks are more likely to be FPs and also slow down the query.
not invk.getCallee() instanceof DotExpr
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ deprecated private class ConcreteMaybeFromProto extends MaybeFromProto {
ConcreteMaybeFromProto() { this = this }
}

/** Gets a data flow node referring to an instance of `Map`. */
private DataFlow::SourceNode mapObject(DataFlow::TypeTracker t) {
t.start() and
result = DataFlow::globalVarRef("Map").getAnInstantiation()
or
exists(DataFlow::TypeTracker t2 | result = mapObject(t2).track(t2, t))
}

/** Gets a data flow node referring to an instance of `Map`. */
private DataFlow::SourceNode mapObject() { result = mapObject(DataFlow::TypeTracker::end()) }

/**
* A taint-tracking configuration for reasoning about unvalidated dynamic method calls.
*/
Expand Down Expand Up @@ -67,7 +78,9 @@ module UnvalidatedDynamicMethodCallConfig implements DataFlow::StateConfigSig {
not PropertyInjection::hasUnsafeMethods(read.getBase().getALocalSource())
)
or
exists(DataFlow::SourceNode base, DataFlow::CallNode get | get = base.getAMethodCall("get") |
exists(DataFlow::CallNode get |
get = mapObject().getAMethodCall("get") and
get.getNumArgument() = 1 and
node1 = get.getArgument(0) and
node2 = get
) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ module PropNameTrackingConfig implements DataFlow::StateConfigSig {
node instanceof DataFlow::VarAccessBarrier or
node = DataFlow::MakeBarrierGuard<BarrierGuard>::getABarrierNode()
}

int accessPathLimit() {
// Speed up the query. For the pattern we're looking for the value rarely
// flows through any contents, apart from a capture content.
result = 1
}
}

class FlowState = PropNameTrackingConfig::FlowState;
Expand Down

0 comments on commit abea019

Please sign in to comment.