JS: Prevent bad join in hasOwnProperty

This commit is contained in:
Asger F
2019-05-30 14:13:48 +01:00
parent 71c86fa69b
commit 779d98a143

View File

@@ -67,14 +67,31 @@ class LocalObject extends DataFlow::SourceNode {
not exposedAsReceiver(this)
}
pragma[nomagic]
predicate hasOwnProperty(string name) {
// the property is defined in the initializer,
any(DataFlow::PropWrite write).writes(this, name, _) and
// and it is never deleted
not exists(DeleteExpr del, DataFlow::PropRef ref |
not hasDeleteWithName(name) and
// and there is no deleted property with computed name
not hasDeleteWithComputedProperty()
}
pragma[noinline]
private predicate hasDeleteWithName(string name) {
exists(DeleteExpr del, DataFlow::PropRef ref |
del.getOperand().flow() = ref and
flowsTo(ref.getBase()) and
(ref.getPropertyName() = name or not exists(ref.getPropertyName()))
ref.getPropertyName() = name
)
}
pragma[noinline]
private predicate hasDeleteWithComputedProperty() {
exists(DeleteExpr del, DataFlow::PropRef ref |
del.getOperand().flow() = ref and
flowsTo(ref.getBase()) and
not exists(ref.getPropertyName())
)
}
}