Skip to content

Commit 8ccc384

Browse files
authored
Merge pull request #11858 from erik-krogh/moreSpawn
JS: track shell:true more in js/shell-command-constructed-from-input
2 parents 59a8b21 + 71af8ab commit 8ccc384

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ module UnsafeShellCommandConstruction {
166166
.asExpr()
167167
.(BooleanLiteral)
168168
.getValue() = "true"
169+
or
170+
exists(API::Node node |
171+
node.asSink() = sys.getOptionsArg() and
172+
node.getMember("shell").asSink().mayHaveBooleanValue(true)
173+
)
169174
}
170175

171176
/**

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ nodes
282282
| lib/lib.js:543:23:543:26 | name |
283283
| lib/lib.js:545:23:545:26 | name |
284284
| lib/lib.js:545:23:545:26 | name |
285+
| lib/lib.js:550:39:550:42 | name |
286+
| lib/lib.js:550:39:550:42 | name |
287+
| lib/lib.js:551:33:551:36 | args |
288+
| lib/lib.js:552:23:552:26 | args |
289+
| lib/lib.js:552:23:552:26 | args |
290+
| lib/lib.js:555:25:555:37 | ["-rf", name] |
291+
| lib/lib.js:555:33:555:36 | name |
292+
| lib/lib.js:555:33:555:36 | name |
285293
| lib/subLib2/compiled-file.ts:3:26:3:29 | name |
286294
| lib/subLib2/compiled-file.ts:3:26:3:29 | name |
287295
| lib/subLib2/compiled-file.ts:4:25:4:28 | name |
@@ -659,6 +667,14 @@ edges
659667
| lib/lib.js:509:39:509:42 | name | lib/lib.js:545:23:545:26 | name |
660668
| lib/lib.js:509:39:509:42 | name | lib/lib.js:545:23:545:26 | name |
661669
| lib/lib.js:509:39:509:42 | name | lib/lib.js:545:23:545:26 | name |
670+
| lib/lib.js:550:39:550:42 | name | lib/lib.js:555:33:555:36 | name |
671+
| lib/lib.js:550:39:550:42 | name | lib/lib.js:555:33:555:36 | name |
672+
| lib/lib.js:550:39:550:42 | name | lib/lib.js:555:33:555:36 | name |
673+
| lib/lib.js:550:39:550:42 | name | lib/lib.js:555:33:555:36 | name |
674+
| lib/lib.js:551:33:551:36 | args | lib/lib.js:552:23:552:26 | args |
675+
| lib/lib.js:551:33:551:36 | args | lib/lib.js:552:23:552:26 | args |
676+
| lib/lib.js:555:25:555:37 | ["-rf", name] | lib/lib.js:551:33:551:36 | args |
677+
| lib/lib.js:555:33:555:36 | name | lib/lib.js:555:25:555:37 | ["-rf", name] |
662678
| lib/subLib2/compiled-file.ts:3:26:3:29 | name | lib/subLib2/compiled-file.ts:4:25:4:28 | name |
663679
| lib/subLib2/compiled-file.ts:3:26:3:29 | name | lib/subLib2/compiled-file.ts:4:25:4:28 | name |
664680
| lib/subLib2/compiled-file.ts:3:26:3:29 | name | lib/subLib2/compiled-file.ts:4:25:4:28 | name |
@@ -775,6 +791,8 @@ edges
775791
| lib/lib.js:537:11:537:26 | "rm -rf " + name | lib/lib.js:509:39:509:42 | name | lib/lib.js:537:23:537:26 | name | This string concatenation which depends on $@ is later used in a $@. | lib/lib.js:509:39:509:42 | name | library input | lib/lib.js:537:3:537:27 | cp.exec ... + name) | shell command |
776792
| lib/lib.js:543:11:543:26 | "rm -rf " + name | lib/lib.js:509:39:509:42 | name | lib/lib.js:543:23:543:26 | name | This string concatenation which depends on $@ is later used in a $@. | lib/lib.js:509:39:509:42 | name | library input | lib/lib.js:543:3:543:27 | cp.exec ... + name) | shell command |
777793
| lib/lib.js:545:11:545:26 | "rm -rf " + name | lib/lib.js:509:39:509:42 | name | lib/lib.js:545:23:545:26 | name | This string concatenation which depends on $@ is later used in a $@. | lib/lib.js:509:39:509:42 | name | library input | lib/lib.js:545:3:545:27 | cp.exec ... + name) | shell command |
794+
| lib/lib.js:552:23:552:26 | args | lib/lib.js:550:39:550:42 | name | lib/lib.js:552:23:552:26 | args | This shell argument which depends on $@ is later used in a $@. | lib/lib.js:550:39:550:42 | name | library input | lib/lib.js:552:9:552:38 | cp.spaw ... wnOpts) | shell command |
795+
| lib/lib.js:555:33:555:36 | name | lib/lib.js:550:39:550:42 | name | lib/lib.js:555:33:555:36 | name | This shell argument which depends on $@ is later used in a $@. | lib/lib.js:550:39:550:42 | name | library input | lib/lib.js:552:9:552:38 | cp.spaw ... wnOpts) | shell command |
778796
| lib/subLib2/compiled-file.ts:4:13:4:28 | "rm -rf " + name | lib/subLib2/compiled-file.ts:3:26:3:29 | name | lib/subLib2/compiled-file.ts:4:25:4:28 | name | This string concatenation which depends on $@ is later used in a $@. | lib/subLib2/compiled-file.ts:3:26:3:29 | name | library input | lib/subLib2/compiled-file.ts:4:5:4:29 | cp.exec ... + name) | shell command |
779797
| lib/subLib2/special-file.js:4:10:4:25 | "rm -rf " + name | lib/subLib2/special-file.js:3:28:3:31 | name | lib/subLib2/special-file.js:4:22:4:25 | name | This string concatenation which depends on $@ is later used in a $@. | lib/subLib2/special-file.js:3:28:3:31 | name | library input | lib/subLib2/special-file.js:4:2:4:26 | cp.exec ... + name) | shell command |
780798
| lib/subLib3/my-file.ts:4:10:4:25 | "rm -rf " + name | lib/subLib3/my-file.ts:3:28:3:31 | name | lib/subLib3/my-file.ts:4:22:4:25 | name | This string concatenation which depends on $@ is later used in a $@. | lib/subLib3/my-file.ts:3:28:3:31 | name | library input | lib/subLib3/my-file.ts:4:2:4:26 | cp.exec ... + name) | shell command |

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,3 +545,12 @@ module.exports.sanitizer4 = function (name) {
545545
cp.exec("rm -rf " + name); // NOT OK
546546
}
547547
}
548+
549+
550+
module.exports.shellThing = function (name) {
551+
function indirectShell(cmd, args, spawnOpts) {
552+
cp.spawn(cmd, args, spawnOpts); // NOT OK
553+
}
554+
555+
indirectShell("rm", ["-rf", name], {shell: true});
556+
}

0 commit comments

Comments
 (0)