Skip to content

Commit 825fc22

Browse files
author
Max Schaefer
committed
JavaScript: Add two new command-injection tests.
1 parent 54c3574 commit 825fc22

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| query-tests/Security/CWE-078/exec-sh2.js:10 | expected an alert, but found none | BAD | ComandInjection |
2+
| query-tests/Security/CWE-078/exec-sh.js:15 | expected an alert, but found none | BAD | ComandInjection |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ options
9494
| child_process-test.js:56:5:56:59 | cp.spaw ... cmd])) | child_process-test.js:56:25:56:58 | ['/C', ... , cmd]) |
9595
| child_process-test.js:57:5:57:50 | cp.spaw ... t(cmd)) | child_process-test.js:57:25:57:49 | ['/C', ... at(cmd) |
9696
| child_process-test.js:67:3:67:21 | cp.spawn(cmd, args) | child_process-test.js:67:17:67:20 | args |
97+
| exec-sh2.js:10:12:10:57 | cp.spaw ... ptions) | exec-sh2.js:10:50:10:56 | options |
98+
| exec-sh.js:15:12:15:61 | cp.spaw ... ptions) | exec-sh.js:15:54:15:60 | options |
9799
| lib/lib.js:152:2:152:23 | cp.spaw ... gs, cb) | lib/lib.js:152:21:152:22 | cb |
98100
| lib/lib.js:159:2:159:23 | cp.spaw ... gs, cb) | lib/lib.js:159:21:159:22 | cb |
99101
| lib/lib.js:163:2:167:2 | cp.spaw ... t' }\\n\\t) | lib/lib.js:166:3:166:22 | { stdio: 'inherit' } |
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const cp = require('child_process'),
2+
http = require('http'),
3+
url = require('url');
4+
5+
function getShell() {
6+
if (process.platform === 'win32') {
7+
return { cmd: 'cmd', arg: '/C' }
8+
} else {
9+
return { cmd: 'sh', arg: '-c' }
10+
}
11+
}
12+
13+
function execSh(command, options) {
14+
var shell = getShell()
15+
return cp.spawn(shell.cmd, [shell.arg, command], options) // BAD
16+
}
17+
18+
http.createServer(function (req, res) {
19+
let cmd = url.parse(req.url, true).query.path;
20+
execSh(cmd);
21+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const cp = require('child_process'),
2+
http = require('http'),
3+
url = require('url');
4+
5+
function getShell() {
6+
return "sh";
7+
}
8+
9+
function execSh(command, options) {
10+
return cp.spawn(getShell(), ["-c", command], options) // BAD
11+
};
12+
13+
http.createServer(function (req, res) {
14+
let cmd = url.parse(req.url, true).query.path;
15+
execSh(cmd);
16+
});

0 commit comments

Comments
 (0)