Skip to content

Commit 28ad667

Browse files
committed
add model for async-execute
1 parent 1d9f8c2 commit 28ad667

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

javascript/ql/src/semmle/javascript/frameworks/SystemCommandExecutors.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ private predicate execApi(string mod, int cmdArg, int optionsArg, boolean shell)
4343
)
4444
or
4545
shell = true and
46-
mod = "exec" and
47-
optionsArg = -2 and
48-
cmdArg = 0
46+
(
47+
mod = "exec" and
48+
optionsArg = -2 and
49+
cmdArg = 0
50+
or
51+
mod = "async-execute" and
52+
optionsArg = 1 and
53+
cmdArg = 0
54+
)
4955
}
5056

5157
private class SystemCommandExecutors extends SystemCommandExecution, DataFlow::InvokeNode {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ nodes
205205
| lib/lib.js:405:39:405:42 | name |
206206
| lib/lib.js:406:22:406:25 | name |
207207
| lib/lib.js:406:22:406:25 | name |
208+
| lib/lib.js:413:39:413:42 | name |
209+
| lib/lib.js:413:39:413:42 | name |
210+
| lib/lib.js:414:24:414:27 | name |
211+
| lib/lib.js:414:24:414:27 | name |
208212
edges
209213
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
210214
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
@@ -444,6 +448,10 @@ edges
444448
| lib/lib.js:405:39:405:42 | name | lib/lib.js:406:22:406:25 | name |
445449
| lib/lib.js:405:39:405:42 | name | lib/lib.js:406:22:406:25 | name |
446450
| lib/lib.js:405:39:405:42 | name | lib/lib.js:406:22:406:25 | name |
451+
| lib/lib.js:413:39:413:42 | name | lib/lib.js:414:24:414:27 | name |
452+
| lib/lib.js:413:39:413:42 | name | lib/lib.js:414:24:414:27 | name |
453+
| lib/lib.js:413:39:413:42 | name | lib/lib.js:414:24:414:27 | name |
454+
| lib/lib.js:413:39:413:42 | name | lib/lib.js:414:24:414:27 | name |
447455
#select
448456
| lib/lib2.js:4:10:4:25 | "rm -rf " + name | lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name | $@ based on library input is later used in $@. | lib/lib2.js:4:10:4:25 | "rm -rf " + name | String concatenation | lib/lib2.js:4:2:4:26 | cp.exec ... + name) | shell command |
449457
| lib/lib2.js:8:10:8:25 | "rm -rf " + name | lib/lib2.js:7:32:7:35 | name | lib/lib2.js:8:22:8:25 | name | $@ based on library input is later used in $@. | lib/lib2.js:8:10:8:25 | "rm -rf " + name | String concatenation | lib/lib2.js:8:2:8:26 | cp.exec ... + name) | shell command |
@@ -502,3 +510,4 @@ edges
502510
| lib/lib.js:351:10:351:27 | "rm -rf " + unsafe | lib/lib.js:349:29:349:34 | unsafe | lib/lib.js:351:22:351:27 | unsafe | $@ based on library input is later used in $@. | lib/lib.js:351:10:351:27 | "rm -rf " + unsafe | String concatenation | lib/lib.js:351:2:351:28 | cp.exec ... unsafe) | shell command |
503511
| lib/lib.js:366:17:366:56 | "learn ... + model | lib/lib.js:360:20:360:23 | opts | lib/lib.js:366:28:366:42 | this.learn_args | $@ based on library input is later used in $@. | lib/lib.js:366:17:366:56 | "learn ... + model | String concatenation | lib/lib.js:367:3:367:18 | cp.exec(command) | shell command |
504512
| lib/lib.js:406:10:406:25 | "rm -rf " + name | lib/lib.js:405:39:405:42 | name | lib/lib.js:406:22:406:25 | name | $@ based on library input is later used in $@. | lib/lib.js:406:10:406:25 | "rm -rf " + name | String concatenation | lib/lib.js:406:2:406:26 | cp.exec ... + name) | shell command |
513+
| lib/lib.js:414:12:414:27 | "rm -rf " + name | lib/lib.js:413:39:413:42 | name | lib/lib.js:414:24:414:27 | name | $@ based on library input is later used in $@. | lib/lib.js:414:12:414:27 | "rm -rf " + name | String concatenation | lib/lib.js:414:2:414:28 | asyncEx ... + name) | shell command |

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
@@ -408,3 +408,8 @@ module.exports.sanitizer3 = function (name) {
408408
var sanitized = yetAnohterSanitizer(name);
409409
cp.exec("rm -rf " + sanitized); // OK
410410
}
411+
412+
var asyncExec = require("async-execute");
413+
module.exports.asyncStuff = function (name) {
414+
asyncExec("rm -rf " + name); // NOT OK
415+
}

0 commit comments

Comments
 (0)