add support for Object.hasOwn(obj, key)

This commit is contained in:
Erik Krogh Kristensen
2022-05-24 13:47:41 +02:00
parent 1717d17fb3
commit 2a97dd9f6f
11 changed files with 171 additions and 10 deletions

View File

@@ -234,6 +234,14 @@ module MembershipCandidate {
test = hasOwn and
hasOwn.calls(membersNode, "hasOwnProperty")
)
or
exists(DataFlow::CallNode hasOwn |
hasOwn = DataFlow::globalVarRef("Object").getAMemberCall("hasOwn")
|
hasOwn.getArgument(0).asExpr() = membersNode and
this = hasOwn.getArgument(1) and
test = hasOwn.asExpr()
)
}
override DataFlow::Node getTest() { result = test.flow() }

View File

@@ -1027,18 +1027,16 @@ module TaintTracking {
class WhitelistContainmentCallSanitizer extends AdditionalSanitizerGuardNode,
DataFlow::MethodCallNode {
WhitelistContainmentCallSanitizer() {
exists(string name |
name = "contains" or
name = "has" or
name = "hasOwnProperty"
|
this.getMethodName() = name
)
this.getMethodName() = ["contains", "has", "hasOwnProperty", "hasOwn"]
}
override predicate sanitizes(boolean outcome, Expr e) {
outcome = true and
e = this.getArgument(0).asExpr()
exists(int propertyIndex |
if this.getMethodName() = "hasOwn" then propertyIndex = 1 else propertyIndex = 0
|
outcome = true and
e = this.getArgument(propertyIndex).asExpr()
)
}
override predicate appliesTo(Configuration cfg) { any() }