Skip to content

Commit cf1e7cf

Browse files
author
Max Schaefer
committed
JavaScript: Move an auxiliary predicate into shared library.
1 parent a85dfb1 commit cf1e7cf

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ module PropertyInjection {
3636
// Assume that a value that is invoked can refer to a function.
3737
exists (node.getAnInvocation())
3838
}
39+
40+
/**
41+
* Holds if the `node` is of form `Object.create(null)` and so it has no prototype.
42+
*/
43+
predicate isPrototypeLessObject(DataFlow::MethodCallNode node) {
44+
node = DataFlow::globalVarRef("Object").getAMethodCall("create") and
45+
node.getArgument(0).asExpr() instanceof NullLiteral
46+
}
3947
}

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ module UnsafeDynamicMethodAccess {
7373
PropertyInjection::hasUnsafeMethods(node) // Redefined here so custom queries can override it
7474
}
7575

76-
/**
77-
* Holds if the `node` is of form `Object.create(null)` and so it has no prototype.
78-
*/
79-
predicate isPrototypeLessObject(DataFlow::MethodCallNode node) {
80-
node = DataFlow::globalVarRef("Object").getAMethodCall("create") and
81-
node.getArgument(0).asExpr() instanceof NullLiteral
82-
}
83-
8476
override predicate isAdditionalFlowStep(DataFlow::Node src, DataFlow::Node dst, DataFlow::FlowLabel srclabel, DataFlow::FlowLabel dstlabel) {
8577
// Reading a property of the global object or of a function
8678
exists (DataFlow::PropRead read |
@@ -92,7 +84,7 @@ module UnsafeDynamicMethodAccess {
9284
or
9385
// Reading a chain of properties from any object with a prototype can lead to Function
9486
exists (PropertyProjection proj |
95-
not isPrototypeLessObject(proj.getObject().getALocalSource()) and
87+
not PropertyInjection::isPrototypeLessObject(proj.getObject().getALocalSource()) and
9688
src = proj.getASelector() and
9789
dst = proj and
9890
(srclabel = data() or srclabel = taint()) and

0 commit comments

Comments
 (0)