introduce PropRef#mayHavePropertyName

This commit is contained in:
Erik Krogh Kristensen
2020-04-27 11:47:51 +02:00
parent 20c956e0a9
commit 1ad64bc619
3 changed files with 11 additions and 9 deletions

View File

@@ -537,6 +537,14 @@ module DataFlow {
*/
abstract Expr getPropertyNameExpr();
/**
* Holds if this property reference may access a property named `propName`.
*/
predicate mayHavePropertyName(string propName) {
propName = this.getPropertyName() or
this.getPropertyNameExpr().flow().mayHaveStringValue(propName)
}
/**
* Gets the name of the property being read or written,
* if it can be statically determined.

View File

@@ -552,7 +552,7 @@ module JQuery {
// Handle basic dynamic method dispatch (e.g. `$element[html ? 'html' : 'text'](content)`)
exists(DataFlow::PropRead read | read = this.getCalleeNode() |
read.getBase().getALocalSource() = [dollar(), objectRef()] and
read.getPropertyNameExpr().flow().mayHaveStringValue(name)
read.mayHavePropertyName(name)
)
or
// Handle contributed JQuery objects that aren't source nodes (usually parameter uses)
@@ -616,10 +616,7 @@ module JQuery {
)
) and
plugin = write.getRhs() and
(
pluginName = write.getPropertyName() or
write.getPropertyNameExpr().flow().mayHaveStringValue(pluginName)
)
write.mayHavePropertyName(pluginName)
)
}

View File

@@ -81,10 +81,7 @@ module XssThroughDom {
DOMTextSource() {
exists(DataFlow::PropRead read | read = this |
read.getBase().getALocalSource() = DOM::domValueRef() and
exists(string propName | propName = ["innerText", "textContent", "value", "name"] |
read.getPropertyName() = propName or
read.getPropertyNameExpr().flow().mayHaveStringValue(propName)
)
read.mayHavePropertyName(["innerText", "textContent", "value", "name"])
)
or
exists(DataFlow::MethodCallNode mcn | mcn = this |