-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'js/shared-dataflow-branch' into js/shared-dataflow-merg…
…e-main
- Loading branch information
Showing
25 changed files
with
404 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
javascript/ql/lib/semmle/javascript/internal/flow_summaries/AllFlowSummaries.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
javascript/ql/lib/semmle/javascript/internal/flow_summaries/ExceptionFlow.qll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Contains a summary for propagating exceptions out of callbacks | ||
*/ | ||
|
||
private import javascript | ||
private import FlowSummaryUtil | ||
private import semmle.javascript.dataflow.internal.AdditionalFlowInternal | ||
private import semmle.javascript.dataflow.internal.DataFlowPrivate | ||
private import semmle.javascript.dataflow.FlowSummary | ||
private import semmle.javascript.internal.flow_summaries.Promises | ||
|
||
private predicate isCallback(DataFlow::SourceNode node) { | ||
node instanceof DataFlow::FunctionNode | ||
or | ||
node instanceof DataFlow::PartialInvokeNode | ||
or | ||
exists(DataFlow::SourceNode prev | | ||
isCallback(prev) and | ||
DataFlow::argumentPassingStep(_, prev.getALocalUse(), _, node) | ||
) | ||
} | ||
|
||
/** | ||
* Summary that propagates exceptions out of callbacks back to the caller. | ||
* | ||
* This summary only applies to calls that have no other call targets. | ||
* See also `FlowSummaryDefaultExceptionalReturn`, which handles calls that have a summary target, | ||
* but where the summary does not mention `ReturnValue[exception]`. | ||
*/ | ||
private class ExceptionFlowSummary extends SummarizedCallable, LibraryCallableInternal { | ||
ExceptionFlowSummary() { this = "Exception propagator" } | ||
|
||
override DataFlow::CallNode getACallStage2() { | ||
not exists(result.getACallee()) and | ||
not exists(SummarizedCallable c | result = [c.getACall(), c.getACallSimple()]) and | ||
// Avoid a few common cases where the exception should not propagate back | ||
not result.getCalleeName() = ["addEventListener", EventEmitter::on()] and | ||
not result = promiseConstructorRef().getAnInvocation() and | ||
// Restrict to cases where a callback is known to flow in, as lambda flow in DataFlowImplCommon blows up otherwise | ||
isCallback(result.getAnArgument().getALocalSource()) | ||
} | ||
|
||
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) { | ||
preservesValue = true and | ||
input = "Argument[0..].ReturnValue[exception]" and | ||
output = "ReturnValue[exception]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.