Skip to content

Commit 600e5ba

Browse files
committed
JS: Exclude methods declared private/protected
1 parent af1b04d commit 600e5ba

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

javascript/ql/lib/semmle/javascript/PackageExports.qll

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ private DataFlow::Node getAValueExportedByPackage() {
4545
|
4646
result = callee.getAPropertyRead("prototype").getAPropertyWrite(publicPropertyName()).getRhs()
4747
or
48-
result = callee.(DataFlow::ClassNode).getInstanceMethod(publicPropertyName())
48+
result = callee.(DataFlow::ClassNode).getInstanceMethod(publicPropertyName()) and
49+
not isPrivateMethodDeclaration(result)
4950
)
5051
or
5152
result = getAValueExportedByPackage().getALocalSource()
@@ -65,7 +66,10 @@ private DataFlow::Node getAValueExportedByPackage() {
6566
// static baz() {} // <- result
6667
// constructor() {} // <- result
6768
// };
68-
exists(DataFlow::ClassNode cla | cla = getAValueExportedByPackage() |
69+
exists(DataFlow::ClassNode cla |
70+
cla = getAValueExportedByPackage() and
71+
not isPrivateMethodDeclaration(result)
72+
|
6973
result = cla.getInstanceMethod(publicPropertyName()) or
7074
result = cla.getStaticMethod(publicPropertyName()) or
7175
result = cla.getConstructor()
@@ -185,3 +189,17 @@ bindingset[result]
185189
private string publicPropertyName() {
186190
result.regexpMatch("[a-zA-Z0-9].*")
187191
}
192+
193+
/**
194+
* Holds if the given function is part of a private (or protected) method declaration.
195+
*/
196+
private predicate isPrivateMethodDeclaration(DataFlow::FunctionNode func) {
197+
exists(MethodDeclaration decl |
198+
decl.getBody() = func.getFunction() and
199+
(
200+
decl.isPrivate()
201+
or
202+
decl.isProtected()
203+
)
204+
)
205+
}

0 commit comments

Comments
 (0)