Skip to content

Commit 0ee3f49

Browse files
committed
add test of webpack-dev-server and monorepo import
1 parent c860151 commit 0ee3f49

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ nodes
4848
| child_process-test.js:70:25:70:31 | req.url |
4949
| child_process-test.js:72:29:72:31 | cmd |
5050
| child_process-test.js:72:29:72:31 | cmd |
51+
| child_process-test.js:80:19:80:36 | req.query.fileName |
52+
| child_process-test.js:80:19:80:36 | req.query.fileName |
53+
| child_process-test.js:80:19:80:36 | req.query.fileName |
54+
| child_process-test.js:82:37:82:54 | req.query.fileName |
55+
| child_process-test.js:82:37:82:54 | req.query.fileName |
5156
| execSeries.js:3:20:3:22 | arr |
5257
| execSeries.js:6:14:6:16 | arr |
5358
| execSeries.js:6:14:6:21 | arr[i++] |
@@ -64,6 +69,10 @@ nodes
6469
| execSeries.js:18:34:18:40 | req.url |
6570
| execSeries.js:19:12:19:16 | [cmd] |
6671
| execSeries.js:19:13:19:15 | cmd |
72+
| lib/subLib/index.js:7:32:7:35 | name |
73+
| lib/subLib/index.js:8:10:8:25 | "rm -rf " + name |
74+
| lib/subLib/index.js:8:10:8:25 | "rm -rf " + name |
75+
| lib/subLib/index.js:8:22:8:25 | name |
6776
| other.js:5:9:5:49 | cmd |
6877
| other.js:5:15:5:38 | url.par ... , true) |
6978
| other.js:5:15:5:44 | url.par ... ).query |
@@ -152,6 +161,9 @@ edges
152161
| child_process-test.js:70:15:70:49 | url.par ... ry.path | child_process-test.js:70:9:70:49 | cmd |
153162
| child_process-test.js:70:25:70:31 | req.url | child_process-test.js:70:15:70:38 | url.par ... , true) |
154163
| child_process-test.js:70:25:70:31 | req.url | child_process-test.js:70:15:70:38 | url.par ... , true) |
164+
| child_process-test.js:80:19:80:36 | req.query.fileName | child_process-test.js:80:19:80:36 | req.query.fileName |
165+
| child_process-test.js:82:37:82:54 | req.query.fileName | lib/subLib/index.js:7:32:7:35 | name |
166+
| child_process-test.js:82:37:82:54 | req.query.fileName | lib/subLib/index.js:7:32:7:35 | name |
155167
| execSeries.js:3:20:3:22 | arr | execSeries.js:6:14:6:16 | arr |
156168
| execSeries.js:6:14:6:16 | arr | execSeries.js:6:14:6:21 | arr[i++] |
157169
| execSeries.js:6:14:6:21 | arr[i++] | execSeries.js:14:24:14:30 | command |
@@ -168,6 +180,9 @@ edges
168180
| execSeries.js:18:34:18:40 | req.url | execSeries.js:18:13:18:47 | require ... , true) |
169181
| execSeries.js:19:12:19:16 | [cmd] | execSeries.js:13:19:13:26 | commands |
170182
| execSeries.js:19:13:19:15 | cmd | execSeries.js:19:12:19:16 | [cmd] |
183+
| lib/subLib/index.js:7:32:7:35 | name | lib/subLib/index.js:8:22:8:25 | name |
184+
| lib/subLib/index.js:8:22:8:25 | name | lib/subLib/index.js:8:10:8:25 | "rm -rf " + name |
185+
| lib/subLib/index.js:8:22:8:25 | name | lib/subLib/index.js:8:10:8:25 | "rm -rf " + name |
171186
| other.js:5:9:5:49 | cmd | other.js:7:33:7:35 | cmd |
172187
| other.js:5:9:5:49 | cmd | other.js:7:33:7:35 | cmd |
173188
| other.js:5:9:5:49 | cmd | other.js:8:28:8:30 | cmd |
@@ -228,7 +243,9 @@ edges
228243
| child_process-test.js:59:5:59:39 | cp.exec ... , args) | child_process-test.js:6:25:6:31 | req.url | child_process-test.js:50:15:50:17 | cmd | This command depends on $@. | child_process-test.js:6:25:6:31 | req.url | a user-provided value |
229244
| child_process-test.js:64:3:64:21 | cp.spawn(cmd, args) | child_process-test.js:6:25:6:31 | req.url | child_process-test.js:43:15:43:17 | cmd | This command depends on $@. | child_process-test.js:6:25:6:31 | req.url | a user-provided value |
230245
| child_process-test.js:72:29:72:31 | cmd | child_process-test.js:70:25:70:31 | req.url | child_process-test.js:72:29:72:31 | cmd | This command depends on $@. | child_process-test.js:70:25:70:31 | req.url | a user-provided value |
246+
| child_process-test.js:80:19:80:36 | req.query.fileName | child_process-test.js:80:19:80:36 | req.query.fileName | child_process-test.js:80:19:80:36 | req.query.fileName | This command depends on $@. | child_process-test.js:80:19:80:36 | req.query.fileName | a user-provided value |
231247
| execSeries.js:14:41:14:47 | command | execSeries.js:18:34:18:40 | req.url | execSeries.js:14:41:14:47 | command | This command depends on $@. | execSeries.js:18:34:18:40 | req.url | a user-provided value |
248+
| lib/subLib/index.js:8:10:8:25 | "rm -rf " + name | child_process-test.js:82:37:82:54 | req.query.fileName | lib/subLib/index.js:8:10:8:25 | "rm -rf " + name | This command depends on $@. | child_process-test.js:82:37:82:54 | req.query.fileName | a user-provided value |
232249
| other.js:7:33:7:35 | cmd | other.js:5:25:5:31 | req.url | other.js:7:33:7:35 | cmd | This command depends on $@. | other.js:5:25:5:31 | req.url | a user-provided value |
233250
| other.js:8:28:8:30 | cmd | other.js:5:25:5:31 | req.url | other.js:8:28:8:30 | cmd | This command depends on $@. | other.js:5:25:5:31 | req.url | a user-provided value |
234251
| other.js:9:32:9:34 | cmd | other.js:5:25:5:31 | req.url | other.js:9:32:9:34 | cmd | This command depends on $@. | other.js:5:25:5:31 | req.url | a user-provided value |

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ http.createServer(function(req, res) {
7272
util.promisify(cp.exec)(cmd); // NOT OK
7373
});
7474

75+
76+
const webpackDevServer = require('webpack-dev-server');
77+
new webpackDevServer(compiler, {
78+
before: function (app) {
79+
app.use(function (req, res, next) {
80+
cp.exec(req.query.fileName); // NOT OK
81+
82+
require("my-sub-lib").foo(req.query.fileName); // calls lib/subLib/index.js#foo
83+
});
84+
}
85+
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ var cp = require("child_process")
22

33
module.exports = function (name) {
44
cp.exec("rm -rf " + name); // OK - this file belongs in a sub-"module", and is not the primary exported module.
5+
};
6+
7+
module.exports.foo = function (name) {
8+
cp.exec("rm -rf " + name); // NOT OK - this is being called explicitly from child_process-test.js
59
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "mySubLib",
2+
"name": "my-sub-lib",
33
"version": "0.0.7",
44
"main": "./index.js"
55
}

0 commit comments

Comments
 (0)