Skip to content

Commit 63f087a

Browse files
authored
Merge pull request github#5653 from erik-krogh/givenCommand
Approved by asgerf
2 parents 364d489 + 17c4bbb commit 63f087a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeShellCommandConstructionCustomizations.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ module UnsafeShellCommandConstruction {
5353
class ExternalInputSource extends Source, DataFlow::ParameterNode {
5454
ExternalInputSource() {
5555
this = Exports::getALibraryInputParameter() and
56-
not this.getName() = ["cmd", "command"] // looks to be on purpose.
56+
not (
57+
// looks to be on purpose.
58+
this.getName() = ["cmd", "command"]
59+
or
60+
this.getName().regexpMatch(".*(Cmd|Command)$") // ends with "Cmd" or "Command"
61+
)
5762
}
5863
}
5964

javascript/ql/test/query-tests/Security/CWE-078/lib/lib.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,4 +483,9 @@ module.exports.splitConcat = function (name) {
483483
let args = ' my name is ' + name; // NOT OK
484484
let cmd = 'echo';
485485
cp.exec(cmd + args);
486+
}
487+
488+
module.exports.myCommand = function (myCommand) {
489+
let cmd = `cd ${cwd} ; ${myCommand}`; // OK - the parameter name suggests that it is purposely a shell command.
490+
cp.exec(cmd);
486491
}

0 commit comments

Comments
 (0)