reuse existing SanitizerGuard from UnsafeJQueryPlugin

This commit is contained in:
Erik Krogh Kristensen
2020-04-22 14:16:15 +02:00
parent 0a29d132d0
commit ac26741816
2 changed files with 7 additions and 19 deletions

View File

@@ -12,6 +12,7 @@ module XssThroughDom {
import Xss::XssThroughDom
private import semmle.javascript.security.dataflow.Xss::DomBasedXss as DomBasedXss
private import semmle.javascript.dataflow.InferredTypes
private import semmle.javascript.security.dataflow.UnsafeJQueryPluginCustomizations::UnsafeJQueryPlugin as UnsafeJQuery
/**
* A taint-tracking configuration for reasoning about XSS through the DOM.
@@ -30,7 +31,7 @@ module XssThroughDom {
override predicate isSanitizerGuard(TaintTracking::SanitizerGuardNode guard) {
guard instanceof TypeTestGuard or
guard instanceof HasNodePropertySanitizerGuard
guard instanceof UnsafeJQuery::PropertyPresenceSanitizer
}
}
@@ -122,22 +123,4 @@ module XssThroughDom {
e = typeof.getOperand()
}
}
/**
* The precense of a `nodeType` or `jquery` property indicates that the value is a DOM node, and not the text of a DOM node.
*
* This sanitizer helps prune infeasible paths in type-overloaded functions.
*/
class HasNodePropertySanitizerGuard extends TaintTracking::SanitizerGuardNode {
DataFlow::PropRead read;
HasNodePropertySanitizerGuard() {
read = this and
read.getPropertyName() = ["nodeType", "jquery"]
}
override predicate sanitizes(boolean outcome, Expr e) {
e = read.getBase().asExpr() and outcome = true
}
}
}

View File

@@ -62,4 +62,9 @@
var valMethod = $("textarea").val;
$("#id").get(0).innerHTML = valMethod(); // NOT OK
var myValue = $(document).find("option").attr("value");
if(myValue.property) {
$("#id").get(0).innerHTML = myValue; // OK.
}
})();