-
Notifications
You must be signed in to change notification settings - Fork 1.9k
ATM: Boost XssThroughDOM #11486
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
Merged
ATM: Boost XssThroughDOM #11486
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b885249
Add a boosted version of XssThroughDOM
tiferet f388703
ATM: update further files following the addition of XssThroughDom query
jhelie 50a3c0d
ATM: update expected ML test values
jhelie 880548b
Merge branch 'main' into tiferet/boost-xss-through-dom
jhelie ae0d82e
ATM: update predicate name
jhelie 98923ce
ATM: update missing .qll
jhelie 352d1a7
ATM: update tests
jhelie 155c146
Merge branch 'main' into tiferet/boost-xss-through-dom
jhelie 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
88 changes: 88 additions & 0 deletions
88
...ental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/XssThroughDomATM.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,88 @@ | ||
| /** | ||
| * For internal use only. | ||
| * | ||
| * A taint-tracking configuration for reasoning about XSS through the DOM. | ||
| * Defines shared code used by the XSS Through DOM boosted query. | ||
| */ | ||
|
|
||
| private import semmle.javascript.heuristics.SyntacticHeuristics | ||
| private import semmle.javascript.security.dataflow.DomBasedXssCustomizations | ||
| private import semmle.javascript.dataflow.InferredTypes | ||
| private import semmle.javascript.security.dataflow.XssThroughDomCustomizations::XssThroughDom as XssThroughDom | ||
| private import semmle.javascript.security.dataflow.UnsafeJQueryPluginCustomizations::UnsafeJQueryPlugin as UnsafeJQuery | ||
| import AdaptiveThreatModeling | ||
|
|
||
| class XssThroughDomAtmConfig extends AtmConfig { | ||
| XssThroughDomAtmConfig() { this = "XssThroughDomAtmConfig" } | ||
|
|
||
| override predicate isKnownSource(DataFlow::Node source) { | ||
| source instanceof XssThroughDom::Source | ||
| } | ||
|
|
||
| override EndpointType getASinkEndpointType() { result instanceof XssSinkType } | ||
|
|
||
| override predicate isSanitizer(DataFlow::Node node) { | ||
| super.isSanitizer(node) or | ||
| node instanceof DomBasedXss::Sanitizer | ||
| } | ||
|
|
||
| override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode guard) { | ||
| guard instanceof TypeTestGuard or | ||
| guard instanceof UnsafeJQuery::PropertyPresenceSanitizer or | ||
| guard instanceof UnsafeJQuery::NumberGuard or | ||
| guard instanceof PrefixStringSanitizer or | ||
| guard instanceof QuoteGuard or | ||
| guard instanceof ContainsHtmlGuard | ||
| } | ||
|
|
||
| override predicate isSanitizerEdge(DataFlow::Node pred, DataFlow::Node succ) { | ||
| DomBasedXss::isOptionallySanitizedEdge(pred, succ) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A test of form `typeof x === "something"`, preventing `x` from being a string in some cases. | ||
| * | ||
| * This sanitizer helps prune infeasible paths in type-overloaded functions. | ||
| */ | ||
| class TypeTestGuard extends TaintTracking::SanitizerGuardNode, DataFlow::ValueNode { | ||
| override EqualityTest astNode; | ||
| Expr operand; | ||
| boolean polarity; | ||
|
|
||
| TypeTestGuard() { | ||
| exists(TypeofTag tag | TaintTracking::isTypeofGuard(astNode, operand, tag) | | ||
| // typeof x === "string" sanitizes `x` when it evaluates to false | ||
| tag = "string" and | ||
| polarity = astNode.getPolarity().booleanNot() | ||
| or | ||
| // typeof x === "object" sanitizes `x` when it evaluates to true | ||
| tag != "string" and | ||
| polarity = astNode.getPolarity() | ||
| ) | ||
| } | ||
|
|
||
| override predicate sanitizes(boolean outcome, Expr e) { | ||
| polarity = outcome and | ||
| e = operand | ||
| } | ||
| } | ||
|
|
||
| private import semmle.javascript.security.dataflow.Xss::Shared as Shared | ||
|
|
||
| private class PrefixStringSanitizer extends TaintTracking::SanitizerGuardNode, | ||
| DomBasedXss::PrefixStringSanitizer { | ||
| PrefixStringSanitizer() { this = this } | ||
| } | ||
|
|
||
| private class PrefixString extends DataFlow::FlowLabel, DomBasedXss::PrefixString { | ||
| PrefixString() { this = this } | ||
| } | ||
|
|
||
| private class QuoteGuard extends TaintTracking::SanitizerGuardNode, Shared::QuoteGuard { | ||
| QuoteGuard() { this = this } | ||
| } | ||
|
|
||
| private class ContainsHtmlGuard extends TaintTracking::SanitizerGuardNode, Shared::ContainsHtmlGuard { | ||
| ContainsHtmlGuard() { this = this } | ||
| } |
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
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: 25 additions & 0 deletions
25
javascript/ql/experimental/adaptivethreatmodeling/src/XssThroughDomATM.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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * For internal use only. | ||
| * | ||
| * @name DOM text reinterpreted as HTML (experimental) | ||
| * @description Reinterpreting text from the DOM as HTML can lead | ||
| * to a cross-site scripting vulnerability. | ||
| * @kind path-problem | ||
| * @scored | ||
| * @problem.severity error | ||
| * @security-severity 6.1 | ||
| * @id js/ml-powered/xss-through-dom | ||
| * @tags experimental security | ||
| * external/cwe/cwe-079 external/cwe/cwe-116 | ||
| */ | ||
|
|
||
| import javascript | ||
| import ATM::ResultsInfo | ||
| import DataFlow::PathGraph | ||
| import experimental.adaptivethreatmodeling.XssThroughDomATM | ||
|
|
||
| from AtmConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink, float score | ||
| where cfg.hasBoostedFlowPath(source, sink, score) | ||
| select sink.getNode(), source, sink, | ||
| "(Experimental) $@ may be reinterpreted as HTML without escaping meta-characters. Identified using machine learning.", | ||
| source.getNode(), "DOM text", score | ||
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.
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.
Shall we just remove this comment now, so we don't forget later? Here and in the corresponding QLL file.
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.
This comment is present in all ATM-related
.qland.qllso probably best done in a separate PR given the churn. I'll open one.