Skip to content

Commit

Permalink
Merge pull request #15763 from asgerf/js/escaping-instance-detection
Browse files Browse the repository at this point in the history
JS: Improve detection of classes with escaping instances
  • Loading branch information
asgerf authored Mar 8, 2024
2 parents 2896bfb + 6a0adff commit 546b0a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,16 @@ private predicate nameFromGlobal(DataFlow::Node node, string package, string nam
(if node.getTopLevel().isExterns() then badness = -10 else badness = 10)
}

/** Gets an API node whose value is exposed to client code. */
private API::Node exposedNode() {
result = API::moduleExport(_)
or
result = exposedNode().getASuccessor()
}

/** Holds if an instance of `cls` can be exposed to client code. */
private predicate hasEscapingInstance(DataFlow::ClassNode cls) {
cls.getAnInstanceReference().flowsTo(any(API::Node n).asSink())
cls.getAnInstanceReference().flowsTo(exposedNode().asSink())
}

private predicate sourceNodeHasNameCandidate(
Expand Down
6 changes: 6 additions & 0 deletions javascript/ql/test/library-tests/EndpointNaming/pack1/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ export function getEscapingInstance() {
} // $ name=(pack1).getEscapingInstance

export function publicFunction() {} // $ name=(pack1).publicFunction

// Escapes into an upstream library, but is not exposed downstream
class InternalClass {
m() {}
}
require('foo').bar(new InternalClass());

0 comments on commit 546b0a9

Please sign in to comment.