@contrast/assess 1.46.1 → 1.46.3
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/package.json +14 -11
- package/lib/crypto-analysis/install/crypto.test.js +0 -146
- package/lib/crypto-analysis/install/math.test.js +0 -65
- package/lib/dataflow/index.test.js +0 -36
- package/lib/dataflow/propagation/index.test.js +0 -103
- package/lib/dataflow/propagation/install/JSON/index.test.js +0 -50
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +0 -232
- package/lib/dataflow/propagation/install/JSON/parse.test.js +0 -968
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +0 -265
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +0 -106
- package/lib/dataflow/propagation/install/buffer.test.js +0 -112
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +0 -94
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +0 -49
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +0 -50
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +0 -148
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +0 -145
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +0 -78
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +0 -69
- package/lib/dataflow/propagation/install/ejs/template.test.js +0 -62
- package/lib/dataflow/propagation/install/encode-uri.test.js +0 -83
- package/lib/dataflow/propagation/install/escape-html.test.js +0 -71
- package/lib/dataflow/propagation/install/escape.test.js +0 -73
- package/lib/dataflow/propagation/install/fastify-send.test.js +0 -42
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +0 -71
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +0 -58
- package/lib/dataflow/propagation/install/joi/any.test.js +0 -270
- package/lib/dataflow/propagation/install/joi/array.test.js +0 -912
- package/lib/dataflow/propagation/install/joi/boolean.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/expression.test.js +0 -76
- package/lib/dataflow/propagation/install/joi/index.test.js +0 -39
- package/lib/dataflow/propagation/install/joi/number.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/object.test.js +0 -119
- package/lib/dataflow/propagation/install/joi/ref.test.js +0 -607
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +0 -513
- package/lib/dataflow/propagation/install/mongoose/index.test.js +0 -42
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +0 -348
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +0 -511
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +0 -199
- package/lib/dataflow/propagation/install/mustache-escape.test.js +0 -62
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +0 -74
- package/lib/dataflow/propagation/install/parse-int.test.js +0 -48
- package/lib/dataflow/propagation/install/path/basename.test.js +0 -143
- package/lib/dataflow/propagation/install/path/dirname.test.js +0 -167
- package/lib/dataflow/propagation/install/path/extname.test.js +0 -141
- package/lib/dataflow/propagation/install/path/format.test.js +0 -250
- package/lib/dataflow/propagation/install/path/index.test.js +0 -45
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +0 -485
- package/lib/dataflow/propagation/install/path/normalize.test.js +0 -176
- package/lib/dataflow/propagation/install/path/parse.test.js +0 -238
- package/lib/dataflow/propagation/install/path/relative.test.js +0 -239
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +0 -158
- package/lib/dataflow/propagation/install/pug/index.test.js +0 -55
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +0 -69
- package/lib/dataflow/propagation/install/querystring/escape.test.js +0 -63
- package/lib/dataflow/propagation/install/querystring/index.test.js +0 -40
- package/lib/dataflow/propagation/install/querystring/parse.test.js +0 -272
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +0 -301
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +0 -283
- package/lib/dataflow/propagation/install/send.test.js +0 -63
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +0 -74
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +0 -119
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +0 -100
- package/lib/dataflow/propagation/install/string/concat.test.js +0 -145
- package/lib/dataflow/propagation/install/string/format-methods.test.js +0 -74
- package/lib/dataflow/propagation/install/string/html-methods.test.js +0 -177
- package/lib/dataflow/propagation/install/string/index.test.js +0 -103
- package/lib/dataflow/propagation/install/string/match-all.test.js +0 -412
- package/lib/dataflow/propagation/install/string/match.test.js +0 -374
- package/lib/dataflow/propagation/install/string/replace.test.js +0 -601
- package/lib/dataflow/propagation/install/string/slice.test.js +0 -278
- package/lib/dataflow/propagation/install/string/split.test.js +0 -513
- package/lib/dataflow/propagation/install/string/substring.test.js +0 -251
- package/lib/dataflow/propagation/install/string/trim.test.js +0 -135
- package/lib/dataflow/propagation/install/unescape.test.js +0 -78
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +0 -63
- package/lib/dataflow/propagation/install/url/parse.test.js +0 -391
- package/lib/dataflow/propagation/install/url/searchParams.test.js +0 -538
- package/lib/dataflow/propagation/install/url/url.test.js +0 -466
- package/lib/dataflow/propagation/install/util-format.test.js +0 -336
- package/lib/dataflow/propagation/install/validator/hooks.test.js +0 -211
- package/lib/dataflow/sinks/index.test.js +0 -78
- package/lib/dataflow/sinks/install/child-process.test.js +0 -338
- package/lib/dataflow/sinks/install/eval.test.js +0 -95
- package/lib/dataflow/sinks/install/express/index.test.js +0 -33
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +0 -109
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +0 -144
- package/lib/dataflow/sinks/install/fastify/index.test.js +0 -32
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/fs.test.js +0 -138
- package/lib/dataflow/sinks/install/function.test.js +0 -103
- package/lib/dataflow/sinks/install/hapi/index.test.js +0 -32
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/http/index.test.js +0 -33
- package/lib/dataflow/sinks/install/http/request.test.js +0 -184
- package/lib/dataflow/sinks/install/http/server-response.test.js +0 -160
- package/lib/dataflow/sinks/install/koa/index.test.js +0 -32
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +0 -200
- package/lib/dataflow/sinks/install/libxmljs.test.js +0 -158
- package/lib/dataflow/sinks/install/marsdb.test.js +0 -166
- package/lib/dataflow/sinks/install/mongodb.test.js +0 -617
- package/lib/dataflow/sinks/install/mssql.test.js +0 -134
- package/lib/dataflow/sinks/install/mysql.test.js +0 -224
- package/lib/dataflow/sinks/install/node-serialize.test.js +0 -83
- package/lib/dataflow/sinks/install/postgres.test.js +0 -152
- package/lib/dataflow/sinks/install/restify.test.js +0 -140
- package/lib/dataflow/sinks/install/sequelize.test.js +0 -100
- package/lib/dataflow/sinks/install/sqlite3.test.js +0 -118
- package/lib/dataflow/sinks/install/vm.test.js +0 -326
- package/lib/dataflow/sources/handler.test.js +0 -501
- package/lib/dataflow/sources/index.test.js +0 -60
- package/lib/dataflow/sources/install/body-parser1.test.js +0 -244
- package/lib/dataflow/sources/install/busboy.test.js +0 -152
- package/lib/dataflow/sources/install/cookie-parser1.test.js +0 -141
- package/lib/dataflow/sources/install/express/params.test.js +0 -110
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +0 -107
- package/lib/dataflow/sources/install/fastify/fastify.test.js +0 -207
- package/lib/dataflow/sources/install/fastify/index.test.js +0 -33
- package/lib/dataflow/sources/install/formidable1.test.js +0 -119
- package/lib/dataflow/sources/install/graphql-http.test.js +0 -133
- package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -171
- package/lib/dataflow/sources/install/hapi/index.test.js +0 -33
- package/lib/dataflow/sources/install/http.test.js +0 -149
- package/lib/dataflow/sources/install/koa/index.test.js +0 -40
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +0 -160
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +0 -197
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +0 -146
- package/lib/dataflow/sources/install/koa/koa2.test.js +0 -145
- package/lib/dataflow/sources/install/multer1.test.js +0 -143
- package/lib/dataflow/sources/install/qs6.test.js +0 -131
- package/lib/dataflow/sources/install/querystring.test.js +0 -82
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +0 -86
- package/lib/dataflow/sources/install/restify/index.test.js +0 -38
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +0 -140
- package/lib/dataflow/sources/install/restify/router.test.js +0 -81
- package/lib/dataflow/tag-utils-complete.test.js +0 -27
- package/lib/dataflow/tag-utils.test.js +0 -192
- package/lib/dataflow/tracker.test.js +0 -216
- package/lib/dataflow/utils/is-safe-content-type.test.js +0 -16
- package/lib/dataflow/utils/is-vulnerable.test.js +0 -115
- package/lib/event-factory.test.js +0 -326
- package/lib/get-policy.test.js +0 -194
- package/lib/get-source-context.test.js +0 -161
- package/lib/index.test.js +0 -45
- package/lib/make-source-context.test.js +0 -50
- package/lib/response-scanning/handlers/index.test.js +0 -419
- package/lib/response-scanning/handlers/utils.test.js +0 -380
- package/lib/response-scanning/index.test.js +0 -41
- package/lib/response-scanning/install/http.test.js +0 -175
- package/lib/rule-scopes.test.js +0 -27
- package/lib/sampler/common.test.js +0 -101
- package/lib/sampler/index.test.js +0 -313
- package/lib/session-configuration/handlers.test.js +0 -84
- package/lib/session-configuration/index.test.js +0 -36
- package/lib/session-configuration/install/express-session.test.js +0 -218
- package/lib/session-configuration/install/fastify-cookie.test.js +0 -63
- package/lib/session-configuration/install/hapi.test.js +0 -269
- package/lib/session-configuration/install/koa.test.js +0 -92
|
@@ -1,338 +0,0 @@
|
|
|
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 { primordials: { 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
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
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
|
-
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const {
|
|
6
|
-
DataflowTag: {
|
|
7
|
-
UNTRUSTED,
|
|
8
|
-
URL_ENCODED,
|
|
9
|
-
}
|
|
10
|
-
} = require('@contrast/common');
|
|
11
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
12
|
-
|
|
13
|
-
describe('assess dataflow sinks express reflected-xss', function () {
|
|
14
|
-
let core, Response, simulateRequestScope, trackString, reportFindings, reportSafePositive;
|
|
15
|
-
|
|
16
|
-
beforeEach(function () {
|
|
17
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
18
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
19
|
-
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
20
|
-
|
|
21
|
-
Response = {
|
|
22
|
-
send: () => { }
|
|
23
|
-
};
|
|
24
|
-
core.depHooks.resolve.yields(Response);
|
|
25
|
-
|
|
26
|
-
require('./reflected-xss')(core).install();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('skips instrumentation if there is no assess store', function () {
|
|
30
|
-
Response.send('hello');
|
|
31
|
-
expect(reportFindings).to.not.have.been.called;
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('skips instrumentation if chunk does not exist', function () {
|
|
35
|
-
simulateRequestScope(function () {
|
|
36
|
-
Response.send();
|
|
37
|
-
expect(reportFindings).to.not.have.been.called;
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('skip instrumentation if chunk is not string', function () {
|
|
42
|
-
simulateRequestScope(function () {
|
|
43
|
-
Response.send(true);
|
|
44
|
-
expect(reportFindings).to.not.have.been.called;
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('skips instrumentation if chunk is not tracked', function () {
|
|
49
|
-
simulateRequestScope(function () {
|
|
50
|
-
Response.send('foo');
|
|
51
|
-
expect(reportFindings).to.not.have.been.called;
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('reports a "safe positive" event when safe tags overlap UNTRUSTED', function () {
|
|
56
|
-
simulateRequestScope(function () {
|
|
57
|
-
const value = 'foo';
|
|
58
|
-
const extern = trackString(value, {
|
|
59
|
-
tags: {
|
|
60
|
-
[URL_ENCODED]: [0, 2],
|
|
61
|
-
[UNTRUSTED]: [0, 2],
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
Response.send(extern);
|
|
66
|
-
|
|
67
|
-
expect(reportSafePositive).to.have.been.calledWithMatch({
|
|
68
|
-
name: 'Express.Response.send',
|
|
69
|
-
ruleId: 'reflected-xss',
|
|
70
|
-
safeTags: [URL_ENCODED],
|
|
71
|
-
strInfo: {
|
|
72
|
-
tags: { [URL_ENCODED]: [0, 2], [UNTRUSTED]: [0, 2] },
|
|
73
|
-
value
|
|
74
|
-
},
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('reports a reflected-xss', function () {
|
|
80
|
-
simulateRequestScope(function () {
|
|
81
|
-
const value = 'foo';
|
|
82
|
-
const extern = trackString(value, {
|
|
83
|
-
tags: {
|
|
84
|
-
[UNTRUSTED]: [0, 2]
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
Response.send(extern);
|
|
88
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
89
|
-
ruleId: 'reflected-xss',
|
|
90
|
-
sinkEvent: {
|
|
91
|
-
args: [{ value, tracked: true }],
|
|
92
|
-
context: "response.send('foo')",
|
|
93
|
-
name: 'Express.Response.send',
|
|
94
|
-
moduleName: 'express',
|
|
95
|
-
methodName: 'Response.send',
|
|
96
|
-
object: {
|
|
97
|
-
value: 'Express.Response',
|
|
98
|
-
tracked: false,
|
|
99
|
-
},
|
|
100
|
-
result: { value: undefined, tracked: false },
|
|
101
|
-
source: 'P0',
|
|
102
|
-
tags: {
|
|
103
|
-
[UNTRUSTED]: [0, 2],
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|