Skip to content

Commit 320879b

Browse files
committed
recognize colon in command-prefixes
1 parent 68f421f commit 320879b

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module UnsafeShellCommandConstruction {
8585
this = root.getALeaf() and
8686
root = isExecutedAsShellCommand(DataFlow::TypeBackTracker::end(), sys) and
8787
exists(string prev | prev = this.getPreviousLeaf().getStringValue() |
88-
prev.regexpMatch(".* ('|\")?[0-9a-zA-Z/]*")
88+
prev.regexpMatch(".* ('|\")?[0-9a-zA-Z/:]*")
8989
)
9090
}
9191

@@ -132,7 +132,7 @@ module UnsafeShellCommandConstruction {
132132
this = call.getFormatArgument(_) and
133133
call = isExecutedAsShellCommand(DataFlow::TypeBackTracker::end(), sys) and
134134
exists(string formatString | call.getFormatString().mayHaveStringValue(formatString) |
135-
formatString.regexpMatch(".* ('|\")?[0-9a-zA-Z/]*%.*")
135+
formatString.regexpMatch(".* ('|\")?[0-9a-zA-Z/:]*%.*")
136136
)
137137
}
138138

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ nodes
176176
| lib/lib.js:315:22:315:25 | name |
177177
| lib/lib.js:320:23:320:26 | name |
178178
| lib/lib.js:320:23:320:26 | name |
179+
| lib/lib.js:324:40:324:42 | arg |
180+
| lib/lib.js:324:40:324:42 | arg |
181+
| lib/lib.js:325:49:325:51 | arg |
182+
| lib/lib.js:325:49:325:51 | arg |
179183
edges
180184
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
181185
| lib/lib2.js:3:28:3:31 | name | lib/lib2.js:4:22:4:25 | name |
@@ -388,6 +392,10 @@ edges
388392
| lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name |
389393
| lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name |
390394
| lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name |
395+
| lib/lib.js:324:40:324:42 | arg | lib/lib.js:325:49:325:51 | arg |
396+
| lib/lib.js:324:40:324:42 | arg | lib/lib.js:325:49:325:51 | arg |
397+
| lib/lib.js:324:40:324:42 | arg | lib/lib.js:325:49:325:51 | arg |
398+
| lib/lib.js:324:40:324:42 | arg | lib/lib.js:325:49:325:51 | arg |
391399
#select
392400
| 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 |
393401
| 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 |
@@ -441,3 +449,4 @@ edges
441449
| lib/lib.js:308:11:308:26 | "rm -rf " + name | lib/lib.js:307:39:307:42 | name | lib/lib.js:308:23:308:26 | name | $@ based on library input is later used in $@. | lib/lib.js:308:11:308:26 | "rm -rf " + name | String concatenation | lib/lib.js:308:3:308:27 | cp.exec ... + name) | shell command |
442450
| lib/lib.js:315:10:315:25 | "rm -rf " + name | lib/lib.js:314:40:314:43 | name | lib/lib.js:315:22:315:25 | name | $@ based on library input is later used in $@. | lib/lib.js:315:10:315:25 | "rm -rf " + name | String concatenation | lib/lib.js:315:2:315:26 | cp.exec ... + name) | shell command |
443451
| lib/lib.js:320:11:320:26 | "rm -rf " + name | lib/lib.js:314:40:314:43 | name | lib/lib.js:320:23:320:26 | name | $@ based on library input is later used in $@. | lib/lib.js:320:11:320:26 | "rm -rf " + name | String concatenation | lib/lib.js:320:3:320:27 | cp.exec ... + name) | shell command |
452+
| lib/lib.js:325:12:325:51 | "MyWind ... " + arg | lib/lib.js:324:40:324:42 | arg | lib/lib.js:325:49:325:51 | arg | $@ based on library input is later used in $@. | lib/lib.js:325:12:325:51 | "MyWind ... " + arg | String concatenation | lib/lib.js:326:2:326:13 | cp.exec(cmd) | 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
@@ -319,4 +319,9 @@ module.exports.typeofcheck = function (name) {
319319
} else {
320320
cp.exec("rm -rf " + name); // NOT OK
321321
}
322+
}
323+
324+
module.exports.typeofcheck = function (arg) {
325+
var cmd = "MyWindowCommand | findstr /i /c:" + arg; // NOT OK
326+
cp.exec(cmd);
322327
}

0 commit comments

Comments
 (0)