Skip to content

Commit bbbb0a2

Browse files
committed
specialize module.createRequire support to ES2015 modules
1 parent 1e65ed2 commit bbbb0a2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

javascript/ql/src/semmle/javascript/NodeJS.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,16 @@ private predicate isRequire(DataFlow::Node nd) {
163163
or
164164
isRequire(nd.getAPredecessor())
165165
or
166-
nd = DataFlow::moduleMember("module", "createRequire").getACall()
166+
// `import { createRequire } from 'module';` support.
167+
// specialized to ES2015 modules to avoid recursion in the `DataFlow::moduleImport()` predicate.
168+
exists(ImportDeclaration imp | imp.getImportedPath().getValue() = "module" |
169+
nd =
170+
imp
171+
.getImportedModuleNode()
172+
.(DataFlow::SourceNode)
173+
.getAPropertyRead("createRequire")
174+
.getACall()
175+
)
167176
}
168177

169178
/**

0 commit comments

Comments
 (0)