Skip to content

Commit 3293a55

Browse files
committed
require arguments to be shell interpreted to be flagged by indirect-command-injection
1 parent b46983a commit 3293a55

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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
}

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)