Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Fix a few perf issues #18412

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading