Skip to content

Commit a9527fd

Browse files
authored
Merge pull request github#5621 from erik-krogh/shellSink
Approved by esbena
2 parents 4cf0b8e + 365b4d7 commit a9527fd

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ module UnsafeShellCommandConstruction {
7070
exists(DataFlow::TypeBackTracker t2 |
7171
t2 = t.smallstep(result, isExecutedAsShellCommand(t2, sys))
7272
)
73+
or
74+
exists(DataFlow::TypeBackTracker t2, StringOps::ConcatenationRoot prev |
75+
t = t2.continue() and
76+
isExecutedAsShellCommand(t2, sys) = prev and
77+
result = prev.getALeaf()
78+
)
7379
}
7480

7581
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ nodes
242242
| lib/lib.js:478:27:478:32 | config |
243243
| lib/lib.js:478:27:478:46 | config.installedPath |
244244
| lib/lib.js:478:27:478:46 | config.installedPath |
245+
| lib/lib.js:482:40:482:43 | name |
246+
| lib/lib.js:482:40:482:43 | name |
247+
| lib/lib.js:483:30:483:33 | name |
248+
| lib/lib.js:483:30:483:33 | name |
245249
| lib/subLib/index.js:3:28:3:31 | name |
246250
| lib/subLib/index.js:3:28:3:31 | name |
247251
| lib/subLib/index.js:4:22:4:25 | name |
@@ -538,6 +542,10 @@ edges
538542
| lib/lib.js:477:33:477:38 | config | lib/lib.js:478:27:478:32 | config |
539543
| lib/lib.js:478:27:478:32 | config | lib/lib.js:478:27:478:46 | config.installedPath |
540544
| lib/lib.js:478:27:478:32 | config | lib/lib.js:478:27:478:46 | config.installedPath |
545+
| lib/lib.js:482:40:482:43 | name | lib/lib.js:483:30:483:33 | name |
546+
| lib/lib.js:482:40:482:43 | name | lib/lib.js:483:30:483:33 | name |
547+
| lib/lib.js:482:40:482:43 | name | lib/lib.js:483:30:483:33 | name |
548+
| lib/lib.js:482:40:482:43 | name | lib/lib.js:483:30:483:33 | name |
541549
| lib/subLib/index.js:3:28:3:31 | name | lib/subLib/index.js:4:22:4:25 | name |
542550
| lib/subLib/index.js:3:28:3:31 | name | lib/subLib/index.js:4:22:4:25 | name |
543551
| lib/subLib/index.js:3:28:3:31 | name | lib/subLib/index.js:4:22:4:25 | name |
@@ -615,5 +623,6 @@ edges
615623
| lib/lib.js:442:12:442:27 | "rm -rf " + name | lib/lib.js:441:39:441:42 | name | lib/lib.js:442:24:442:27 | name | $@ based on $@ is later used in $@. | lib/lib.js:442:12:442:27 | "rm -rf " + name | String concatenation | lib/lib.js:441:39:441:42 | name | library input | lib/lib.js:442:2:442:28 | asyncEx ... + name) | shell command |
616624
| lib/lib.js:447:13:447:28 | "rm -rf " + name | lib/lib.js:446:20:446:23 | name | lib/lib.js:447:25:447:28 | name | $@ based on $@ is later used in $@. | lib/lib.js:447:13:447:28 | "rm -rf " + name | String concatenation | lib/lib.js:446:20:446:23 | name | library input | lib/lib.js:447:3:447:29 | asyncEx ... + name) | shell command |
617625
| lib/lib.js:478:27:478:46 | config.installedPath | lib/lib.js:477:33:477:38 | config | lib/lib.js:478:27:478:46 | config.installedPath | $@ based on $@ is later used in $@. | lib/lib.js:478:27:478:46 | config.installedPath | Path concatenation | lib/lib.js:477:33:477:38 | config | library input | lib/lib.js:479:12:479:20 | exec(cmd) | shell command |
626+
| lib/lib.js:483:13:483:33 | ' my na ... + name | lib/lib.js:482:40:482:43 | name | lib/lib.js:483:30:483:33 | name | $@ based on $@ is later used in $@. | lib/lib.js:483:13:483:33 | ' my na ... + name | String concatenation | lib/lib.js:482:40:482:43 | name | library input | lib/lib.js:485:2:485:20 | cp.exec(cmd + args) | shell command |
618627
| lib/subLib/index.js:4:10:4:25 | "rm -rf " + name | lib/subLib/index.js:3:28:3:31 | name | lib/subLib/index.js:4:22:4:25 | name | $@ based on $@ is later used in $@. | lib/subLib/index.js:4:10:4:25 | "rm -rf " + name | String concatenation | lib/subLib/index.js:3:28:3:31 | name | library input | lib/subLib/index.js:4:2:4:26 | cp.exec ... + name) | shell command |
619628
| lib/subLib/index.js:8:10:8:25 | "rm -rf " + name | lib/subLib/index.js:7:32:7:35 | name | lib/subLib/index.js:8:22:8:25 | name | $@ based on $@ is later used in $@. | lib/subLib/index.js:8:10:8:25 | "rm -rf " + name | String concatenation | lib/subLib/index.js:7:32:7:35 | name | library input | lib/subLib/index.js:8:2:8:26 | cp.exec ... + name) | shell command |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,10 @@ const exec = promisify(require('child_process').exec);
477477
module.exports = function check(config) {
478478
const cmd = path.join(config.installedPath, 'myBinary -v'); // NOT OK
479479
return exec(cmd);
480+
}
481+
482+
module.exports.splitConcat = function (name) {
483+
let args = ' my name is ' + name; // NOT OK
484+
let cmd = 'echo';
485+
cp.exec(cmd + args);
480486
}

0 commit comments

Comments
 (0)