Skip to content

Commit 16c33b5

Browse files
author
Max Schaefer
committed
JavaScript: Recognise references to the process global.
1 parent 58285c0 commit 16c33b5

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,23 @@ import semmle.javascript.security.SensitiveActions
88

99
module NodeJSLib {
1010
/**
11-
* Gets a reference to the 'process' object.
11+
* An access to the global `process` variable in a Node.js module, interpreted as
12+
* an import of the `process` module.
1213
*/
13-
DataFlow::SourceNode process() {
14-
result = DataFlow::globalVarRef("process") or
15-
result = DataFlow::moduleImport("process")
14+
private class ImplicitProcessImport extends DataFlow::ModuleImportNode::Range {
15+
ImplicitProcessImport() {
16+
this = DataFlow::globalVarRef("process") and
17+
getTopLevel() instanceof NodeModule
18+
}
19+
20+
override string getPath() { result = "process" }
1621
}
1722

1823
/**
19-
* Gets a reference to a member of the 'process' object.
24+
* Gets a reference to the 'process' object.
2025
*/
21-
private DataFlow::SourceNode processMember(string member) {
22-
result = process().getAPropertyRead(member) or
23-
result = DataFlow::moduleMember("process", member)
26+
DataFlow::SourceNode process() {
27+
result = DataFlow::moduleImport("process")
2428
}
2529

2630
/**
@@ -363,7 +367,7 @@ module NodeJSLib {
363367
ProcessTermination() {
364368
this = DataFlow::moduleImport("exit").getAnInvocation()
365369
or
366-
this = processMember("exit").getACall()
370+
this = DataFlow::moduleMember("process", "exit").getACall()
367371
}
368372
}
369373

0 commit comments

Comments
 (0)