Skip to content

Commit 493b377

Browse files
committed
JS: More precise isFunctionSource
1 parent 6d597be commit 493b377

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

javascript/ql/lib/semmle/javascript/endpoints/EndpointNaming.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,25 @@ private predicate sourceNodeHasPrimaryName(
267267
min(string n | sourceNodeHasNameCandidate(node, package, n, badness) | n order by n.length(), n)
268268
}
269269

270+
/** Gets a data flow node referring to a function value. */
271+
private DataFlow::SourceNode functionValue(DataFlow::TypeTracker t) {
272+
t.start() and
273+
(
274+
result instanceof DataFlow::FunctionNode
275+
or
276+
result instanceof DataFlow::ClassNode
277+
or
278+
result instanceof DataFlow::PartialInvokeNode
279+
)
280+
or
281+
exists(DataFlow::TypeTracker t2 | result = functionValue(t2).track(t2, t))
282+
}
283+
284+
/** Gets a data flow node referring to a function value. */
285+
private DataFlow::SourceNode functionValue() {
286+
result = functionValue(DataFlow::TypeTracker::end())
287+
}
288+
270289
/**
271290
* Holds if `node` is a function or a call that returns a function.
272291
*/
@@ -277,6 +296,7 @@ private predicate isFunctionSource(DataFlow::SourceNode node) {
277296
or
278297
node instanceof DataFlow::ClassNode
279298
or
299+
node = functionValue() and
280300
node instanceof DataFlow::InvokeNode and
281301
exists(node.getABoundFunctionValue(_)) and
282302
// `getASinkNode` steps through imports (but not other calls) so exclude calls that are imports (i.e. require calls)

0 commit comments

Comments
 (0)