Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2818fa6

Browse files
committed
JS: Updates to shared Xss.qll
1 parent 547a8a9 commit 2818fa6

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

  • javascript/ql/lib/semmle/javascript/security/dataflow

javascript/ql/lib/semmle/javascript/security/dataflow/Xss.qll

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,62 @@ module Shared {
7272
private import semmle.javascript.security.dataflow.IncompleteHtmlAttributeSanitizationCustomizations::IncompleteHtmlAttributeSanitization as IncompleteHtml
7373

7474
/**
75-
* A guard that checks if a string can contain quotes, which is a guard for strings that are inside an HTML attribute.
75+
* A barrier guard that applies to multiple XSS queries.
76+
*/
77+
abstract class BarrierGuard extends DataFlow::Node {
78+
/**
79+
* Holds if this node acts as a barrier for data flow, blocking further flow from `e` if `this` evaluates to `outcome`.
80+
*/
81+
predicate blocksExpr(boolean outcome, Expr e) { none() }
82+
}
83+
84+
/**
85+
* A barrier guard that applies to multiple XSS queries.
7686
*/
77-
abstract class QuoteGuard extends TaintTracking::SanitizerGuardNode, StringOps::Includes {
78-
QuoteGuard() {
87+
module BarrierGuard = DataFlow::MakeBarrierGuard<BarrierGuard>;
88+
89+
private class QuoteGuard2 extends BarrierGuard, StringOps::Includes {
90+
QuoteGuard2() {
7991
this.getSubstring().mayHaveStringValue("\"") and
8092
this.getBaseString()
8193
.getALocalSource()
8294
.flowsTo(any(IncompleteHtml::HtmlAttributeConcatenation attributeConcat))
8395
}
8496

85-
override predicate sanitizes(boolean outcome, Expr e) {
97+
override predicate blocksExpr(boolean outcome, Expr e) {
8698
e = this.getBaseString().getEnclosingExpr() and outcome = this.getPolarity().booleanNot()
8799
}
88100
}
89101

90102
/**
91-
* A sanitizer guard that checks for the existence of HTML chars in a string.
92-
* E.g. `/["'&<>]/.exec(str)`.
103+
* A guard that checks if a string can contain quotes, which is a guard for strings that are inside an HTML attribute.
93104
*/
94-
abstract class ContainsHtmlGuard extends TaintTracking::SanitizerGuardNode, StringOps::RegExpTest {
95-
ContainsHtmlGuard() {
105+
abstract class QuoteGuard extends TaintTracking::SanitizerGuardNode instanceof QuoteGuard2 {
106+
override predicate sanitizes(boolean outcome, Expr e) { super.blocksExpr(outcome, e) }
107+
}
108+
109+
private class ContainsHtmlGuard2 extends BarrierGuard, StringOps::RegExpTest {
110+
ContainsHtmlGuard2() {
96111
exists(RegExpCharacterClass regExp |
97112
regExp = this.getRegExp() and
98113
forall(string s | s = ["\"", "&", "<", ">"] | regExp.getAMatchedString() = s)
99114
)
100115
}
101116

102-
override predicate sanitizes(boolean outcome, Expr e) {
117+
override predicate blocksExpr(boolean outcome, Expr e) {
103118
outcome = this.getPolarity().booleanNot() and e = this.getStringOperand().asExpr()
104119
}
105120
}
106121

122+
/**
123+
* A sanitizer guard that checks for the existence of HTML chars in a string.
124+
* E.g. `/["'&<>]/.exec(str)`.
125+
*/
126+
abstract class ContainsHtmlGuard extends TaintTracking::SanitizerGuardNode instanceof ContainsHtmlGuard2
127+
{
128+
override predicate sanitizes(boolean outcome, Expr e) { super.blocksExpr(outcome, e) }
129+
}
130+
107131
/**
108132
* Holds if `str` is used in a switch-case that has cases matching HTML escaping.
109133
*/

0 commit comments

Comments
 (0)