Skip to content

Commit fd4e8f8

Browse files
authored
Merge pull request github#5526 from erik-krogh/quotedShell
Approved by esbena
2 parents 61880ba + 5e59f6d commit fd4e8f8

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ module ShellCommandInjectionFromEnvironment {
5555
class ShellCommandSink extends Sink, DataFlow::ValueNode {
5656
ShellCommandSink() { any(SystemCommandExecution sys).isShellInterpreted(this) }
5757
}
58+
59+
/**
60+
* A string-concatenation leaf that is surrounded by quotes, seen as a sanitizer for command-injection.
61+
*/
62+
class QuotingConcatSanitizer extends Sanitizer, StringOps::ConcatenationLeaf {
63+
QuotingConcatSanitizer() {
64+
this.getNextLeaf().getStringValue().regexpMatch("(\"|').*") and
65+
this.getPreviousLeaf().getStringValue().regexpMatch(".*(\"|')")
66+
}
67+
}
5868
}

javascript/ql/test/query-tests/Security/CWE-078/UselessUseOfCat.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ syncCommand
6363
| tst_shell-command-injection-from-environment.js:5:2:5:62 | cp.exec ... emp")]) |
6464
| tst_shell-command-injection-from-environment.js:6:2:6:54 | cp.exec ... temp")) |
6565
| tst_shell-command-injection-from-environment.js:9:2:9:58 | execa.s ... temp")) |
66+
| tst_shell-command-injection-from-environment.js:12:2:12:34 | execa.s ... + safe) |
6667
| uselesscat.js:16:1:16:29 | execSyn ... uinfo') |
6768
| uselesscat.js:18:1:18:26 | execSyn ... path}`) |
6869
| uselesscat.js:20:1:20:36 | execSyn ... wc -l') |

javascript/ql/test/query-tests/Security/CWE-078/tst_shell-command-injection-from-environment.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@ var cp = require('child_process'),
77

88
execa.shell('rm -rf ' + path.join(__dirname, "temp")); // NOT OK
99
execa.shellSync('rm -rf ' + path.join(__dirname, "temp")); // NOT OK
10+
11+
const safe = "\"" + path.join(__dirname, "temp") + "\"";
12+
execa.shellSync('rm -rf ' + safe); // OK
1013
});

0 commit comments

Comments
 (0)