@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,171 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { InputType } = require('@contrast/common');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
|
|
8
|
-
describe('assess dataflow sources hapi', function () {
|
|
9
|
-
const hapi = {
|
|
10
|
-
server(server) {
|
|
11
|
-
return server;
|
|
12
|
-
},
|
|
13
|
-
Server(server) {
|
|
14
|
-
return server;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const reqMock = {
|
|
19
|
-
query: { q: 'value' },
|
|
20
|
-
path: '/uri/{id}',
|
|
21
|
-
state: { cookie: 'foo' },
|
|
22
|
-
payload: { foo: 'bar' },
|
|
23
|
-
params: { p: '1' },
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const hMock = {
|
|
27
|
-
continue: sinon.stub()
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
let core, sources, simulateRequestScope;
|
|
31
|
-
|
|
32
|
-
beforeEach(function () {
|
|
33
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
34
|
-
|
|
35
|
-
core.depHooks.resolve
|
|
36
|
-
.withArgs({ name: '@hapi/hapi', version: '>=18 <22' })
|
|
37
|
-
.yields(hapi);
|
|
38
|
-
|
|
39
|
-
sources = core.assess.dataflow.sources;
|
|
40
|
-
sinon.stub(sources, 'handle');
|
|
41
|
-
|
|
42
|
-
require('./hapi')(core).install();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
['server', 'Server'].forEach((server) => {
|
|
46
|
-
describe(`${server}`, function () {
|
|
47
|
-
|
|
48
|
-
['onRequest', 'onPostAuth'].forEach((ext) => {
|
|
49
|
-
it(`logs error when handle fails ${ext}`, function() {
|
|
50
|
-
simulateRequestScope(() => {
|
|
51
|
-
|
|
52
|
-
const err = new Error('Error');
|
|
53
|
-
const serverInstance = {
|
|
54
|
-
ext: sinon.stub(),
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
serverInstance.ext.withArgs(ext, sinon.match.func).callsFake((string, method) => {
|
|
58
|
-
method(reqMock, hMock);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
sources.handle.throws(err);
|
|
62
|
-
hapi[server](serverInstance);
|
|
63
|
-
|
|
64
|
-
expect(core.logger.error).to.have.been.calledWith({ err, inputType: sinon.match.string, funcKey: `assess-dataflow-source:hapi.${server}` }, 'unable to handle Hapi source');
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('does not call handle with tracked data onRequest', function() {
|
|
70
|
-
simulateRequestScope(() => {
|
|
71
|
-
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
72
|
-
sourceContext.parsedQuery = true;
|
|
73
|
-
sourceContext.parsedPath = true;
|
|
74
|
-
|
|
75
|
-
const serverInstance = {
|
|
76
|
-
ext: sinon.stub(),
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
serverInstance.ext.withArgs('onRequest', sinon.match.func).callsFake((string, method) => {
|
|
80
|
-
method(reqMock, hMock);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
hapi[server](serverInstance);
|
|
84
|
-
|
|
85
|
-
expect(sources.handle).to.not.have.been.called;
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('calls handle with request data onRequest', function () {
|
|
90
|
-
simulateRequestScope(() => {
|
|
91
|
-
const serverInstance = {
|
|
92
|
-
ext: sinon.stub(),
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
serverInstance.ext.withArgs('onRequest', sinon.match.func).callsFake((string, method) => {
|
|
96
|
-
method(reqMock, hMock);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
hapi[server](serverInstance);
|
|
100
|
-
|
|
101
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
102
|
-
context: 'req.query',
|
|
103
|
-
data: reqMock.query,
|
|
104
|
-
inputType: InputType.QUERYSTRING,
|
|
105
|
-
name: 'hapi.onRequest',
|
|
106
|
-
});
|
|
107
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
108
|
-
context: 'req.path',
|
|
109
|
-
data: reqMock.path,
|
|
110
|
-
inputType: InputType.URI,
|
|
111
|
-
name: 'hapi.onRequest',
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('does not call handle with tracked data onPostAuth', function() {
|
|
117
|
-
simulateRequestScope(() => {
|
|
118
|
-
const sourceContext = core.scopes.sources.getStore()?.assess;
|
|
119
|
-
sourceContext.parsedCookies = true;
|
|
120
|
-
sourceContext.parsedBody = true;
|
|
121
|
-
sourceContext.parsedParams = true;
|
|
122
|
-
|
|
123
|
-
const serverInstance = {
|
|
124
|
-
ext: sinon.stub(),
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
serverInstance.ext.withArgs('onPostAuth', sinon.match.func).callsFake((string, method) => {
|
|
128
|
-
method(reqMock, hMock);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
hapi[server](serverInstance);
|
|
132
|
-
|
|
133
|
-
expect(sources.handle).to.not.have.been.called;
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('calls handle with request data onPostAuth', function () {
|
|
138
|
-
simulateRequestScope(() => {
|
|
139
|
-
const serverInstance = {
|
|
140
|
-
ext: sinon.stub(),
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
serverInstance.ext.withArgs('onPostAuth', sinon.match.func).callsFake((string, method) => {
|
|
144
|
-
method(reqMock, hMock);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
hapi[server](serverInstance);
|
|
148
|
-
|
|
149
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
150
|
-
context: 'req.state',
|
|
151
|
-
data: reqMock.state,
|
|
152
|
-
inputType: InputType.COOKIE_VALUE,
|
|
153
|
-
name: 'hapi.onPostAuth',
|
|
154
|
-
});
|
|
155
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
156
|
-
context: 'req.payload',
|
|
157
|
-
data: reqMock.payload,
|
|
158
|
-
inputType: InputType.BODY,
|
|
159
|
-
name: 'hapi.onPostAuth',
|
|
160
|
-
});
|
|
161
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
162
|
-
context: 'req.params',
|
|
163
|
-
data: reqMock.params,
|
|
164
|
-
inputType: InputType.URL_PARAMETER,
|
|
165
|
-
name: 'hapi.onPostAuth',
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const proxyquire = require('proxyquire');
|
|
5
|
-
const mocks = require('@contrast/test/mocks');
|
|
6
|
-
|
|
7
|
-
const moduleMock = (moduleName, mock) => (deps) => {
|
|
8
|
-
deps.assess.dataflow.sources.hapiInstrumentation[moduleName] = mock[moduleName];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
describe('assess dataflow sources Hapi', function () {
|
|
12
|
-
let core, hapiSourcesMock, hapiSourcesModule, modulesWithInstall;
|
|
13
|
-
|
|
14
|
-
beforeEach(function () {
|
|
15
|
-
core = mocks.core();
|
|
16
|
-
core.assess = mocks.assess();
|
|
17
|
-
hapiSourcesMock = core.assess.dataflow.sources.hapiInstrumentation;
|
|
18
|
-
hapiSourcesModule = proxyquire('.', {
|
|
19
|
-
'./hapi': moduleMock('hapi', hapiSourcesMock)
|
|
20
|
-
});
|
|
21
|
-
modulesWithInstall = [
|
|
22
|
-
'hapi'
|
|
23
|
-
];
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('installs the components', function () {
|
|
27
|
-
hapiSourcesModule(core).install();
|
|
28
|
-
|
|
29
|
-
modulesWithInstall.forEach((module) => {
|
|
30
|
-
expect(hapiSourcesMock[module].install).to.have.been.calledOnce;
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const EventEmitter = require('events');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const { expect } = require('chai');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
const mocks = require('@contrast/test/mocks');
|
|
8
|
-
|
|
9
|
-
describe('assess dataflow sources http', function () {
|
|
10
|
-
let core, simulateRequestScope, request, response, server;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
14
|
-
|
|
15
|
-
request = mocks.incomingMessage();
|
|
16
|
-
response = mocks.serverResponse();
|
|
17
|
-
|
|
18
|
-
class Server extends EventEmitter { }
|
|
19
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'http' })).yields({ Server });
|
|
20
|
-
core.logger.child = () => core.logger;
|
|
21
|
-
|
|
22
|
-
require('./http')(core).install();
|
|
23
|
-
server = new Server();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('instantiates assess store with appropriate metadata and handles base sources', function (next) {
|
|
27
|
-
simulateRequestScope(() => {
|
|
28
|
-
core.scopes.sources.getStore().assess.req;
|
|
29
|
-
server.on('request', test);
|
|
30
|
-
server.emit('request', request, response);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
function test(req, res) {
|
|
34
|
-
const store = core.scopes.sources.getStore()?.assess;
|
|
35
|
-
// validate store
|
|
36
|
-
expect(store).to.have.property('propagationEventsCount', 0);
|
|
37
|
-
// url(1), headers(3), rawHeaders(3)
|
|
38
|
-
expect(store).to.have.property('sourceEventsCount', 7);
|
|
39
|
-
expect(store.policy.enabledRules).to.be.a('Set').and.length.greaterThan(5);
|
|
40
|
-
// should match the mock
|
|
41
|
-
expect(store.reqData).to.deep.equal({
|
|
42
|
-
ip: '127.0.0.1',
|
|
43
|
-
httpVersion: '1.1',
|
|
44
|
-
method: 'get',
|
|
45
|
-
headers: {
|
|
46
|
-
'content-type': 'text/html',
|
|
47
|
-
language: 'en',
|
|
48
|
-
referer: 'http://fake.url.foo'
|
|
49
|
-
},
|
|
50
|
-
uriPath: '/index',
|
|
51
|
-
queries: '_id=123',
|
|
52
|
-
contentType: 'text/html'
|
|
53
|
-
});
|
|
54
|
-
expect(store.responseData).to.deep.equal({});
|
|
55
|
-
// tracked inputs
|
|
56
|
-
expect(core.assess.dataflow.tracker.getData(request.url)).to.be.ok;
|
|
57
|
-
expect(core.assess.dataflow.tracker.getData(request.headers['content-type'])).to.be.ok;
|
|
58
|
-
// patched methods
|
|
59
|
-
expect(core.patcher.isContrastHooked(res.writeHead)).to.be.true;
|
|
60
|
-
expect(core.patcher.isContrastHooked(res.setHeader)).to.be.true;
|
|
61
|
-
response.writeHead(200, { 'content-type': 'application/json' });
|
|
62
|
-
expect(store.responseData).to.deep.equal({ contentType: 'application/json' });
|
|
63
|
-
response.setHeader('content-type', 'text/html');
|
|
64
|
-
expect(store.responseData).to.deep.equal({ contentType: 'text/html' });
|
|
65
|
-
response.writeHead(); // instrumentation is noop
|
|
66
|
-
expect(store.responseData).to.deep.equal({ contentType: 'text/html' });
|
|
67
|
-
next();
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('noop if server event is not type \'request\'', function (next) {
|
|
72
|
-
simulateRequestScope(() => {
|
|
73
|
-
server.on('foo', test);
|
|
74
|
-
server.emit('foo', request, response);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
function test(req, res) {
|
|
78
|
-
const store = core.scopes.sources.getStore()?.assess;
|
|
79
|
-
// // validate store
|
|
80
|
-
expect(store).to.have.property('propagationEventsCount', 0);
|
|
81
|
-
expect(store).to.have.property('sourceEventsCount', 0);
|
|
82
|
-
expect(store.policy.enabledRules).to.be.a('Set').and.length.greaterThan(5);
|
|
83
|
-
// // tracked inputs
|
|
84
|
-
expect(core.assess.dataflow.tracker.getData(request.url)).to.be.null;
|
|
85
|
-
expect(core.assess.dataflow.tracker.getData(request.headers['content-type'])).to.be.null;
|
|
86
|
-
// // patched methods
|
|
87
|
-
expect(core.patcher.isContrastHooked(res.writeHead)).to.be.false;
|
|
88
|
-
expect(core.patcher.isContrastHooked(res.setHeader)).to.be.false;
|
|
89
|
-
next();
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('logs debug message if there is no async request store', function (next) {
|
|
94
|
-
server.on('request', test);
|
|
95
|
-
server.emit('request', request, response);
|
|
96
|
-
|
|
97
|
-
function test(req, res) {
|
|
98
|
-
const store = core.scopes.sources.getStore()?.assess;
|
|
99
|
-
// validate store
|
|
100
|
-
expect(store).to.be.undefined;
|
|
101
|
-
// tracked inputs
|
|
102
|
-
expect(core.assess.dataflow.tracker.getData(request.url)).to.be.null;
|
|
103
|
-
expect(core.assess.dataflow.tracker.getData(request.headers['content-type'])).to.be.null;
|
|
104
|
-
// patched methods
|
|
105
|
-
expect(core.patcher.isContrastHooked(res.writeHead)).to.be.false;
|
|
106
|
-
expect(core.patcher.isContrastHooked(res.setHeader)).to.be.false;
|
|
107
|
-
next();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('handles a case with an error in the `.handle` method', function (next) {
|
|
112
|
-
const err = new Error('test');
|
|
113
|
-
core.assess.dataflow.sources.handle = sinon.stub().throws(err);
|
|
114
|
-
|
|
115
|
-
simulateRequestScope(() => {
|
|
116
|
-
server.on('request', test);
|
|
117
|
-
server.emit('request', request, response);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
function test(req, res) {
|
|
121
|
-
const store = core.scopes.sources.getStore()?.assess;
|
|
122
|
-
// validate store
|
|
123
|
-
expect(store).to.have.property('propagationEventsCount', 0);
|
|
124
|
-
expect(store).to.have.property('sourceEventsCount', 0);
|
|
125
|
-
expect(store.policy.enabledRules).to.be.a('Set').and.length.greaterThan(5);
|
|
126
|
-
expect(store.reqData).to.deep.equal({
|
|
127
|
-
ip: '127.0.0.1',
|
|
128
|
-
httpVersion: '1.1',
|
|
129
|
-
method: 'get',
|
|
130
|
-
headers: {
|
|
131
|
-
'content-type': 'text/html',
|
|
132
|
-
language: 'en',
|
|
133
|
-
referer: 'http://fake.url.foo'
|
|
134
|
-
},
|
|
135
|
-
uriPath: '/index',
|
|
136
|
-
queries: '_id=123',
|
|
137
|
-
contentType: 'text/html'
|
|
138
|
-
});
|
|
139
|
-
expect(store.responseData).to.deep.equal({});
|
|
140
|
-
// tracked inputs
|
|
141
|
-
expect(core.assess.dataflow.tracker.getData(request.url)).to.be.null;
|
|
142
|
-
expect(core.assess.dataflow.tracker.getData(request.headers['content-type'])).to.be.null;
|
|
143
|
-
// patched methods
|
|
144
|
-
expect(core.patcher.isContrastHooked(res.writeHead)).to.be.true;
|
|
145
|
-
expect(core.patcher.isContrastHooked(res.setHeader)).to.be.true;
|
|
146
|
-
next();
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const proxyquire = require('proxyquire');
|
|
5
|
-
const mocks = require('@contrast/test/mocks');
|
|
6
|
-
|
|
7
|
-
const moduleMock = (moduleName, mock) => (deps) => {
|
|
8
|
-
deps.assess.dataflow.sources.koaInstrumentation[moduleName] = mock[moduleName];
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
describe('assess dataflow sources koa', function () {
|
|
12
|
-
let core, koaSourcesMock, koaSourcesModule, modulesWithInstall;
|
|
13
|
-
|
|
14
|
-
beforeEach(function () {
|
|
15
|
-
core = mocks.core();
|
|
16
|
-
core.assess = mocks.assess();
|
|
17
|
-
koaSourcesMock = core.assess.dataflow.sources.koaInstrumentation;
|
|
18
|
-
koaSourcesModule = proxyquire('.', {
|
|
19
|
-
'./koa2': moduleMock('koa2', koaSourcesMock),
|
|
20
|
-
'./koa-bodyparsers': moduleMock('koaBodyparsers', koaSourcesMock),
|
|
21
|
-
'./koa-multer': moduleMock('koaMulter', koaSourcesMock),
|
|
22
|
-
'./koa-routers': moduleMock('koaRouters', koaSourcesMock),
|
|
23
|
-
});
|
|
24
|
-
modulesWithInstall = [
|
|
25
|
-
'koa2',
|
|
26
|
-
'koaBodyparsers',
|
|
27
|
-
'koaMulter',
|
|
28
|
-
'koaRouters',
|
|
29
|
-
];
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('installs the components', function () {
|
|
33
|
-
koaSourcesModule(core).install();
|
|
34
|
-
|
|
35
|
-
modulesWithInstall.forEach((module) => {
|
|
36
|
-
expect(koaSourcesMock[module].install).to.have.been.calledOnce;
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
const { InputType } = require('@contrast/common');
|
|
7
|
-
const koaBodyInstr = require('./koa-bodyparsers');
|
|
8
|
-
|
|
9
|
-
describe('assess dataflow sources koa-body v5.x.x and koa-bodyparser v4.x.x', function () {
|
|
10
|
-
let core, simulateRequestScope, koaBodyparserMock, patchedKoaBodyparser, body, sources, nextStub;
|
|
11
|
-
|
|
12
|
-
beforeEach(function () {
|
|
13
|
-
({ core, simulateRequestScope } = initAssessFixture());
|
|
14
|
-
|
|
15
|
-
sources = core.assess.dataflow.sources;
|
|
16
|
-
sinon.spy(sources, 'handle');
|
|
17
|
-
|
|
18
|
-
body = { parameter: 'parsed' };
|
|
19
|
-
|
|
20
|
-
koaBodyparserMock = (body) => (ctx, next) => {
|
|
21
|
-
ctx.request.body = body;
|
|
22
|
-
next();
|
|
23
|
-
};
|
|
24
|
-
nextStub = sinon.stub();
|
|
25
|
-
sinon.spy(core.patcher, 'patch');
|
|
26
|
-
|
|
27
|
-
koaBodyInstr(core).install();
|
|
28
|
-
patchedKoaBodyparser = core.depHooks.resolve.yield(koaBodyparserMock)[0];
|
|
29
|
-
core.patcher.patch.resetHistory();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('calls patcher on the `koa-body` and `koa-bodyparser` module exports', function () {
|
|
33
|
-
core.depHooks.resolve.yield(koaBodyparserMock);
|
|
34
|
-
|
|
35
|
-
expect(core.patcher.patch).to.have.been.calledTwice;
|
|
36
|
-
expect(core.patcher.patch).to.have.been.calledWithMatch(koaBodyparserMock, {
|
|
37
|
-
name: 'koa-body',
|
|
38
|
-
patchType: 'assess-dataflow-source',
|
|
39
|
-
post: sinon.match.func
|
|
40
|
-
});
|
|
41
|
-
expect(core.patcher.patch).to.have.been.calledWithMatch(koaBodyparserMock, {
|
|
42
|
-
name: 'koa-bodyparser',
|
|
43
|
-
patchType: 'assess-dataflow-source',
|
|
44
|
-
post: sinon.match.func
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('calls `.handle` when parsing body is successful and in right context', function () {
|
|
49
|
-
let scCall1, scCall2, scCall3;
|
|
50
|
-
|
|
51
|
-
simulateRequestScope(() => {
|
|
52
|
-
const bParser = patchedKoaBodyparser(body);
|
|
53
|
-
bParser({ request: { body: {} } }, nextStub);
|
|
54
|
-
|
|
55
|
-
scCall1 = core.scopes.sources.getStore()?.assess;
|
|
56
|
-
});
|
|
57
|
-
simulateRequestScope(() => {
|
|
58
|
-
scCall2 = core.scopes.sources.getStore()?.assess;
|
|
59
|
-
scCall2.reqData.headers = {
|
|
60
|
-
'content-type': 'application/json'
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const bParser = patchedKoaBodyparser(body);
|
|
64
|
-
bParser({ request: {} }, nextStub);
|
|
65
|
-
});
|
|
66
|
-
simulateRequestScope(() => {
|
|
67
|
-
const bParser = patchedKoaBodyparser('non-object-body');
|
|
68
|
-
bParser({ request: {} }, nextStub);
|
|
69
|
-
|
|
70
|
-
scCall3 = core.scopes.sources.getStore()?.assess;
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
expect(core.patcher.patch).to.have.been.calledThrice;
|
|
75
|
-
expect(core.patcher.patch).to.have.been.calledWithMatch(sinon.match.func, {
|
|
76
|
-
name: 'koa-body',
|
|
77
|
-
patchType: 'assess-dataflow-source',
|
|
78
|
-
pre: sinon.match.func
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(nextStub).to.have.been.calledThrice;
|
|
82
|
-
expect(sources.handle).to.have.been.calledThrice;
|
|
83
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
84
|
-
context: 'ctx.request.body',
|
|
85
|
-
name: 'koa-body',
|
|
86
|
-
stacktraceOpts: {
|
|
87
|
-
constructorOpt: sinon.match.func,
|
|
88
|
-
},
|
|
89
|
-
inputType: InputType.PARAMETER_VALUE,
|
|
90
|
-
data: { parameter: 'parsed' },
|
|
91
|
-
sourceContext: scCall1
|
|
92
|
-
});
|
|
93
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
94
|
-
context: 'ctx.request.body',
|
|
95
|
-
name: 'koa-body',
|
|
96
|
-
stacktraceOpts: {
|
|
97
|
-
constructorOpt: sinon.match.func,
|
|
98
|
-
},
|
|
99
|
-
inputType: InputType.JSON_VALUE,
|
|
100
|
-
data: { parameter: 'parsed' },
|
|
101
|
-
sourceContext: scCall2
|
|
102
|
-
});
|
|
103
|
-
expect(sources.handle).to.have.been.calledWithMatch({
|
|
104
|
-
context: 'ctx.request.body',
|
|
105
|
-
name: 'koa-body',
|
|
106
|
-
stacktraceOpts: {
|
|
107
|
-
constructorOpt: sinon.match.func,
|
|
108
|
-
},
|
|
109
|
-
inputType: InputType.BODY,
|
|
110
|
-
data: 'non-object-body',
|
|
111
|
-
sourceContext: scCall3
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('does not call `.handle` when there is no assess policy in request context', function () {
|
|
116
|
-
simulateRequestScope(() => {
|
|
117
|
-
const cParser = patchedKoaBodyparser(body);
|
|
118
|
-
cParser({ request: {} }, nextStub);
|
|
119
|
-
}, { assess: { policy: null } });
|
|
120
|
-
|
|
121
|
-
expect(sources.handle).not.to.have.been.called;
|
|
122
|
-
expect(nextStub).to.have.been.calledOnce;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('does not call `.handle` when the values are already tracked', function () {
|
|
126
|
-
simulateRequestScope(() => {
|
|
127
|
-
core.scopes.sources.getStore().assess.parsedBody = true;
|
|
128
|
-
|
|
129
|
-
const cParser = patchedKoaBodyparser(body);
|
|
130
|
-
cParser({ request: {} }, nextStub);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(sources.handle).not.to.have.been.called;
|
|
134
|
-
expect(core.logger.trace).to.have.been.calledWith(
|
|
135
|
-
{ funcKey: 'assess-dataflow-source:koa-body' },
|
|
136
|
-
'values already tracked',
|
|
137
|
-
);
|
|
138
|
-
expect(nextStub).to.have.been.calledOnce;
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('handles a case with an error in the `.handle` method', function () {
|
|
142
|
-
const err = new Error('test');
|
|
143
|
-
|
|
144
|
-
core.assess.dataflow.sources.handle = () => {
|
|
145
|
-
throw err;
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
simulateRequestScope(() => {
|
|
149
|
-
const cParser = patchedKoaBodyparser(body);
|
|
150
|
-
cParser({ request: {} }, nextStub);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
expect(core.logger.error).to.have.been.calledWith(
|
|
154
|
-
{ err, inputType: InputType.PARAMETER_VALUE, funcKey: 'assess-dataflow-source:koa-body' },
|
|
155
|
-
'unable to handle Koa source',
|
|
156
|
-
);
|
|
157
|
-
expect(nextStub).to.have.been.calledOnce;
|
|
158
|
-
expect(nextStub).not.to.have.been.calledWith(err);
|
|
159
|
-
});
|
|
160
|
-
});
|