Skip to content

Commit 79a9d7d

Browse files
committed
JS: removed execa parts from SystemCommandExecutors and moved it to Execa.qll
1 parent 0902ca0 commit 79a9d7d

File tree

2 files changed

+85
-13
lines changed

2 files changed

+85
-13
lines changed

javascript/ql/lib/semmle/javascript/frameworks/Execa.qll

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ module Execa {
5858
or
5959
this = API::moduleImport("execa").getMember("execaSync").getACall() and
6060
isSync = true
61+
or
62+
this = API::moduleImport("execa").getACall() and
63+
isSync = false
6164
}
6265
}
6366

@@ -208,4 +211,86 @@ module Execa {
208211
private predicate isExecaShellEnable(API::Node n) {
209212
n.getMember("shell").asSink().asExpr().(BooleanLiteral).getValue() = "true"
210213
}
214+
215+
/**
216+
* A call to `execa.node`
217+
*/
218+
class ExecaNodeCall extends SystemCommandExecution, API::CallNode {
219+
ExecaNodeCall() { this = API::moduleImport("execa").getMember("node").getACall() }
220+
221+
override DataFlow::Node getACommandArgument() { result = this.getArgument(0) }
222+
223+
override predicate isShellInterpreted(DataFlow::Node arg) { none() }
224+
225+
override DataFlow::Node getArgumentList() {
226+
result = this.getArgument(1) and
227+
not result.asExpr() instanceof ObjectExpr
228+
}
229+
230+
override predicate isSync() { none() }
231+
232+
override DataFlow::Node getOptionsArg() {
233+
result = this.getLastArgument() and
234+
result.asExpr() instanceof ObjectExpr
235+
}
236+
}
237+
238+
/**
239+
* A call to `execa.stdout`, `execa.stderr`, or `execa.sync`
240+
*/
241+
class ExecaStreamCall extends SystemCommandExecution, API::CallNode {
242+
string methodName;
243+
244+
ExecaStreamCall() {
245+
methodName in ["stdout", "stderr", "sync"] and
246+
this = API::moduleImport("execa").getMember(methodName).getACall()
247+
}
248+
249+
override DataFlow::Node getACommandArgument() { result = this.getArgument(0) }
250+
251+
override predicate isShellInterpreted(DataFlow::Node arg) {
252+
arg = this.getArgument(0) and
253+
isExecaShellEnable(this.getParameter([1, 2]))
254+
}
255+
256+
override DataFlow::Node getArgumentList() {
257+
result = this.getArgument(1) and
258+
not result.asExpr() instanceof ObjectExpr
259+
}
260+
261+
override predicate isSync() { methodName = "sync" }
262+
263+
override DataFlow::Node getOptionsArg() {
264+
result = this.getLastArgument() and
265+
result.asExpr() instanceof ObjectExpr
266+
}
267+
}
268+
269+
/**
270+
* A call to `execa.shell` or `execa.shellSync`
271+
*/
272+
class ExecaShellCall extends SystemCommandExecution, API::CallNode {
273+
boolean sync;
274+
275+
ExecaShellCall() {
276+
this = API::moduleImport("execa").getMember("shell").getACall() and
277+
sync = false
278+
or
279+
this = API::moduleImport("execa").getMember("shellSync").getACall() and
280+
sync = true
281+
}
282+
283+
override DataFlow::Node getACommandArgument() { result = this.getArgument(0) }
284+
285+
override predicate isShellInterpreted(DataFlow::Node arg) { arg = this.getACommandArgument() }
286+
287+
override DataFlow::Node getArgumentList() { none() }
288+
289+
override predicate isSync() { sync = true }
290+
291+
override DataFlow::Node getOptionsArg() {
292+
result = this.getArgument(1) and
293+
result.asExpr() instanceof ObjectExpr
294+
}
295+
}
211296
}

javascript/ql/lib/semmle/javascript/frameworks/SystemCommandExecutors.qll

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,6 @@ private predicate execApi(
1616
cmdArg = 0 and
1717
shell = false and
1818
optionsArg = -1
19-
or
20-
mod = "execa" and
21-
optionsArg = -1 and
22-
(
23-
shell = false and
24-
fn = ["node", "stdout", "stderr", "sync"]
25-
or
26-
shell = true and
27-
fn = ["command", "commandSync", "shell", "shellSync"]
28-
) and
29-
cmdArg = 0
3019
)
3120
}
3221

@@ -38,8 +27,6 @@ private predicate execApi(string mod, int cmdArg, int optionsArg, boolean shell)
3827
mod = "cross-spawn-async" and cmdArg = 0 and optionsArg = -1
3928
or
4029
mod = "exec-async" and cmdArg = 0 and optionsArg = -1
41-
or
42-
mod = "execa" and cmdArg = 0 and optionsArg = -1
4330
)
4431
or
4532
shell = true and

0 commit comments

Comments
 (0)