Skip to content

Commit 3647b9c

Browse files
authored
Merge pull request github#13196 from erik-krogh/indirectCommand
JS: require arguments to be shell interpreted to be flagged by indirect-command-injection
2 parents 05c30e8 + 239234c commit 3647b9c

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,10 @@ private class ExecActionsCall extends SystemCommandExecution, DataFlow::CallNode
7878

7979
override DataFlow::Node getOptionsArg() { result = this.getArgument(2) }
8080

81+
override predicate isShellInterpreted(DataFlow::Node arg) {
82+
arg = this.getACommandArgument() and
83+
not this.getArgumentList().getALocalSource() instanceof DataFlow::ArrayCreationNode
84+
}
85+
8186
override predicate isSync() { none() }
8287
}

javascript/ql/lib/semmle/javascript/security/dataflow/IndirectCommandInjectionCustomizations.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,13 @@ module IndirectCommandInjection {
199199
}
200200

201201
/**
202-
* A command argument to a function that initiates an operating system command.
202+
* A command argument to a function that initiates an operating system command as a shell invocation.
203203
*/
204204
private class SystemCommandExecutionSink extends Sink, DataFlow::ValueNode {
205-
SystemCommandExecutionSink() { this = any(SystemCommandExecution sys).getACommandArgument() }
205+
SystemCommandExecutionSink() {
206+
exists(SystemCommandExecution sys |
207+
sys.isShellInterpreted(this) and this = sys.getACommandArgument()
208+
)
209+
}
206210
}
207211
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `js/indirect-command-line-injection` query no longer flags command arguments that cannot be interpreted as a shell string.

javascript/ql/test/query-tests/Security/CWE-078/IndirectCommandInjection/command-line-parameter-command-injection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,6 @@ cp.exec("cmd.sh " + require("optimist").argv.foo); // NOT OK
144144

145145
cp.exec("cmd.sh " + program.opts().pizzaType); // NOT OK
146146
cp.exec("cmd.sh " + program.pizzaType); // NOT OK
147+
148+
cp.execFile(program.opts().pizzaType, ["foo", "bar"]); // OK
147149
});

0 commit comments

Comments
 (0)