-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 jump steps generated by IIFEs and exception flow #18043
Open
asgerf
wants to merge
19
commits into
github:js/shared-dataflow-branch
Choose a base branch
from
asgerf:jss/jump-and-test-exclusion
base: js/shared-dataflow-branch
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5ed362f
JS: Add exception test case
asgerf 7acc568
JS: Port exception steps to a universal summary
asgerf 7f2eae0
JS: Add test case for false flow through IIFEs
asgerf 37676f4
JS: Remove jump steps from IIFE steps
asgerf 023dcce
JS: Disable variable capture heuristic
asgerf d2daec4
JS: Add tests explaining why the IIFE in f2 didn't work
asgerf 80a5a59
JS: Use getUnderlyingValue() a few places in VariableCapture
asgerf 0166990
JS: Block InsecureRandomness flow into test files
asgerf d1c9e47
JS: More aggressive test file classification
asgerf b7dd455
JS: Add test case
asgerf dcdb2e5
JS: Fix callback check so it works without parameters
asgerf 948d21c
JS: Propagate exceptions from summarized callables by default
asgerf 84820ad
Add test for exception flow out of finally()
asgerf 4e62a51
JS: Only apply exception propagator when no other summary applies
asgerf ce00bd2
JS: More docs
asgerf 9dad2d6
JS: Update DataFlowConsistency
asgerf 1ac7591
JS: Update missed flow in capture-flow.js
asgerf 7a77432
JS: Update lost result in insecure-download
asgerf 930a7b6
JS: Update output changes to nodes/edges/subpaths
asgerf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import javascript | |
private import semmle.javascript.security.SensitiveActions | ||
import InsecureRandomnessCustomizations::InsecureRandomness | ||
private import InsecureRandomnessCustomizations::InsecureRandomness as InsecureRandomness | ||
private import semmle.javascript.filters.ClassifyFiles as ClassifyFiles | ||
|
||
/** | ||
* A taint tracking configuration for random values that are not cryptographically secure. | ||
|
@@ -20,7 +21,11 @@ module InsecureRandomnessConfig implements DataFlow::ConfigSig { | |
|
||
predicate isSink(DataFlow::Node sink) { sink instanceof Sink } | ||
|
||
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer } | ||
predicate isBarrier(DataFlow::Node node) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't seem to be tested? |
||
node instanceof Sanitizer | ||
or | ||
ClassifyFiles::isTestFile(node.getFile()) | ||
} | ||
|
||
predicate isBarrierOut(DataFlow::Node node) { | ||
// stop propagation at the sinks to avoid double reporting | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Currently"?
Is that hinting towards plans for a another solution in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this predicate can populated with jump steps that should be excluded, and currently the only use-case for this is the workaround mentioned. So it was meant to imply that other things could get added to the predicate as well.