-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Support integer subscripts in the API graph #15497
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
Draft
yoff
wants to merge
2
commits into
github:main
Choose a base branch
from
yoff:python/test-subscript-int
base: main
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.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import python | ||
private import semmle.python.dataflow.new.internal.DataFlowDispatch | ||
|
||
predicate resolvedCall(CallNode call, Function callable) { | ||
exists(DataFlowCallable dfCallable, DataFlowCall dfCall | | ||
dfCallable.getScope() = callable and | ||
dfCall.getNode() = call and | ||
dfCallable = viableCallable(dfCall) | ||
) | ||
} | ||
|
||
from Function f, CallNode call, string name | ||
where | ||
resolvedCall(call, f) and | ||
not call.getLocation().getFile().inStdlib() and | ||
f.getLocation().getFile().inStdlib() and | ||
f.getName() = name and | ||
name != "__init__" | ||
select name, f.getScope() |
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,136 @@ | ||
import python | ||
import semmle.python.dataflow.new.DataFlow | ||
import semmle.python.dataflow.new.TaintTracking | ||
|
||
pragma[inline] | ||
predicate inStdLib(DataFlow::Node node) { node.getLocation().getFile().inStdlib() } | ||
|
||
pragma[inline] | ||
string stepsTo(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) { | ||
if DataFlow::localFlow(nodeFrom, nodeTo) | ||
then result = "local" | ||
else | ||
if | ||
TaintTracking::localTaint(nodeFrom, nodeTo) | ||
or | ||
exists(TaintTracking::AdditionalTaintStep s | s.step(nodeFrom, nodeTo)) | ||
or | ||
exists( | ||
TaintTracking::AdditionalTaintStep s, DataFlow::Node entryNode, DataFlow::Node exitNode | ||
| | ||
s.step(entryNode, exitNode) | ||
| | ||
TaintTracking::localTaint(nodeFrom, entryNode) and | ||
TaintTracking::localTaint(exitNode, nodeTo) | ||
) | ||
then result = "taint" | ||
else result = "no" | ||
} | ||
|
||
abstract class EntryPointsByQuery extends string { | ||
bindingset[this] | ||
EntryPointsByQuery() { any() } | ||
|
||
abstract predicate subpath( | ||
DataFlow::Node argument, DataFlow::ParameterNode parameter, DataFlow::Node outNode | ||
); | ||
|
||
predicate entryPoint( | ||
DataFlow::Node argument, string parameterName, string functionName, DataFlow::Node outNode, | ||
string alreadyModelled | ||
) { | ||
exists(DataFlow::ParameterNode parameter, Function function | | ||
parameterName = parameter.getParameter().getName() and | ||
functionName = function.getLocation().getFile().getShortName() + ":" + function.getName() | ||
| | ||
this.subpath(argument, parameter, outNode) and | ||
not inStdLib(argument) and | ||
inStdLib(parameter) and | ||
function = parameter.getScope() and | ||
alreadyModelled = stepsTo(argument, outNode) | ||
) | ||
} | ||
} | ||
|
||
module EntryPointsForRegexInjectionQuery { | ||
private import semmle.python.security.dataflow.RegexInjectionQuery | ||
|
||
module Flow = RegexInjectionFlow; | ||
|
||
private import Flow::PathGraph | ||
|
||
private class EntryPointsForRegexInjectionQuery extends EntryPointsByQuery { | ||
EntryPointsForRegexInjectionQuery() { this = "RegexInjectionQuery" } | ||
|
||
override predicate subpath( | ||
DataFlow::Node argument, DataFlow::ParameterNode parameter, DataFlow::Node outNode | ||
) { | ||
exists(Flow::PathNode arg, Flow::PathNode par, Flow::PathNode out | | ||
subpaths(arg, par, _, out) | ||
| | ||
argument = arg.getNode() and | ||
parameter = par.getNode() and | ||
outNode = out.getNode() | ||
) | ||
} | ||
} | ||
} | ||
|
||
module EntryPointsForUnsafeShellCommandConstructionQuery { | ||
private import semmle.python.security.dataflow.UnsafeShellCommandConstructionQuery | ||
|
||
module Flow = UnsafeShellCommandConstructionFlow; | ||
|
||
private import Flow::PathGraph | ||
|
||
private class EntryPointsForUnsafeShellCommandConstructionQuery extends EntryPointsByQuery { | ||
EntryPointsForUnsafeShellCommandConstructionQuery() { | ||
this = "UnsafeShellCommandConstructionQuery" | ||
} | ||
|
||
override predicate subpath( | ||
DataFlow::Node argument, DataFlow::ParameterNode parameter, DataFlow::Node outNode | ||
) { | ||
exists(Flow::PathNode arg, Flow::PathNode par, Flow::PathNode out | | ||
subpaths(arg, par, _, out) | ||
| | ||
argument = arg.getNode() and | ||
parameter = par.getNode() and | ||
outNode = out.getNode() | ||
) | ||
} | ||
} | ||
} | ||
|
||
module EntryPointsForPolynomialReDoSQuery { | ||
private import semmle.python.security.dataflow.PolynomialReDoSQuery | ||
|
||
module Flow = PolynomialReDoSFlow; | ||
|
||
private import Flow::PathGraph | ||
|
||
private class EntryPointsForPolynomialReDoSQuery extends EntryPointsByQuery { | ||
EntryPointsForPolynomialReDoSQuery() { this = "PolynomialReDoSQuery" } | ||
|
||
override predicate subpath( | ||
DataFlow::Node argument, DataFlow::ParameterNode parameter, DataFlow::Node outNode | ||
) { | ||
exists(Flow::PathNode arg, Flow::PathNode par, Flow::PathNode out | | ||
subpaths(arg, par, _, out) | ||
| | ||
argument = arg.getNode() and | ||
parameter = par.getNode() and | ||
outNode = out.getNode() | ||
) | ||
} | ||
} | ||
} | ||
|
||
from | ||
EntryPointsByQuery e, DataFlow::Node argument, string parameter, string functionName, | ||
DataFlow::Node outNode, string alreadyModelled | ||
Check warningCode scanning / CodeQL Misspelling
This variable name contains the non-US spelling 'modelled', which should instead be 'modeled'.
|
||
where | ||
e.entryPoint(argument, parameter, functionName, outNode, alreadyModelled) and | ||
alreadyModelled = "no" | ||
// select e, argument, parameter, functionName, outNode, alreadyModelled | ||
select e, parameter, functionName, alreadyModelled |
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
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.
Check warning
Code scanning / CodeQL
Misspelling