@contrast/assess 1.46.0 → 1.46.2
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,326 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const { InputType } = require('@contrast/common');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
|
|
8
|
-
const os = require('os');
|
|
9
|
-
|
|
10
|
-
const testMethod = os.platform() === 'win32' ? describe.skip : describe;
|
|
11
|
-
|
|
12
|
-
testMethod('assess event-factory', function () {
|
|
13
|
-
let core, createSourceEvent, createPropagationEvent, createSinkEvent;
|
|
14
|
-
|
|
15
|
-
beforeEach(function () {
|
|
16
|
-
({ core } = initAssessFixture());
|
|
17
|
-
({
|
|
18
|
-
createSourceEvent,
|
|
19
|
-
createPropagationEvent,
|
|
20
|
-
createSinkEvent
|
|
21
|
-
} = require('./event-factory')(core));
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe('createSourceEvent', function () {
|
|
25
|
-
[
|
|
26
|
-
{
|
|
27
|
-
data: {},
|
|
28
|
-
invalidProp: 'result',
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
data: { result: { tracked: true, value: 'foo' } },
|
|
32
|
-
invalidProp: 'name',
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
data: {
|
|
36
|
-
name: 'frogs',
|
|
37
|
-
result: { tracked: true, value: 'foo' },
|
|
38
|
-
inputType: 'bad-value',
|
|
39
|
-
},
|
|
40
|
-
invalidProp: 'inputType',
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
data: {
|
|
44
|
-
name: 'frogs',
|
|
45
|
-
result: { tracked: true, value: 'foo' },
|
|
46
|
-
inputType: InputType.QUERYSTRING,
|
|
47
|
-
},
|
|
48
|
-
invalidProp: 'tags',
|
|
49
|
-
message: 'event has no tags'
|
|
50
|
-
}
|
|
51
|
-
].forEach(({
|
|
52
|
-
data,
|
|
53
|
-
invalidProp,
|
|
54
|
-
message = `invalid ${invalidProp}`,
|
|
55
|
-
}) => {
|
|
56
|
-
it(`will not create event when props are invalid: ${message}`, function () {
|
|
57
|
-
const event = createSourceEvent(data);
|
|
58
|
-
expect(event).to.equal(null);
|
|
59
|
-
expect(core.logger.debug).to.have.been.calledWith(
|
|
60
|
-
sinon.match.object,
|
|
61
|
-
'Source event not created: %s',
|
|
62
|
-
message
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
[
|
|
68
|
-
{
|
|
69
|
-
data: {
|
|
70
|
-
name: 'COOKIE_VALUE.frogs',
|
|
71
|
-
result: { tracked: true, value: 'foo' },
|
|
72
|
-
inputType: InputType.COOKIE_VALUE,
|
|
73
|
-
tags: {
|
|
74
|
-
untrusted: [0, 4],
|
|
75
|
-
cookie: [0, 4],
|
|
76
|
-
},
|
|
77
|
-
stack: [],
|
|
78
|
-
},
|
|
79
|
-
}
|
|
80
|
-
].forEach(({ data, expected }) => {
|
|
81
|
-
it('returns the event data when validated', function () {
|
|
82
|
-
const event = createSourceEvent(data);
|
|
83
|
-
expect(event).to.equal(data);
|
|
84
|
-
expect(core.logger.debug).not.to.have.been.called;
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe('createPropagationEvent', function () {
|
|
90
|
-
const validData = {
|
|
91
|
-
name: 'String.prototype.concat',
|
|
92
|
-
history: [{ mock: 'SourceEvent' }],
|
|
93
|
-
object: {
|
|
94
|
-
value: 'test',
|
|
95
|
-
tracked: true
|
|
96
|
-
},
|
|
97
|
-
args: [{ value: '-another-test', tracked: false }],
|
|
98
|
-
result: {
|
|
99
|
-
value: 'test-another-test',
|
|
100
|
-
tracked: true
|
|
101
|
-
},
|
|
102
|
-
source: 'O',
|
|
103
|
-
target: 'R',
|
|
104
|
-
tags: { untrusted: [0, 3] }
|
|
105
|
-
};
|
|
106
|
-
const validStore = {
|
|
107
|
-
assess: {
|
|
108
|
-
propagationEventsCount: 0
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
const validResult = {
|
|
112
|
-
name: 'String.prototype.concat',
|
|
113
|
-
history: [{ mock: 'SourceEvent' }],
|
|
114
|
-
object: {
|
|
115
|
-
value: 'test',
|
|
116
|
-
tracked: true
|
|
117
|
-
},
|
|
118
|
-
args: [{ value: '-another-test', tracked: false }],
|
|
119
|
-
result: {
|
|
120
|
-
value: 'test-another-test',
|
|
121
|
-
tracked: true
|
|
122
|
-
},
|
|
123
|
-
tags: { untrusted: [0, 3] },
|
|
124
|
-
addedTags: [],
|
|
125
|
-
removedTags: [],
|
|
126
|
-
source: 'O',
|
|
127
|
-
target: 'R'
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
it('logs a debug statement for missing source context and returns null when executed in the wrong context', function () {
|
|
131
|
-
core.scopes.sources.run({}, function () {
|
|
132
|
-
const result = createPropagationEvent(validData);
|
|
133
|
-
|
|
134
|
-
expect(core.logger.debug).to.have.been.calledOnceWith(
|
|
135
|
-
sinon.match.object,
|
|
136
|
-
'No sourceContext found during Propagation event creation'
|
|
137
|
-
);
|
|
138
|
-
expect(result).to.be.null;
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('logs a debug statement for going above the maximum propagation events limit and returns null when we are above the said limit', function () {
|
|
143
|
-
core.scopes.sources.run({ assess: { propagationEventsCount: 500 } }, function () {
|
|
144
|
-
const result = createPropagationEvent(validData);
|
|
145
|
-
|
|
146
|
-
expect(core.logger.debug).to.have.been.calledOnceWith(
|
|
147
|
-
sinon.match.object,
|
|
148
|
-
'Maximum number of Propagation events reached. Event not created'
|
|
149
|
-
);
|
|
150
|
-
expect(result).to.be.null;
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
[
|
|
156
|
-
{
|
|
157
|
-
data: { ...validData, name: '' },
|
|
158
|
-
message: 'invalid name',
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
data: { ...validData, source: undefined },
|
|
162
|
-
message: 'invalid source',
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
data: { ...validData, history: [] },
|
|
166
|
-
message: 'invalid history',
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
data: { ...validData, source: 'S' },
|
|
170
|
-
message: 'invalid source',
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
data: { ...validData, target: 'T' },
|
|
174
|
-
message: 'invalid target',
|
|
175
|
-
},
|
|
176
|
-
].forEach(({ data, message }) => {
|
|
177
|
-
it(`logs a debug statement when insufficient data is passed and returns null: ${message}`, function () {
|
|
178
|
-
core.scopes.sources.run(validStore, function () {
|
|
179
|
-
const result = createPropagationEvent(data);
|
|
180
|
-
|
|
181
|
-
expect(core.logger.debug).to.have.been.calledOnceWith(
|
|
182
|
-
sinon.match.object,
|
|
183
|
-
'Propagation event not created: %s',
|
|
184
|
-
message,
|
|
185
|
-
);
|
|
186
|
-
expect(result).to.be.null;
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('returns an event with stacktrace generator function when stacktraces option is set to "ALL"', function () {
|
|
192
|
-
core.config.assess.stacktraces = 'ALL';
|
|
193
|
-
core.scopes.sources.run(validStore, function () {
|
|
194
|
-
const result = createPropagationEvent(validData);
|
|
195
|
-
|
|
196
|
-
expect(result).to.be.like(validResult);
|
|
197
|
-
expect(result.time).not.to.be.undefined;
|
|
198
|
-
expect(result.stack).to.be.an('array');
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
['SOME', 'SINK', 'NONE'].forEach((option) => {
|
|
203
|
-
it(`returns an event without stacktrace generator function when stacktraces option is not set to "ALL" and set to ${option}`, function () {
|
|
204
|
-
core.config.assess.stacktraces = option;
|
|
205
|
-
core.scopes.sources.run(validStore, function () {
|
|
206
|
-
const result = createPropagationEvent(validData);
|
|
207
|
-
|
|
208
|
-
expect(result).to.be.like(validResult);
|
|
209
|
-
expect(result.time).not.to.be.undefined;
|
|
210
|
-
expect(result.stack).to.deep.equal([]);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
describe('createSinkEvent', function () {
|
|
217
|
-
const validData = {
|
|
218
|
-
name: 'mysql/lib/Connection.query',
|
|
219
|
-
history: [{ mock: 'SourceEvent' }],
|
|
220
|
-
object: {
|
|
221
|
-
value: 'MySQL.Query#0001',
|
|
222
|
-
tracked: false
|
|
223
|
-
},
|
|
224
|
-
args: [{ value: 'malicious-value', tracked: true }],
|
|
225
|
-
result: {
|
|
226
|
-
value: null,
|
|
227
|
-
tracked: false
|
|
228
|
-
},
|
|
229
|
-
tags: { untrusted: [0, 14] },
|
|
230
|
-
source: 'P0'
|
|
231
|
-
};
|
|
232
|
-
const validStore = {
|
|
233
|
-
assess: {
|
|
234
|
-
propagationEventsCount: 0
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
const validResult = {
|
|
238
|
-
name: 'mysql/lib/Connection.query',
|
|
239
|
-
history: [{ mock: 'SourceEvent' }],
|
|
240
|
-
object: {
|
|
241
|
-
value: 'MySQL.Query#0001',
|
|
242
|
-
tracked: false
|
|
243
|
-
},
|
|
244
|
-
args: [{ value: 'malicious-value', tracked: true }],
|
|
245
|
-
result: {
|
|
246
|
-
value: null,
|
|
247
|
-
tracked: false
|
|
248
|
-
},
|
|
249
|
-
tags: { untrusted: [0, 14] },
|
|
250
|
-
source: 'P0',
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
it('logs a debug statement for missing source context and returns null when executed in the wrong context', function () {
|
|
254
|
-
core.scopes.sources.run({}, function () {
|
|
255
|
-
const result = createSinkEvent(validData);
|
|
256
|
-
|
|
257
|
-
expect(core.logger.debug).to.have.been.calledOnceWith(
|
|
258
|
-
sinon.match.object,
|
|
259
|
-
'no sourceContext found during sink event creation'
|
|
260
|
-
);
|
|
261
|
-
expect(result).to.be.null;
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
[
|
|
266
|
-
{
|
|
267
|
-
data: {
|
|
268
|
-
...validData,
|
|
269
|
-
name: '',
|
|
270
|
-
},
|
|
271
|
-
message: 'no sink event name'
|
|
272
|
-
},
|
|
273
|
-
{
|
|
274
|
-
data: {
|
|
275
|
-
...validData,
|
|
276
|
-
history: []
|
|
277
|
-
},
|
|
278
|
-
message: 'empty history for sink event'
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
data: {
|
|
282
|
-
...validData,
|
|
283
|
-
source: 'S'
|
|
284
|
-
},
|
|
285
|
-
message: 'malformed or missing sink event source field',
|
|
286
|
-
},
|
|
287
|
-
].forEach(({ data, message }) => {
|
|
288
|
-
it(`logs a debug statement when insufficient data is passed and returns null: ${message}`, function () {
|
|
289
|
-
core.scopes.sources.run(validStore, function () {
|
|
290
|
-
const result = createSinkEvent(data);
|
|
291
|
-
|
|
292
|
-
expect(core.logger.debug).to.have.been.calledWith(
|
|
293
|
-
sinon.match.object,
|
|
294
|
-
message
|
|
295
|
-
);
|
|
296
|
-
expect(result).to.be.null;
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
['ALL', 'SOME', 'SINK'].forEach((option) => {
|
|
302
|
-
it(`returns an event with stacktrace generator function when stacktraces option is not set to "NONE" and set to ${option}`, function () {
|
|
303
|
-
core.config.assess.stacktraces = option;
|
|
304
|
-
core.scopes.sources.run(validStore, function () {
|
|
305
|
-
const result = createSinkEvent(validData);
|
|
306
|
-
|
|
307
|
-
expect(result).to.be.like(validResult);
|
|
308
|
-
expect(result.time).not.to.be.undefined;
|
|
309
|
-
expect(result.stack).to.be.instanceOf(Array);
|
|
310
|
-
expect(result.stack.length).to.be.greaterThan(0);
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('returns an event without stacktrace generator function when stacktraces option is set to "NONE"', function () {
|
|
316
|
-
core.config.assess.stacktraces = 'NONE';
|
|
317
|
-
core.scopes.sources.run(validStore, function () {
|
|
318
|
-
const result = createSinkEvent(validData);
|
|
319
|
-
|
|
320
|
-
expect(result).to.be.like(validResult);
|
|
321
|
-
expect(result.time).not.to.be.undefined;
|
|
322
|
-
expect(result.stack).to.deep.equal([]);
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
});
|
|
326
|
-
});
|
package/lib/get-policy.test.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { Event } = require('@contrast/common');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
|
|
7
|
-
describe('assess getPolicy', function () {
|
|
8
|
-
let core, getPolicy;
|
|
9
|
-
|
|
10
|
-
beforeEach(function () {
|
|
11
|
-
({ core } = initAssessFixture());
|
|
12
|
-
getPolicy = require('./get-policy')(core);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
function assertPolicyOK(policy) {
|
|
16
|
-
expect(policy).to.have.property('enabledRules').and.be.a('Set').not.empty;
|
|
17
|
-
expect(policy).to.have.property('getInputPolicy').and.be.a('Function');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
it('inits policy and will adjust according to TS settings updates', function() {
|
|
21
|
-
let policy = getPolicy();
|
|
22
|
-
|
|
23
|
-
expect(policy.enabledRules).to.have.length.greaterThan(1);
|
|
24
|
-
expect(policy.enabledRules).to.contain('reflected-xss');
|
|
25
|
-
|
|
26
|
-
core.messages.emit(Event.SERVER_SETTINGS_UPDATE, {
|
|
27
|
-
assess: {
|
|
28
|
-
['sql-injection']: { enable: true },
|
|
29
|
-
['reflected-xss']: { enable: false },
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
policy = getPolicy();
|
|
34
|
-
|
|
35
|
-
expect(policy.enabledRules).to.contain('sql-injection');
|
|
36
|
-
expect(policy.enabledRules).not.to.contain('reflected-xss');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('url exclusions can disable all rules', function() {
|
|
40
|
-
const uriPath = '/exclude-all-rules';
|
|
41
|
-
let policy = getPolicy({ uriPath });
|
|
42
|
-
|
|
43
|
-
assertPolicyOK(policy);
|
|
44
|
-
|
|
45
|
-
core.messages.emit(Event.SERVER_SETTINGS_UPDATE, {
|
|
46
|
-
exclusions: {
|
|
47
|
-
url: [{
|
|
48
|
-
urls: ['/exclude-all-rules'],
|
|
49
|
-
matchStrategy: 'ONLY',
|
|
50
|
-
assessmentRules: [],
|
|
51
|
-
assess_rules: [],
|
|
52
|
-
protect_rules: [],
|
|
53
|
-
modes: ['assess', 'defend'],
|
|
54
|
-
name: 'UrlExclusionAllRules'
|
|
55
|
-
}]
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
policy = getPolicy({ uriPath });
|
|
60
|
-
expect(policy).to.be.null;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('url exclusions can disable specific rules', function() {
|
|
64
|
-
const uriPath = '/exclude-some-rules';
|
|
65
|
-
let policy = getPolicy({ uriPath });
|
|
66
|
-
|
|
67
|
-
assertPolicyOK(policy);
|
|
68
|
-
|
|
69
|
-
core.messages.emit(Event.SERVER_SETTINGS_UPDATE, {
|
|
70
|
-
exclusions: {
|
|
71
|
-
url: [{
|
|
72
|
-
urls: ['/exclude-some-rules'],
|
|
73
|
-
matchStrategy: 'ONLY',
|
|
74
|
-
assessmentRules: [],
|
|
75
|
-
assess_rules: ['sql-injection'],
|
|
76
|
-
protect_rules: [],
|
|
77
|
-
modes: ['assess', 'defend'],
|
|
78
|
-
name: 'UrlExclusionAllRules'
|
|
79
|
-
}]
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
policy = getPolicy({ uriPath });
|
|
84
|
-
expect(policy.enabledRules).not.to.contain('sql-injection');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
[
|
|
88
|
-
{
|
|
89
|
-
inputType: 'HEADER',
|
|
90
|
-
exclusionType: 'HEADER',
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
inputType: 'QUERYSTRING',
|
|
94
|
-
exclusionType: 'PARAMETER',
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
inputType: 'BODY',
|
|
98
|
-
exclusionType: 'PARAMETER',
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
inputType: 'URL_PARAMETER',
|
|
102
|
-
exclusionType: 'PARAMETER',
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
inputType: 'COOKIE_VALUE',
|
|
106
|
-
exclusionType: 'COOKIE',
|
|
107
|
-
},
|
|
108
|
-
].forEach(({ inputType, exclusionType }) => {
|
|
109
|
-
it(`input exclusions can exclude specific rules (input: ${inputType}, exclusion:${exclusionType})`, function() {
|
|
110
|
-
core.messages.emit(Event.SERVER_SETTINGS_UPDATE, {
|
|
111
|
-
exclusions: {
|
|
112
|
-
input: [{
|
|
113
|
-
type: exclusionType,
|
|
114
|
-
urls: ['/exclude-some-inputs', '/exclude-some-inputs-.*'],
|
|
115
|
-
matchStrategy: 'ONLY',
|
|
116
|
-
assessmentRules: [],
|
|
117
|
-
assess_rules: ['sql-injection', 'nosql-injection'],
|
|
118
|
-
protect_rules: [],
|
|
119
|
-
modes: ['assess', 'defend'],
|
|
120
|
-
name: 'abc.*'
|
|
121
|
-
}]
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const policy = getPolicy({ uriPath: '/exclude-some-inputs' });
|
|
126
|
-
let inputPolicy = policy.getInputPolicy(inputType, 'abcdef');
|
|
127
|
-
expect(inputPolicy).to.have.property('track', true);
|
|
128
|
-
expect(inputPolicy).to.have.property('excludedRules')
|
|
129
|
-
.to.be.a('Set')
|
|
130
|
-
.and.have.lengthOf(2)
|
|
131
|
-
.and.contain('nosql-injection')
|
|
132
|
-
.and.contain('sql-injection');
|
|
133
|
-
|
|
134
|
-
inputPolicy = policy.getInputPolicy(inputType, 'xyz');
|
|
135
|
-
expect(inputPolicy).to.have.property('track', true);
|
|
136
|
-
expect(inputPolicy).to.have.property('excludedRules')
|
|
137
|
-
.to.be.a('Set')
|
|
138
|
-
.and.have.lengthOf(0);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
[
|
|
143
|
-
{
|
|
144
|
-
inputType: 'HEADER',
|
|
145
|
-
exclusionType: 'HEADER',
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
inputType: 'QUERYSTRING',
|
|
149
|
-
exclusionType: 'PARAMETER',
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
inputType: 'BODY',
|
|
153
|
-
exclusionType: 'PARAMETER',
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
inputType: 'URL_PARAMETER',
|
|
157
|
-
exclusionType: 'PARAMETER',
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
inputType: 'COOKIE_VALUE',
|
|
161
|
-
exclusionType: 'COOKIE',
|
|
162
|
-
},
|
|
163
|
-
].forEach(({ inputType, exclusionType }) => {
|
|
164
|
-
it(`input exclusions can exclude specific rules (input: ${inputType}, exclusion:${exclusionType})`, function() {
|
|
165
|
-
core.messages.emit(Event.SERVER_SETTINGS_UPDATE, {
|
|
166
|
-
exclusions: {
|
|
167
|
-
input: [{
|
|
168
|
-
type: exclusionType,
|
|
169
|
-
urls: ['/exclude-some-inputs', '/exclude-some-inputs-.*'],
|
|
170
|
-
matchStrategy: 'ONLY',
|
|
171
|
-
assessmentRules: [],
|
|
172
|
-
assess_rules: [],
|
|
173
|
-
protect_rules: [],
|
|
174
|
-
modes: ['assess', 'defend'],
|
|
175
|
-
name: 'abc.*'
|
|
176
|
-
}]
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
const policy = getPolicy({ uriPath: '/exclude-some-inputs' });
|
|
181
|
-
let inputPolicy;
|
|
182
|
-
|
|
183
|
-
inputPolicy = policy.getInputPolicy(inputType, 'abcdef');
|
|
184
|
-
expect(inputPolicy).to.have.property('track', false);
|
|
185
|
-
expect(inputPolicy).not.to.have.property('excludedRules');
|
|
186
|
-
|
|
187
|
-
inputPolicy = policy.getInputPolicy(inputType, 'xyz');
|
|
188
|
-
expect(inputPolicy).to.have.property('track', true);
|
|
189
|
-
expect(inputPolicy).to.have.property('excludedRules')
|
|
190
|
-
.to.be.a('Set')
|
|
191
|
-
.and.have.lengthOf(0);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { Event } = require('@contrast/common');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
const sinon = require('sinon');
|
|
7
|
-
|
|
8
|
-
function execStoreAssertions(assessStore) {
|
|
9
|
-
expect(assessStore).to.be.an('object').and.deep.include({
|
|
10
|
-
reqData: {
|
|
11
|
-
ip: '127.0.0.1',
|
|
12
|
-
httpVersion: '1.1',
|
|
13
|
-
method: 'get',
|
|
14
|
-
headers: {
|
|
15
|
-
'content-type': 'text/html',
|
|
16
|
-
language: 'en',
|
|
17
|
-
referer: 'http://fake.url.foo',
|
|
18
|
-
},
|
|
19
|
-
uriPath: '/index',
|
|
20
|
-
queries: '_id=123',
|
|
21
|
-
contentType: 'text/html'
|
|
22
|
-
},
|
|
23
|
-
responseData: {},
|
|
24
|
-
sourceEventsCount: 0,
|
|
25
|
-
propagationEventsCount: 0,
|
|
26
|
-
});
|
|
27
|
-
expect(assessStore.policy.enabledRules).to.have.length.greaterThan(5);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe('assess getSourceContext', function () {
|
|
31
|
-
let core, simulateRequestScope;
|
|
32
|
-
|
|
33
|
-
beforeEach(function () {
|
|
34
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
describe('getPropagatorContext()', function() {
|
|
38
|
-
it('returns null when instrumentation is locked', function () {
|
|
39
|
-
sinon.stub(core.scopes.instrumentation, 'isLocked').returns(true);
|
|
40
|
-
|
|
41
|
-
simulateRequestScope(() => {
|
|
42
|
-
expect(core.assess.getPropagatorContext()).to.be.null;
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('returns null when not in request scope', function() {
|
|
47
|
-
expect(core.assess.getPropagatorContext()).to.be.null;
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('returns null when assess is disabled by policy', function() {
|
|
51
|
-
simulateRequestScope(() => {
|
|
52
|
-
expect(core.assess.getPropagatorContext()).to.be.null;
|
|
53
|
-
expect(core.logger.trace).to.have.been.calledWith('Assess intentionally disabled for this request');
|
|
54
|
-
}, { assess: { policy: undefined } });
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('returns assess store when max propagation event threshold is not met', function() {
|
|
58
|
-
simulateRequestScope(() => {
|
|
59
|
-
execStoreAssertions(core.assess.getPropagatorContext());
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('returns null when max propagation event threshold is exceeded', function() {
|
|
64
|
-
core.config.setValue('assess.max_propagation_events', 10);
|
|
65
|
-
|
|
66
|
-
simulateRequestScope(() => {
|
|
67
|
-
expect(core.assess.getPropagatorContext()).to.be.null;
|
|
68
|
-
}, { assess: { propagationEventsCount: 11 } });
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('getSinkContext()', function() {
|
|
73
|
-
it('returns null when instrumentation is locked', function () {
|
|
74
|
-
sinon.stub(core.scopes.instrumentation, 'isLocked').returns(true);
|
|
75
|
-
|
|
76
|
-
simulateRequestScope(() => {
|
|
77
|
-
expect(core.assess.getSinkContext()).to.be.null;
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('returns null when not in request scope', function() {
|
|
82
|
-
expect(core.assess.getSinkContext()).to.be.null;
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('returns null when assess is disabled by policy', function() {
|
|
86
|
-
simulateRequestScope(() => {
|
|
87
|
-
expect(core.assess.getSinkContext()).to.be.null;
|
|
88
|
-
expect(core.logger.trace).to.have.been.calledWith('Assess intentionally disabled for this request');
|
|
89
|
-
}, { assess: { policy: undefined } });
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('returns assess store when ruleId is not passed', function() {
|
|
93
|
-
simulateRequestScope(() => {
|
|
94
|
-
execStoreAssertions(core.assess.getSourceContext());
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('returns assess store when ruleId provided is enabled in the policy', function() {
|
|
99
|
-
simulateRequestScope(() => {
|
|
100
|
-
execStoreAssertions(core.assess.getSinkContext('reflected-xss'));
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('returns null when ruleId provided is not enabled in the policy', function() {
|
|
105
|
-
core.messages.emit(Event.SERVER_SETTINGS_UPDATE, {
|
|
106
|
-
assess: {
|
|
107
|
-
['reflected-xss']: { enable: false },
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
simulateRequestScope(() => {
|
|
112
|
-
expect(core.assess.getSinkContext('reflected-xss')).to.be.null;
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
describe('getSourceContext()', function() {
|
|
118
|
-
it('returns null when instrumentation is locked', function () {
|
|
119
|
-
sinon.stub(core.scopes.instrumentation, 'isLocked').returns(true);
|
|
120
|
-
|
|
121
|
-
simulateRequestScope(() => {
|
|
122
|
-
expect(core.assess.getSourceContext()).to.be.null;
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('returns null when not in request scope', function() {
|
|
127
|
-
expect(core.assess.getSourceContext()).to.be.null;
|
|
128
|
-
expect(core.logger.warn).to.have.been.calledWithMatch(
|
|
129
|
-
sinon.match.object,
|
|
130
|
-
'assess running outside of request scope',
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('returns null when assess is disabled by policy', function() {
|
|
135
|
-
simulateRequestScope(() => {
|
|
136
|
-
expect(core.assess.getSourceContext()).to.be.null;
|
|
137
|
-
expect(core.logger.trace).to.have.been.calledWith('Assess intentionally disabled for this request');
|
|
138
|
-
}, { assess: { policy: undefined } });
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('returns assess store when in request scope', function() {
|
|
142
|
-
simulateRequestScope(() => {
|
|
143
|
-
execStoreAssertions(core.assess.getSourceContext());
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('returns assess store when max source event threshold is not met', function() {
|
|
148
|
-
simulateRequestScope(() => {
|
|
149
|
-
execStoreAssertions(core.assess.getSourceContext());
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('returns null when max source event threshold is exceeded', function() {
|
|
154
|
-
core.config.setValue('assess.max_context_source_events', 10);
|
|
155
|
-
|
|
156
|
-
simulateRequestScope(() => {
|
|
157
|
-
expect(core.assess.getSourceContext()).to.be.null;
|
|
158
|
-
}, { assess: { sourceEventsCount: 11 } });
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
});
|