Skip to content

Commit 546b0a9

Browse files
authored
Merge pull request #15763 from asgerf/js/escaping-instance-detection
JS: Improve detection of classes with escaping instances
2 parents 2896bfb + 6a0adff commit 546b0a9

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,16 @@ private predicate nameFromGlobal(DataFlow::Node node, string package, string nam
277277
(if node.getTopLevel().isExterns() then badness = -10 else badness = 10)
278278
}
279279

280+
/** Gets an API node whose value is exposed to client code. */
281+
private API::Node exposedNode() {
282+
result = API::moduleExport(_)
283+
or
284+
result = exposedNode().getASuccessor()
285+
}
286+
280287
/** Holds if an instance of `cls` can be exposed to client code. */
281288
private predicate hasEscapingInstance(DataFlow::ClassNode cls) {
282-
cls.getAnInstanceReference().flowsTo(any(API::Node n).asSink())
289+
cls.getAnInstanceReference().flowsTo(exposedNode().asSink())
283290
}
284291

285292
private predicate sourceNodeHasNameCandidate(

javascript/ql/test/library-tests/EndpointNaming/pack1/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ export function getEscapingInstance() {
1313
} // $ name=(pack1).getEscapingInstance
1414

1515
export function publicFunction() {} // $ name=(pack1).publicFunction
16+
17+
// Escapes into an upstream library, but is not exposed downstream
18+
class InternalClass {
19+
m() {}
20+
}
21+
require('foo').bar(new InternalClass());

0 commit comments

Comments
 (0)