Skip to content

Commit ac26741

Browse files
committed
reuse existing SanitizerGuard from UnsafeJQueryPlugin
1 parent 0a29d13 commit ac26741

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/XssThroughDom.qll

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module XssThroughDom {
1212
import Xss::XssThroughDom
1313
private import semmle.javascript.security.dataflow.Xss::DomBasedXss as DomBasedXss
1414
private import semmle.javascript.dataflow.InferredTypes
15+
private import semmle.javascript.security.dataflow.UnsafeJQueryPluginCustomizations::UnsafeJQueryPlugin as UnsafeJQuery
1516

1617
/**
1718
* A taint-tracking configuration for reasoning about XSS through the DOM.
@@ -30,7 +31,7 @@ module XssThroughDom {
3031

3132
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode guard) {
3233
guard instanceof TypeTestGuard or
33-
guard instanceof HasNodePropertySanitizerGuard
34+
guard instanceof UnsafeJQuery::PropertyPresenceSanitizer
3435
}
3536
}
3637

@@ -122,22 +123,4 @@ module XssThroughDom {
122123
e = typeof.getOperand()
123124
}
124125
}
125-
126-
/**
127-
* The precense of a `nodeType` or `jquery` property indicates that the value is a DOM node, and not the text of a DOM node.
128-
*
129-
* This sanitizer helps prune infeasible paths in type-overloaded functions.
130-
*/
131-
class HasNodePropertySanitizerGuard extends TaintTracking::SanitizerGuardNode {
132-
DataFlow::PropRead read;
133-
134-
HasNodePropertySanitizerGuard() {
135-
read = this and
136-
read.getPropertyName() = ["nodeType", "jquery"]
137-
}
138-
139-
override predicate sanitizes(boolean outcome, Expr e) {
140-
e = read.getBase().asExpr() and outcome = true
141-
}
142-
}
143126
}

javascript/ql/test/query-tests/Security/CWE-079/xss-through-dom.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,9 @@
6262

6363
var valMethod = $("textarea").val;
6464
$("#id").get(0).innerHTML = valMethod(); // NOT OK
65+
66+
var myValue = $(document).find("option").attr("value");
67+
if(myValue.property) {
68+
$("#id").get(0).innerHTML = myValue; // OK.
69+
}
6570
})();

0 commit comments

Comments
 (0)