@contrast/assess 1.30.0 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/crypto-analysis/install/crypto.test.js +146 -0
- package/lib/crypto-analysis/install/math.test.js +65 -0
- package/lib/dataflow/index.test.js +36 -0
- package/lib/dataflow/propagation/index.test.js +103 -0
- package/lib/dataflow/propagation/install/JSON/index.test.js +50 -0
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +232 -0
- package/lib/dataflow/propagation/install/JSON/parse.test.js +968 -0
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +265 -0
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +106 -0
- package/lib/dataflow/propagation/install/buffer.test.js +109 -0
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +94 -0
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +49 -0
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +50 -0
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +148 -0
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +145 -0
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +78 -0
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +69 -0
- package/lib/dataflow/propagation/install/ejs/template.test.js +62 -0
- package/lib/dataflow/propagation/install/encode-uri.test.js +83 -0
- package/lib/dataflow/propagation/install/escape-html.test.js +71 -0
- package/lib/dataflow/propagation/install/escape.test.js +73 -0
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +71 -0
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +58 -0
- package/lib/dataflow/propagation/install/joi/any.test.js +270 -0
- package/lib/dataflow/propagation/install/joi/array.test.js +912 -0
- package/lib/dataflow/propagation/install/joi/boolean.test.js +103 -0
- package/lib/dataflow/propagation/install/joi/expression.test.js +76 -0
- package/lib/dataflow/propagation/install/joi/index.test.js +39 -0
- package/lib/dataflow/propagation/install/joi/number.test.js +103 -0
- package/lib/dataflow/propagation/install/joi/object.test.js +119 -0
- package/lib/dataflow/propagation/install/joi/ref.test.js +607 -0
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +513 -0
- package/lib/dataflow/propagation/install/mongoose/index.test.js +42 -0
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +348 -0
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +512 -0
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +160 -0
- package/lib/dataflow/propagation/install/mustache-escape.test.js +62 -0
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +74 -0
- package/lib/dataflow/propagation/install/parse-int.test.js +48 -0
- package/lib/dataflow/propagation/install/path/basename.test.js +143 -0
- package/lib/dataflow/propagation/install/path/dirname.test.js +167 -0
- package/lib/dataflow/propagation/install/path/extname.test.js +141 -0
- package/lib/dataflow/propagation/install/path/format.test.js +250 -0
- package/lib/dataflow/propagation/install/path/index.test.js +45 -0
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +485 -0
- package/lib/dataflow/propagation/install/path/normalize.test.js +176 -0
- package/lib/dataflow/propagation/install/path/parse.test.js +238 -0
- package/lib/dataflow/propagation/install/path/relative.test.js +239 -0
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +158 -0
- package/lib/dataflow/propagation/install/pug/index.test.js +55 -0
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +69 -0
- package/lib/dataflow/propagation/install/querystring/escape.test.js +63 -0
- package/lib/dataflow/propagation/install/querystring/index.test.js +40 -0
- package/lib/dataflow/propagation/install/querystring/parse.test.js +272 -0
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +301 -0
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +281 -0
- package/lib/dataflow/propagation/install/send.test.js +63 -0
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +73 -0
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +130 -0
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +100 -0
- package/lib/dataflow/propagation/install/string/concat.test.js +132 -0
- package/lib/dataflow/propagation/install/string/format-methods.test.js +61 -0
- package/lib/dataflow/propagation/install/string/html-methods.test.js +164 -0
- package/lib/dataflow/propagation/install/string/index.test.js +103 -0
- package/lib/dataflow/propagation/install/string/match-all.test.js +399 -0
- package/lib/dataflow/propagation/install/string/match.test.js +361 -0
- package/lib/dataflow/propagation/install/string/replace.test.js +588 -0
- package/lib/dataflow/propagation/install/string/slice.test.js +265 -0
- package/lib/dataflow/propagation/install/string/split.test.js +500 -0
- package/lib/dataflow/propagation/install/string/substring.test.js +238 -0
- package/lib/dataflow/propagation/install/string/trim.test.js +122 -0
- package/lib/dataflow/propagation/install/unescape.test.js +78 -0
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +63 -0
- package/lib/dataflow/propagation/install/url/parse.test.js +391 -0
- package/lib/dataflow/propagation/install/url/searchParams.test.js +538 -0
- package/lib/dataflow/propagation/install/url/url.test.js +466 -0
- package/lib/dataflow/propagation/install/util-format.test.js +336 -0
- package/lib/dataflow/propagation/install/validator/hooks.test.js +211 -0
- package/lib/dataflow/sinks/index.test.js +78 -0
- package/lib/dataflow/sinks/install/child-process.test.js +338 -0
- package/lib/dataflow/sinks/install/eval.test.js +95 -0
- package/lib/dataflow/sinks/install/express/index.test.js +33 -0
- package/lib/dataflow/sinks/install/express/reflected-xss.js +55 -57
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +109 -0
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +144 -0
- package/lib/dataflow/sinks/install/fastify/index.test.js +32 -0
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +130 -0
- package/lib/dataflow/sinks/install/fs.test.js +138 -0
- package/lib/dataflow/sinks/install/function.test.js +103 -0
- package/lib/dataflow/sinks/install/hapi/index.test.js +32 -0
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +130 -0
- package/lib/dataflow/sinks/install/http/index.test.js +33 -0
- package/lib/dataflow/sinks/install/http/request.test.js +184 -0
- package/lib/dataflow/sinks/install/http/server-response.test.js +162 -0
- package/lib/dataflow/sinks/install/koa/index.test.js +32 -0
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +200 -0
- package/lib/dataflow/sinks/install/libxmljs.test.js +158 -0
- package/lib/dataflow/sinks/install/marsdb.test.js +166 -0
- package/lib/dataflow/sinks/install/mongodb.test.js +621 -0
- package/lib/dataflow/sinks/install/mssql.test.js +136 -0
- package/lib/dataflow/sinks/install/mysql.test.js +233 -0
- package/lib/dataflow/sinks/install/node-serialize.test.js +85 -0
- package/lib/dataflow/sinks/install/postgres.test.js +158 -0
- package/lib/dataflow/sinks/install/restify.test.js +142 -0
- package/lib/dataflow/sinks/install/sequelize.test.js +100 -0
- package/lib/dataflow/sinks/install/sqlite3.test.js +118 -0
- package/lib/dataflow/sinks/install/vm.test.js +326 -0
- package/lib/dataflow/sources/handler.test.js +463 -0
- package/lib/dataflow/sources/index.test.js +58 -0
- package/lib/dataflow/sources/install/body-parser1.test.js +248 -0
- package/lib/dataflow/sources/install/busboy.test.js +152 -0
- package/lib/dataflow/sources/install/cookie-parser1.test.js +143 -0
- package/lib/dataflow/sources/install/express/params.test.js +105 -0
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +65 -0
- package/lib/dataflow/sources/install/fastify/fastify.js +1 -1
- package/lib/dataflow/sources/install/fastify/fastify.test.js +210 -0
- package/lib/dataflow/sources/install/fastify/index.test.js +33 -0
- package/lib/dataflow/sources/install/formidable1.test.js +119 -0
- package/lib/dataflow/sources/install/hapi/hapi.test.js +172 -0
- package/lib/dataflow/sources/install/hapi/index.test.js +33 -0
- package/lib/dataflow/sources/install/http.test.js +155 -0
- package/lib/dataflow/sources/install/koa/index.test.js +40 -0
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +161 -0
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +197 -0
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +146 -0
- package/lib/dataflow/sources/install/koa/koa2.test.js +145 -0
- package/lib/dataflow/sources/install/multer1.test.js +145 -0
- package/lib/dataflow/sources/install/qs6.test.js +131 -0
- package/lib/dataflow/sources/install/querystring.test.js +82 -0
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +88 -0
- package/lib/dataflow/sources/install/restify/index.test.js +38 -0
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +144 -0
- package/lib/dataflow/sources/install/restify/router.test.js +83 -0
- package/lib/dataflow/tag-utils-complete.test.js +27 -0
- package/lib/dataflow/tag-utils.test.js +192 -0
- package/lib/dataflow/tracker.test.js +216 -0
- package/lib/dataflow/utils/is-safe-content-type.test.js +16 -0
- package/lib/dataflow/utils/is-vulnerable.test.js +115 -0
- package/lib/event-factory.test.js +321 -0
- package/lib/get-policy.test.js +194 -0
- package/lib/get-source-context.test.js +108 -0
- package/lib/index.test.js +41 -0
- package/lib/make-source-context.test.js +50 -0
- package/lib/response-scanning/handlers/index.test.js +425 -0
- package/lib/response-scanning/handlers/utils.test.js +391 -0
- package/lib/response-scanning/index.test.js +41 -0
- package/lib/response-scanning/install/http.test.js +175 -0
- package/lib/rule-scopes.test.js +27 -0
- package/lib/session-configuration/handlers.test.js +84 -0
- package/lib/session-configuration/index.test.js +36 -0
- package/lib/session-configuration/install/express-session.test.js +220 -0
- package/lib/session-configuration/install/fastify-cookie.test.js +65 -0
- package/lib/session-configuration/install/hapi.test.js +269 -0
- package/lib/session-configuration/install/koa.js +50 -44
- package/lib/session-configuration/install/koa.test.js +92 -0
- package/package.json +2 -2
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
DataflowTag: { UNTRUSTED }
|
|
5
|
+
} = require('@contrast/common');
|
|
6
|
+
const sinon = require('sinon');
|
|
7
|
+
const { expect } = require('chai');
|
|
8
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
9
|
+
const { UtilInspect } = require('@contrast/common');
|
|
10
|
+
|
|
11
|
+
describe('assess dataflow sinks child_process', function () {
|
|
12
|
+
let core, child_process, simulateRequestScope, trackString, tracker, reportFindings;
|
|
13
|
+
|
|
14
|
+
beforeEach(function () {
|
|
15
|
+
|
|
16
|
+
child_process = {
|
|
17
|
+
exec() { },
|
|
18
|
+
execSync() { },
|
|
19
|
+
spawn() { },
|
|
20
|
+
spawnSync() { },
|
|
21
|
+
execFile() { },
|
|
22
|
+
execFileSync() { }
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
26
|
+
tracker = core.assess.dataflow.tracker;
|
|
27
|
+
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
28
|
+
const origCreateSinkEvent = core.assess.eventFactory.createSinkEvent;
|
|
29
|
+
|
|
30
|
+
core.assess.eventFactory.createSinkEvent = function (data) {
|
|
31
|
+
if (data.tags['do-not-create-an-event']) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return origCreateSinkEvent(data);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
core.depHooks.resolve.yields(child_process);
|
|
38
|
+
|
|
39
|
+
require('./child-process')(core).install();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
['execFile', 'execFileSync', 'execSync', 'spawn', 'spawnSync'].forEach((method) => {
|
|
43
|
+
describe(`skips instrumentation in faulty cases for child_process.${method}()`, function () {
|
|
44
|
+
it('skips instrumentation if assess store is missing', function () {
|
|
45
|
+
child_process[method]('test &whoami');
|
|
46
|
+
expect(reportFindings).not.to.have.been.called;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('skips instrumentation if a command value is not provided ', function () {
|
|
50
|
+
simulateRequestScope(function () {
|
|
51
|
+
child_process[method]();
|
|
52
|
+
expect(reportFindings).not.to.have.been.called;
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('skips instrumentation if the command value is not a string', function () {
|
|
57
|
+
simulateRequestScope(function () {
|
|
58
|
+
child_process[method]({});
|
|
59
|
+
expect(reportFindings).not.to.have.been.called;
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
['spawn', 'spawnSync'].forEach((method) => {
|
|
66
|
+
describe(`instrumentation specific for child_process.${method}`, function () {
|
|
67
|
+
it('skips instrumentation if neither the command nor the args are tracked', function () {
|
|
68
|
+
simulateRequestScope(function () {
|
|
69
|
+
child_process[method]('test', ['whoami'], { shell: true });
|
|
70
|
+
expect(reportFindings).not.to.have.been.called;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('skips instrumentation if only the args are tracked and shell option is set to false', function () {
|
|
75
|
+
simulateRequestScope(function () {
|
|
76
|
+
const str = trackString('whoami', {
|
|
77
|
+
tags: {
|
|
78
|
+
[UNTRUSTED]: [0, 11],
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const { extern } = tracker.getData(str);
|
|
82
|
+
|
|
83
|
+
child_process[method]('test', [extern], { shell: false });
|
|
84
|
+
expect(reportFindings).not.to.have.been.called;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('reports an cmd-injection from the command argument', function () {
|
|
89
|
+
simulateRequestScope(function () {
|
|
90
|
+
const value = 'test &whoami';
|
|
91
|
+
const extern = trackString(value, {
|
|
92
|
+
tags: {
|
|
93
|
+
[UNTRUSTED]: [0, 11],
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
child_process[method](extern);
|
|
98
|
+
child_process[method](extern, ['untracked-arg']);
|
|
99
|
+
child_process[method](extern, ['untracked-arg'], { shell: true });
|
|
100
|
+
expect(reportFindings).to.have.been.calledThrice;
|
|
101
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
102
|
+
ruleId: 'cmd-injection',
|
|
103
|
+
sinkEvent: {
|
|
104
|
+
name: `child_process.${method}`,
|
|
105
|
+
moduleName: 'child_process',
|
|
106
|
+
methodName: method,
|
|
107
|
+
context: `child_process.${method}('${extern}')`,
|
|
108
|
+
object: {
|
|
109
|
+
value: 'child_process',
|
|
110
|
+
tracked: false,
|
|
111
|
+
},
|
|
112
|
+
args: [{ value, tracked: true }],
|
|
113
|
+
tags: { [UNTRUSTED]: [0, 11] },
|
|
114
|
+
source: 'P0',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
118
|
+
ruleId: 'cmd-injection',
|
|
119
|
+
sinkEvent: {
|
|
120
|
+
name: `child_process.${method}`,
|
|
121
|
+
moduleName: 'child_process',
|
|
122
|
+
methodName: method,
|
|
123
|
+
context: `child_process.${method}('${extern}', [ 'untracked-arg' ])`,
|
|
124
|
+
object: {
|
|
125
|
+
value: 'child_process',
|
|
126
|
+
tracked: false,
|
|
127
|
+
},
|
|
128
|
+
args: [
|
|
129
|
+
{ value, tracked: true },
|
|
130
|
+
{ value: UtilInspect(['untracked-arg']), tracked: false }
|
|
131
|
+
],
|
|
132
|
+
tags: { [UNTRUSTED]: [0, 11] },
|
|
133
|
+
source: 'P0',
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
137
|
+
ruleId: 'cmd-injection',
|
|
138
|
+
sinkEvent: {
|
|
139
|
+
name: `child_process.${method}`,
|
|
140
|
+
moduleName: 'child_process',
|
|
141
|
+
methodName: method,
|
|
142
|
+
context: `child_process.${method}('${extern}', [ 'untracked-arg' ], { shell: true })`,
|
|
143
|
+
object: {
|
|
144
|
+
value: 'child_process',
|
|
145
|
+
tracked: false,
|
|
146
|
+
},
|
|
147
|
+
args: [
|
|
148
|
+
{ value, tracked: true },
|
|
149
|
+
{ value: UtilInspect(['untracked-arg']), tracked: false },
|
|
150
|
+
{ value: UtilInspect({ shell: true }), tracked: false }
|
|
151
|
+
],
|
|
152
|
+
tags: { [UNTRUSTED]: [0, 11] },
|
|
153
|
+
source: 'P0',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('reports an cmd-injection from the args for the command with the shell option set to true', function () {
|
|
160
|
+
simulateRequestScope(function () {
|
|
161
|
+
const value = '; whoami';
|
|
162
|
+
const extern = trackString(value, {
|
|
163
|
+
tags: {
|
|
164
|
+
[UNTRUSTED]: [0, 7],
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
child_process[method]('test', [extern], { shell: true });
|
|
169
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
170
|
+
ruleId: 'cmd-injection',
|
|
171
|
+
sinkEvent: {
|
|
172
|
+
name: `child_process.${method}`,
|
|
173
|
+
moduleName: 'child_process',
|
|
174
|
+
methodName: method,
|
|
175
|
+
context: `child_process.${method}('test', [ '${extern}' ], { shell: true })`,
|
|
176
|
+
object: {
|
|
177
|
+
value: 'child_process',
|
|
178
|
+
tracked: false,
|
|
179
|
+
},
|
|
180
|
+
args: [
|
|
181
|
+
{ value: 'test', tracked: false },
|
|
182
|
+
{ value: UtilInspect([value]), tracked: true },
|
|
183
|
+
{ value: UtilInspect({ shell: true }), tracked: false },
|
|
184
|
+
],
|
|
185
|
+
tags: { [UNTRUSTED]: [0, 7] },
|
|
186
|
+
source: 'P1',
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('reports an cmd-injection from the args for the command with the shell option set to true even with an error in the first event creation', function () {
|
|
193
|
+
simulateRequestScope(function () {
|
|
194
|
+
const cmd = trackString('test', {
|
|
195
|
+
tags: {
|
|
196
|
+
[UNTRUSTED]: [0, 3],
|
|
197
|
+
'do-not-create-an-event': [0, 3],
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
const value = '; whoami';
|
|
201
|
+
const extern = trackString(value, {
|
|
202
|
+
tags: {
|
|
203
|
+
[UNTRUSTED]: [0, 7],
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
child_process[method](cmd, [extern], { shell: true });
|
|
208
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
209
|
+
ruleId: 'cmd-injection',
|
|
210
|
+
sinkEvent: {
|
|
211
|
+
name: `child_process.${method}`,
|
|
212
|
+
object: {
|
|
213
|
+
value: 'child_process',
|
|
214
|
+
tracked: false,
|
|
215
|
+
},
|
|
216
|
+
args: [
|
|
217
|
+
{ value: 'test', tracked: true },
|
|
218
|
+
{ value: UtilInspect([value]), tracked: true },
|
|
219
|
+
{ value: UtilInspect({ shell: true }), tracked: false },
|
|
220
|
+
],
|
|
221
|
+
tags: { [UNTRUSTED]: [0, 7] },
|
|
222
|
+
source: 'P1',
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
['exec', 'execSync'].forEach((method) => {
|
|
231
|
+
describe(`instrumentation specific for child_process.${method}`, function () {
|
|
232
|
+
it('reports an cmd-injection from the command argument', function () {
|
|
233
|
+
simulateRequestScope(function() {
|
|
234
|
+
const value = 'test &whoami';
|
|
235
|
+
const extern = trackString(value, {
|
|
236
|
+
tags: {
|
|
237
|
+
[UNTRUSTED]: [0, 11],
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
child_process[method](extern);
|
|
242
|
+
child_process[method](extern, ['untracked-arg']);
|
|
243
|
+
child_process[method](extern, ['untracked-arg'], { shell: true });
|
|
244
|
+
expect(reportFindings).to.have.been.calledThrice;
|
|
245
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
246
|
+
ruleId: 'cmd-injection',
|
|
247
|
+
sinkEvent: {
|
|
248
|
+
name: `child_process.${method}`,
|
|
249
|
+
object: {
|
|
250
|
+
value: 'child_process',
|
|
251
|
+
tracked: false,
|
|
252
|
+
},
|
|
253
|
+
args: [{ value, tracked: true }],
|
|
254
|
+
tags: { [UNTRUSTED]: [0, 11] },
|
|
255
|
+
source: 'P0',
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
259
|
+
ruleId: 'cmd-injection',
|
|
260
|
+
sinkEvent: {
|
|
261
|
+
name: `child_process.${method}`,
|
|
262
|
+
object: {
|
|
263
|
+
value: 'child_process',
|
|
264
|
+
tracked: false,
|
|
265
|
+
},
|
|
266
|
+
args: [
|
|
267
|
+
{ value, tracked: true },
|
|
268
|
+
{ value: UtilInspect(['untracked-arg']), tracked: false }
|
|
269
|
+
],
|
|
270
|
+
tags: { [UNTRUSTED]: [0, 11] },
|
|
271
|
+
source: 'P0',
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
275
|
+
ruleId: 'cmd-injection',
|
|
276
|
+
sinkEvent: {
|
|
277
|
+
name: `child_process.${method}`,
|
|
278
|
+
object: {
|
|
279
|
+
value: 'child_process',
|
|
280
|
+
tracked: false,
|
|
281
|
+
},
|
|
282
|
+
args: [
|
|
283
|
+
{ value, tracked: true },
|
|
284
|
+
{ value: UtilInspect(['untracked-arg']), tracked: false },
|
|
285
|
+
{ value: UtilInspect({ shell: true }), tracked: false }
|
|
286
|
+
],
|
|
287
|
+
tags: { [UNTRUSTED]: [0, 11] },
|
|
288
|
+
source: 'P0',
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
['execFile', 'execFileSync'].forEach((method) => {
|
|
297
|
+
describe(`instrumentation specific for child_process.${method}`, function () {
|
|
298
|
+
it('does not report if the second argument is not an Array, or is an empty Array', function () {
|
|
299
|
+
simulateRequestScope(function () {
|
|
300
|
+
child_process[method]('test', { shell: true });
|
|
301
|
+
child_process[method]('test', [], { shell: true });
|
|
302
|
+
child_process[method]('test', 'test', { shell: true });
|
|
303
|
+
expect(reportFindings).to.not.have.been.called;
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('reports an cmd-injection from the args for the command with the shell option set to true', function () {
|
|
308
|
+
simulateRequestScope(function () {
|
|
309
|
+
const value = '; showami';
|
|
310
|
+
const extern = trackString(value, {
|
|
311
|
+
tags: {
|
|
312
|
+
[UNTRUSTED]: [0, 7],
|
|
313
|
+
},
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
child_process[method]('test', [extern], { shell: true });
|
|
317
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
318
|
+
ruleId: 'cmd-injection',
|
|
319
|
+
sinkEvent: {
|
|
320
|
+
name: `child_process.${method}`,
|
|
321
|
+
object: {
|
|
322
|
+
value: 'child_process',
|
|
323
|
+
tracked: false,
|
|
324
|
+
},
|
|
325
|
+
args: [
|
|
326
|
+
{ value: 'test', tracked: false },
|
|
327
|
+
{ value: UtilInspect([value]), tracked: true },
|
|
328
|
+
{ value: UtilInspect({ shell: true }), tracked: false },
|
|
329
|
+
],
|
|
330
|
+
tags: { [UNTRUSTED]: [0, 7] },
|
|
331
|
+
source: 'P1',
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
DataflowTag: { UNTRUSTED, CUSTOM_VALIDATED },
|
|
5
|
+
Rule: { UNSAFE_CODE_EXECUTION },
|
|
6
|
+
} = require('@contrast/common');
|
|
7
|
+
const sinon = require('sinon');
|
|
8
|
+
const { expect } = require('chai');
|
|
9
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
+
|
|
11
|
+
describe('assess dataflow sinks eval', function () {
|
|
12
|
+
let core, simulateRequestScope, trackString, reportFindings, reportSafePositive;
|
|
13
|
+
|
|
14
|
+
beforeEach(function () {
|
|
15
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
16
|
+
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
17
|
+
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
18
|
+
core.contrastMethods.install();
|
|
19
|
+
|
|
20
|
+
require('./eval')(core).install();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('skips instrumentation if assess store is missing', function () {
|
|
24
|
+
global.ContrastMethods.eval('test');
|
|
25
|
+
|
|
26
|
+
expect(reportFindings).not.to.have.been.called;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('skips instrumentation if a value is not provided ', function () {
|
|
30
|
+
simulateRequestScope(function () {
|
|
31
|
+
global.ContrastMethods.eval();
|
|
32
|
+
|
|
33
|
+
expect(reportFindings).not.to.have.been.called;
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('skips instrumentation if the argument is not a tracked', function () {
|
|
38
|
+
simulateRequestScope(function () {
|
|
39
|
+
global.ContrastMethods.eval('not-tracked');
|
|
40
|
+
|
|
41
|
+
expect(reportFindings).not.to.have.been.called;
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('skips instrumentation if the argument is sanitized', function () {
|
|
46
|
+
simulateRequestScope(function () {
|
|
47
|
+
const value = 'test';
|
|
48
|
+
const extern = trackString(value, {
|
|
49
|
+
tags: {
|
|
50
|
+
[UNTRUSTED]: [0, 3],
|
|
51
|
+
[CUSTOM_VALIDATED]: [0, 3]
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
global.ContrastMethods.eval(extern);
|
|
56
|
+
|
|
57
|
+
expect(reportFindings).not.to.have.been.called;
|
|
58
|
+
expect(reportSafePositive).to.have.been.calledWith({
|
|
59
|
+
name: 'eval',
|
|
60
|
+
ruleId: UNSAFE_CODE_EXECUTION,
|
|
61
|
+
safeTags: [CUSTOM_VALIDATED],
|
|
62
|
+
strInfo: { value, tags: { [UNTRUSTED]: [0, 3], [CUSTOM_VALIDATED]: [0, 3] } }
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('reports an unsafe-code-execution', function () {
|
|
68
|
+
simulateRequestScope(function () {
|
|
69
|
+
const value = 'test';
|
|
70
|
+
const extern = trackString(value, {
|
|
71
|
+
tags: {
|
|
72
|
+
[UNTRUSTED]: [0, 3],
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
global.ContrastMethods.eval(extern);
|
|
77
|
+
|
|
78
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
79
|
+
ruleId: UNSAFE_CODE_EXECUTION,
|
|
80
|
+
sinkEvent: {
|
|
81
|
+
args: [{ value, tracked: true }],
|
|
82
|
+
context: 'eval(\'test\')',
|
|
83
|
+
name: 'eval',
|
|
84
|
+
moduleName: 'global',
|
|
85
|
+
methodName: 'eval',
|
|
86
|
+
object: { value: 'global', tracked: false },
|
|
87
|
+
source: 'P0',
|
|
88
|
+
tags: { [UNTRUSTED]: [0, 3] }
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const proxyquire = require('proxyquire');
|
|
5
|
+
const sinon = require('sinon');
|
|
6
|
+
const mocks = require('@contrast/test/mocks');
|
|
7
|
+
|
|
8
|
+
const MODULES = ['unvalidatedRedirect'];
|
|
9
|
+
|
|
10
|
+
describe('assess dataflow sinks express', function () {
|
|
11
|
+
let core, express;
|
|
12
|
+
|
|
13
|
+
beforeEach(function () {
|
|
14
|
+
core = mocks.core();
|
|
15
|
+
core.assess = { dataflow: { sinks: {} } };
|
|
16
|
+
|
|
17
|
+
const moduleMock = (name) => (deps) => {
|
|
18
|
+
deps.assess.dataflow.sinks.express[name] = { install: sinon.stub() };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
express = proxyquire('.', {
|
|
22
|
+
'./reflected-xss': moduleMock('reflectedXss'),
|
|
23
|
+
'./unvalidated-redirect': moduleMock('unvalidatedRedirect'),
|
|
24
|
+
})(core);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('installs its components', function () {
|
|
28
|
+
express.install();
|
|
29
|
+
MODULES.forEach((module) => {
|
|
30
|
+
expect(express[module].install).to.have.been.calledOnce;
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -73,72 +73,70 @@ module.exports = function(core) {
|
|
|
73
73
|
|
|
74
74
|
reflectedXss.install = function() {
|
|
75
75
|
depHooks.resolve({ name: 'express', file: 'lib/response' }, (Response) => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (!sourceContext) return next();
|
|
76
|
+
const name = 'Express.Response.send';
|
|
77
|
+
patcher.patch(Response, 'send', {
|
|
78
|
+
name,
|
|
79
|
+
patchType,
|
|
80
|
+
around: (next, data) => {
|
|
81
|
+
const sourceContext = getSourceContext(RULE, ruleId);
|
|
82
|
+
if (!sourceContext) return next();
|
|
84
83
|
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
const { contentType } = sourceContext.responseData;
|
|
85
|
+
if (contentType && isSafeContentType(contentType)) return next();
|
|
87
86
|
|
|
88
|
-
|
|
87
|
+
const [str] = data.args;
|
|
89
88
|
|
|
90
|
-
|
|
89
|
+
if (!str || !isString(str)) return next();
|
|
91
90
|
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
const strInfo = tracker.getData(str);
|
|
92
|
+
if (!strInfo) return next();
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
94
|
+
if (strInfo.tags && isVulnerable(UNTRUSTED, safeTags, strInfo.tags)) {
|
|
95
|
+
const sinkEvent = createSinkEvent({
|
|
96
|
+
args: [{
|
|
97
|
+
tracked: true,
|
|
98
|
+
value: strInfo.value,
|
|
99
|
+
}],
|
|
100
|
+
context: `response.send('${strInfo.value}')`,
|
|
101
|
+
history: [strInfo],
|
|
102
|
+
name,
|
|
103
|
+
moduleName: 'express',
|
|
104
|
+
methodName: 'Response.send',
|
|
105
|
+
object: {
|
|
106
|
+
tracked: false,
|
|
107
|
+
value: 'Express.Response',
|
|
108
|
+
},
|
|
109
|
+
result: {
|
|
110
|
+
tracked: false,
|
|
111
|
+
value: undefined,
|
|
112
|
+
},
|
|
113
|
+
tags: strInfo.tags,
|
|
114
|
+
source: 'P0',
|
|
115
|
+
stacktraceOpts: {
|
|
116
|
+
constructorOpt: data.hooked,
|
|
117
|
+
prependFrames: [data.orig]
|
|
118
|
+
},
|
|
119
|
+
});
|
|
121
120
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
ruleId,
|
|
125
|
-
sinkEvent
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
} else if (config.assess.safe_positives.enable) {
|
|
129
|
-
reportSafePositive({
|
|
130
|
-
name,
|
|
121
|
+
if (sinkEvent) {
|
|
122
|
+
reportFindings({
|
|
131
123
|
ruleId,
|
|
132
|
-
|
|
133
|
-
strInfo: {
|
|
134
|
-
tags: strInfo.tags,
|
|
135
|
-
value: strInfo.value,
|
|
136
|
-
}
|
|
124
|
+
sinkEvent
|
|
137
125
|
});
|
|
138
126
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
127
|
+
} else if (config.assess.safe_positives.enable) {
|
|
128
|
+
reportSafePositive({
|
|
129
|
+
name,
|
|
130
|
+
ruleId,
|
|
131
|
+
safeTags: filterSafeTags(safeTags, strInfo),
|
|
132
|
+
strInfo: {
|
|
133
|
+
tags: strInfo.tags,
|
|
134
|
+
value: strInfo.value,
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return ruleScopes.run(ruleId, next);
|
|
139
|
+
},
|
|
142
140
|
});
|
|
143
141
|
});
|
|
144
142
|
};
|