Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
ATM: Simplify query configurations#11323
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5402f04
Delete `CoreKnowledge`.
tiferet 05a943c
Delete `StandardEndpointFilters`.
tiferet 50291c7
`AtmConfig` inherits from `TaintTracking::Configuration`.
tiferet cd24ec8
Move the definition of `isSource` to the base class:
tiferet a710b72
Move the definition of `isSink` to the base class:
tiferet 75cd7a9
Remove code duplication in query .ql files:
tiferet 6f807e9
Doc suggestion from code review
tiferet c5184d3
Suggestion from code review:
tiferet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
27 changes: 26 additions & 1 deletion
27 ...experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/ATMConfig.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
96 changes: 45 additions & 51 deletions
96 ...ntal/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/NosqlInjectionATM.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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| /** | ||
| * For internal use only. | ||
| * | ||
| * A taint-tracking configuration for reasoning about NoSQL injection vulnerabilities. | ||
| * Defines shared code used by the NoSQL injection boosted query. | ||
| */ | ||
| @@ -10,62 +11,19 @@ private import semmle.javascript.security.dataflow.NosqlInjectionCustomizations | ||
| import AdaptiveThreatModeling | ||
| class NosqlInjectionAtmConfig extends AtmConfig { | ||
| NosqlInjectionAtmConfig() { this = "NosqlInjectionATMConfig" } | ||
| NosqlInjectionAtmConfig() { this = "NosqlInjectionAtmConfig" } | ||
| override predicate isKnownSource(DataFlow::Node source) { | ||
| source instanceof NosqlInjection::Source or TaintedObject::isSource(source, _) | ||
| } | ||
| override EndpointType getASinkEndpointType() { result instanceof NosqlInjectionSinkType } | ||
| } | ||
| /** DEPRECATED: Alias for NosqlInjectionAtmConfig */ | ||
| deprecated class NosqlInjectionATMConfig = NosqlInjectionAtmConfig; | ||
| /** Holds if src -> trg is an additional flow step in the non-boosted NoSql injection security query. */ | ||
| predicate isBaseAdditionalFlowStep( | ||
| DataFlow::Node src, DataFlow::Node trg, DataFlow::FlowLabel inlbl, DataFlow::FlowLabel outlbl | ||
| ) { | ||
| TaintedObject::step(src, trg, inlbl, outlbl) | ||
| or | ||
| // additional flow step to track taint through NoSQL query objects | ||
| inlbl = TaintedObject::label() and | ||
| outlbl = TaintedObject::label() and | ||
| exists(NoSql::Query query, DataFlow::SourceNode queryObj | | ||
| queryObj.flowsTo(query) and | ||
| queryObj.flowsTo(trg) and | ||
| src = queryObj.getAPropertyWrite().getRhs() | ||
| ) | ||
| } | ||
| /** | ||
| * Gets a value that is (transitively) written to `query`, where `query` is a NoSQL sink. | ||
| * | ||
| * This predicate allows us to propagate data flow through property writes and array constructors | ||
| * within a query object, enabling the security query to pick up NoSQL injection vulnerabilities | ||
| * involving more complex queries. | ||
| */ | ||
| DataFlow::Node getASubexpressionWithinQuery(DataFlow::Node query) { | ||
| any(NosqlInjectionAtmConfig cfg).isEffectiveSink(query) and | ||
| exists(DataFlow::SourceNode receiver | | ||
| receiver = [getASubexpressionWithinQuery(query), query].getALocalSource() | ||
| | | ||
| result = | ||
| [receiver.getAPropertyWrite().getRhs(), receiver.(DataFlow::ArrayCreationNode).getAnElement()] | ||
| ) | ||
| } | ||
| /** | ||
| * A taint-tracking configuration for reasoning about NoSQL injection vulnerabilities. | ||
| * | ||
| * This is largely a copy of the taint tracking configuration for the standard NoSQL injection | ||
| * query, except additional ATM sinks have been added and the additional flow step has been | ||
| * generalised to cover the sinks predicted by ATM. | ||
| */ | ||
| class Configuration extends TaintTracking::Configuration { | ||
| Configuration() { this = "NosqlInjectionATM" } | ||
| override predicate isSource(DataFlow::Node source) { source instanceof NosqlInjection::Source } | ||
kaeluka marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| /* | ||
| * This is largely a copy of the taint tracking configuration for the standard NoSQL injection | ||
| * query, except additional ATM sinks have been added and the additional flow step has been | ||
| * generalised to cover the sinks predicted by ATM. | ||
| */ | ||
| override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) { | ||
| TaintedObject::isSource(source, label) | ||
| @@ -75,7 +33,7 @@ class Configuration extends TaintTracking::Configuration { | ||
| sink.(NosqlInjection::Sink).getAFlowLabel() = label | ||
| or | ||
| // Allow effective sinks to have any taint label | ||
| any(NosqlInjectionAtmConfig cfg).isEffectiveSink(sink) | ||
| isEffectiveSink(sink) | ||
| } | ||
| override predicate isSanitizer(DataFlow::Node node) { | ||
| @@ -94,7 +52,43 @@ class Configuration extends TaintTracking::Configuration { | ||
| isBaseAdditionalFlowStep(src, trg, inlbl, outlbl) | ||
| or | ||
| // relaxed version of previous step to track taint through unmodeled NoSQL query objects | ||
| any(NosqlInjectionAtmConfig cfg).isEffectiveSink(trg) and | ||
| isEffectiveSink(trg) and | ||
| src = getASubexpressionWithinQuery(trg) | ||
| } | ||
| /** Holds if src -> trg is an additional flow step in the non-boosted NoSql injection security query. */ | ||
| private predicate isBaseAdditionalFlowStep( | ||
| DataFlow::Node src, DataFlow::Node trg, DataFlow::FlowLabel inlbl, DataFlow::FlowLabel outlbl | ||
| ) { | ||
| TaintedObject::step(src, trg, inlbl, outlbl) | ||
| or | ||
| // additional flow step to track taint through NoSQL query objects | ||
| inlbl = TaintedObject::label() and | ||
| outlbl = TaintedObject::label() and | ||
| exists(NoSql::Query query, DataFlow::SourceNode queryObj | | ||
| queryObj.flowsTo(query) and | ||
| queryObj.flowsTo(trg) and | ||
| src = queryObj.getAPropertyWrite().getRhs() | ||
| ) | ||
| } | ||
| /** | ||
| * Gets a value that is (transitively) written to `query`, where `query` is a NoSQL sink. | ||
| * | ||
| * This predicate allows us to propagate data flow through property writes and array constructors | ||
| * within a query object, enabling the security query to pick up NoSQL injection vulnerabilities | ||
| * involving more complex queries. | ||
| */ | ||
| private DataFlow::Node getASubexpressionWithinQuery(DataFlow::Node query) { | ||
| isEffectiveSink(query) and | ||
| exists(DataFlow::SourceNode receiver | | ||
| receiver = [getASubexpressionWithinQuery(query), query].getALocalSource() | ||
| | | ||
| result = | ||
| [ | ||
| receiver.getAPropertyWrite().getRhs(), | ||
| receiver.(DataFlow::ArrayCreationNode).getAnElement() | ||
| ] | ||
| ) | ||
| } | ||
| } | ||
25 changes: 6 additions & 19 deletions
25 ...mental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/SqlInjectionATM.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
25 changes: 8 additions & 17 deletions
25 ...imental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/TaintedPathATM.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
26 changes: 6 additions & 20 deletions
26 ...ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/XssATM.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
9 changes: 5 additions & 4 deletions
9 ...erimental/adaptivethreatmodeling/modelbuilding/extraction/ExtractEndpointDataTraining.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
7 changes: 2 additions & 5 deletions
7 javascript/ql/experimental/adaptivethreatmodeling/src/NosqlInjectionATM.ql
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 |
|---|---|---|
| @@ -17,11 +17,8 @@ import ATM::ResultsInfo | ||
| import DataFlow::PathGraph | ||
| import experimental.adaptivethreatmodeling.NosqlInjectionATM | ||
| from DataFlow::Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score | ||
| where | ||
| cfg.hasFlowPath(source, sink) and | ||
| not isFlowLikelyInBaseQuery(source.getNode(), sink.getNode()) and | ||
| score = getScoreForFlow(source.getNode(), sink.getNode()) | ||
| from AtmConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score | ||
| where cfg.getAlerts(source, sink, score) | ||
tiferet marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| select sink.getNode(), source, sink, | ||
| "(Experimental) This may be a database query that depends on $@. Identified using machine learning.", | ||
| source.getNode(), "a user-provided value", score | ||
7 changes: 2 additions & 5 deletions
7 javascript/ql/experimental/adaptivethreatmodeling/src/SqlInjectionATM.ql
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
7 changes: 2 additions & 5 deletions
7 javascript/ql/experimental/adaptivethreatmodeling/src/TaintedPathATM.ql
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Minor/bikeshed: I'd prefer a name that doesn't suggest a return/result value, and mentions flow. Also makes it easier to see the parallels between unboosted and boosted queries. How about
hasLikelyFlowPath?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.
I don't know about
hasLikelyFlowPath, because one of the conditions it must meet ishasFlowPath. LogicallyhasFlowPathshould implyhasLikelyFlowPath.Maybe something like
hasBoostedFlowPath? We've been trying to get rid of the "boosted" terminology, but I can't think of something better right now. I thinkhasAlertwould be clearer (ultimately that's what this predicate does -- it surfaces all the alerts for this config), but that doesn't mention flow.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.
Note: I tracked this renaming together with the other renamings here, so that we can merge this PR and XssThroughDOM and open a separate PR for all the renamings