Merge pull request #13196 from erik-krogh/indirectCommand

JS: require arguments to be shell interpreted to be flagged by indirect-command-injection
This commit is contained in:
Erik Krogh Kristensen
2023-05-22 11:53:57 +02:00
committed by GitHub
4 changed files with 17 additions and 2 deletions

View File

@@ -78,5 +78,10 @@ private class ExecActionsCall extends SystemCommandExecution, DataFlow::CallNode
override DataFlow::Node getOptionsArg() { result = this.getArgument(2) }
override predicate isShellInterpreted(DataFlow::Node arg) {
arg = this.getACommandArgument() and
not this.getArgumentList().getALocalSource() instanceof DataFlow::ArrayCreationNode
}
override predicate isSync() { none() }
}

View File

@@ -199,9 +199,13 @@ module IndirectCommandInjection {
}
/**
* A command argument to a function that initiates an operating system command.
* A command argument to a function that initiates an operating system command as a shell invocation.
*/
private class SystemCommandExecutionSink extends Sink, DataFlow::ValueNode {
SystemCommandExecutionSink() { this = any(SystemCommandExecution sys).getACommandArgument() }
SystemCommandExecutionSink() {
exists(SystemCommandExecution sys |
sys.isShellInterpreted(this) and this = sys.getACommandArgument()
)
}
}
}

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The `js/indirect-command-line-injection` query no longer flags command arguments that cannot be interpreted as a shell string.

View File

@@ -144,4 +144,6 @@ cp.exec("cmd.sh " + require("optimist").argv.foo); // NOT OK
cp.exec("cmd.sh " + program.opts().pizzaType); // NOT OK
cp.exec("cmd.sh " + program.pizzaType); // NOT OK
cp.execFile(program.opts().pizzaType, ["foo", "bar"]); // OK
});