Skip to content

Commit 3899f2c

Browse files
committed
upgrade execa scripts
1 parent 261cabd commit 3899f2c

File tree

3 files changed

+213
-134
lines changed

3 files changed

+213
-134
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,22 @@ module Execa {
125125
class ExecaScript extends SystemCommandExecution, ExecaScriptCall {
126126
ExecaScript() { isSync = [false, true] }
127127

128-
override DataFlow::Node getACommandArgument() { result = this.getParameter(1).asSink() }
128+
override DataFlow::Node getACommandArgument() {
129+
result = this.getParameter(1).asSink() and
130+
not isTaggedTemplateFirstChildAnElement(this.getParameter(1).asSink().asExpr().getParent())
131+
}
129132

130133
override predicate isShellInterpreted(DataFlow::Node arg) {
131134
isExecaShellEnable(this.getParameter(0)) and
132135
arg = this.getAParameter().asSink()
133136
}
134137

135138
override DataFlow::Node getArgumentList() {
136-
result = this.getParameter(any(int i | i > 2)).asSink() and
137-
// here I should check if the first parameter of Template literal is the rightmost string of this Template literal then the arguments of this command execution will be the second and third and .. parameters
138-
not exists(string s | this.getACall().getArgument(0).mayHaveStringValue(s) | s.matches(""))
139+
result = this.getParameter(any(int i | i >= 1)).asSink() and
140+
isTaggedTemplateFirstChildAnElement(this.getParameter(1).asSink().asExpr().getParent())
139141
or
140-
result = this.getParameter(any(int i | i > 1)).asSink() and
141-
// here I should check if the first parameter of Template literal is a constant which is the command, then the arguments of this command execution will be the first, second and third and .. parameters
142-
not exists(string s | this.getACall().getArgument(0).mayHaveStringValue(s) | s.matches(""))
142+
result = this.getParameter(any(int i | i >= 2)).asSink() and
143+
not isTaggedTemplateFirstChildAnElement(this.getParameter(1).asSink().asExpr().getParent())
143144
}
144145

145146
override DataFlow::Node getOptionsArg() { result = this.getParameter(0).asSink() }
@@ -196,6 +197,11 @@ module Execa {
196197
}
197198
}
198199

200+
/** Gets a TemplateLiteral and check if first child is a template element */
201+
private predicate isTaggedTemplateFirstChildAnElement(TemplateLiteral templateLit) {
202+
exists(templateLit.getChildExpr(0).(TemplateElement))
203+
}
204+
199205
/**
200206
* Holds whether Execa has shell enabled options or not, get Parameter responsible for options
201207
*/

0 commit comments

Comments
 (0)