-
Notifications
You must be signed in to change notification settings - Fork 1.7k
JS: Derive type-tracking steps from flow summaries #18125
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
Merged
asgerf
merged 9 commits into
github:js/shared-dataflow-branch
from
asgerf:jss/summary-type-tracker
Dec 3, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
df12f25
JS: Rename propagatesFlowExt -> propagatesFlow
asgerf e34064e
JS: Initial instantiation of sumamry type tracking
asgerf 6349903
JS: Move FlowSummary/Summaries.qll into testUtilities
asgerf 440cbb7
JS: Add inline-expectation test for type tracking
asgerf 2f0c80a
JS: Include summary steps in type tracking
asgerf 9c6b698
JS: Add test to restrict dependencies
asgerf cab8a40
JS: Fix accidental recursion
asgerf 8bca664
JS: Add test showing lack of inclusion in PropertyName
asgerf 054558d
JS: Include content properties in type-tracker properties
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 hidden or 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 hidden or 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 hidden or 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
83 changes: 83 additions & 0 deletions
83
javascript/ql/lib/semmle/javascript/dataflow/internal/sharedlib/SummaryTypeTracker.qll
This file contains hidden or 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,83 @@ | ||
private import semmle.javascript.Locations | ||
private import codeql.typetracking.internal.SummaryTypeTracker | ||
private import semmle.javascript.dataflow.internal.DataFlowPrivate as DataFlowPrivate | ||
private import semmle.javascript.dataflow.FlowSummary as FlowSummary | ||
private import FlowSummaryImpl as FlowSummaryImpl | ||
private import DataFlowArg | ||
|
||
private module SummaryFlowConfig implements Input { | ||
import JSDataFlow | ||
import FlowSummaryImpl::Public | ||
import FlowSummaryImpl::Private | ||
import FlowSummaryImpl::Private::SummaryComponent | ||
|
||
class Content = DataFlow::ContentSet; | ||
|
||
class ContentFilter extends Unit { | ||
ContentFilter() { none() } | ||
} | ||
|
||
ContentFilter getFilterFromWithoutContentStep(Content content) { none() } | ||
|
||
ContentFilter getFilterFromWithContentStep(Content content) { none() } | ||
|
||
predicate singleton = SummaryComponentStack::singleton/1; | ||
|
||
predicate push = SummaryComponentStack::push/2; | ||
|
||
SummaryComponent return() { | ||
result = SummaryComponent::return(DataFlowPrivate::MkNormalReturnKind()) | ||
} | ||
|
||
Node argumentOf(Node call, SummaryComponent arg, boolean isPostUpdate) { | ||
// Note: we cannot rely on DataFlowPrivate::DataFlowCall here because that depends on the call graph. | ||
exists(ArgumentPosition apos, ParameterPosition ppos, Node argNode | | ||
arg = argument(ppos) and | ||
parameterMatch(ppos, apos) and | ||
( | ||
argNode = call.(DataFlow::InvokeNode).getArgument(apos.asPositional()) | ||
or | ||
apos.isThis() and | ||
argNode = call.(DataFlow::CallNode).getReceiver() | ||
) | ||
| | ||
isPostUpdate = true and result = argNode.getPostUpdateNode() | ||
or | ||
isPostUpdate = false and result = argNode | ||
) | ||
} | ||
|
||
Node parameterOf(Node callable, SummaryComponent param) { | ||
exists(ArgumentPosition apos, ParameterPosition ppos, DataFlow::FunctionNode function | | ||
param = parameter(apos) and | ||
parameterMatch(ppos, apos) and | ||
callable = function | ||
| | ||
result = function.getParameter(ppos.asPositional()) | ||
or | ||
ppos.isThis() and | ||
result = function.getReceiver() | ||
) | ||
} | ||
|
||
Node returnOf(Node callable, SummaryComponent return) { | ||
return = return() and | ||
result = callable.(DataFlow::FunctionNode).getReturnNode() | ||
} | ||
|
||
class SummarizedCallable instanceof SummarizedCallableImpl { | ||
predicate propagatesFlow( | ||
SummaryComponentStack input, SummaryComponentStack output, boolean preservesValue | ||
) { | ||
super.propagatesFlow(input, output, preservesValue, _) | ||
} | ||
|
||
string toString() { result = super.toString() } | ||
} | ||
|
||
Node callTo(SummarizedCallable callable) { | ||
result = callable.(FlowSummary::SummarizedCallable).getACallSimple() | ||
} | ||
} | ||
|
||
import SummaryFlow<SummaryFlowConfig> |
This file contains hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.