@contrast/assess 1.46.1 → 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,130 +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
|
-
const ruleId = 'unvalidated-redirect';
|
|
14
|
-
|
|
15
|
-
describe('assess dataflow sinks hapi unvalidated-redirect', function () {
|
|
16
|
-
let core, simulateRequestScope, trackString, tracker, reportFindings, reportSafePositive;
|
|
17
|
-
|
|
18
|
-
class Response {
|
|
19
|
-
redirect() { }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
beforeEach(function () {
|
|
23
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
24
|
-
tracker = core.assess.dataflow.tracker;
|
|
25
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
26
|
-
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
27
|
-
|
|
28
|
-
core.depHooks.resolve.yields(Response);
|
|
29
|
-
|
|
30
|
-
require('./unvalidated-redirect')(core).install();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('skips instrumentation if there is no assess store', function () {
|
|
34
|
-
Response.prototype.redirect('hello');
|
|
35
|
-
expect(reportFindings).to.not.have.been.called;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('skips instrumentation if url does not exist', function () {
|
|
39
|
-
simulateRequestScope(function () {
|
|
40
|
-
Response.prototype.redirect();
|
|
41
|
-
expect(reportFindings).to.not.have.been.called;
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('skip sinstrumentation if url is not string', function () {
|
|
46
|
-
simulateRequestScope(function () {
|
|
47
|
-
Response.prototype.redirect(1, 2);
|
|
48
|
-
expect(reportFindings).to.not.have.been.called;
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('skips instrumentation if url is not tracked', function () {
|
|
53
|
-
simulateRequestScope(function () {
|
|
54
|
-
Response.prototype.redirect('url');
|
|
55
|
-
expect(reportFindings).to.not.have.been.called;
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('reports a "safe positive" event when safe tags overlap UNTRUSTED', function () {
|
|
60
|
-
simulateRequestScope(function () {
|
|
61
|
-
const value = 'https%3A%2F%2Fhello.com';
|
|
62
|
-
const stop = value.length - 1;
|
|
63
|
-
const extern = trackString(value, {
|
|
64
|
-
tags: {
|
|
65
|
-
[URL_ENCODED]: [0, stop],
|
|
66
|
-
[UNTRUSTED]: [0, stop],
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
Response.prototype.redirect(extern);
|
|
71
|
-
|
|
72
|
-
expect(reportSafePositive).to.have.been.calledWithMatch({
|
|
73
|
-
name: 'hapi.Response.prototype.redirect',
|
|
74
|
-
ruleId,
|
|
75
|
-
safeTags: [URL_ENCODED],
|
|
76
|
-
strInfo: {
|
|
77
|
-
tags: { [URL_ENCODED]: [0, stop], [UNTRUSTED]: [0, stop] },
|
|
78
|
-
value
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('reports an unvalidated-redirect', function () {
|
|
85
|
-
simulateRequestScope(function () {
|
|
86
|
-
const value = 'https://hello.com/query?test=value';
|
|
87
|
-
const extern = trackString(value, {
|
|
88
|
-
tags: {
|
|
89
|
-
[URL_ENCODED]: [0, 2],
|
|
90
|
-
[UNTRUSTED]: [0, 16],
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
Response.prototype.redirect(extern);
|
|
95
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
96
|
-
ruleId,
|
|
97
|
-
sinkEvent: {
|
|
98
|
-
args: [{ value, tracked: true }],
|
|
99
|
-
context: 'response.redirect(\'https://hello.com/query?test=value\')',
|
|
100
|
-
name: 'hapi.Response.prototype.redirect',
|
|
101
|
-
moduleName: 'hapi',
|
|
102
|
-
methodName: 'Response.prototype.redirect',
|
|
103
|
-
object: {
|
|
104
|
-
value: 'hapi.Response',
|
|
105
|
-
tracked: false,
|
|
106
|
-
},
|
|
107
|
-
result: { value: undefined, tracked: false },
|
|
108
|
-
source: 'P0',
|
|
109
|
-
tags: { [URL_ENCODED]: [0, 2], [UNTRUSTED]: [0, 16] },
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('does not report an unvalidated-redirect if the tainted data is not in the URI path', function () {
|
|
116
|
-
simulateRequestScope(function () {
|
|
117
|
-
const url = 'https://hello.com/query?test=value';
|
|
118
|
-
const str = trackString(url, {
|
|
119
|
-
tags: {
|
|
120
|
-
[URL_ENCODED]: [0, 2],
|
|
121
|
-
[UNTRUSTED]: [24, 33],
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
const { extern } = tracker.getData(str);
|
|
125
|
-
|
|
126
|
-
Response.prototype.redirect(extern);
|
|
127
|
-
expect(reportFindings).to.not.have.been.called;
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|
|
@@ -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 = ['request', 'serverResponse'];
|
|
9
|
-
|
|
10
|
-
describe('assess dataflow sinks http', function () {
|
|
11
|
-
let core, http;
|
|
12
|
-
|
|
13
|
-
beforeEach(function () {
|
|
14
|
-
core = mocks.core();
|
|
15
|
-
core.assess = { dataflow: { sinks: {} } };
|
|
16
|
-
|
|
17
|
-
const moduleMock = (name) => (deps) => {
|
|
18
|
-
deps.assess.dataflow.sinks.http[name] = { install: sinon.stub() };
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
http = proxyquire('.', {
|
|
22
|
-
'./request': moduleMock('request'),
|
|
23
|
-
'./server-response': moduleMock('serverResponse'),
|
|
24
|
-
})(core);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('installs its components', function () {
|
|
28
|
-
http.install();
|
|
29
|
-
MODULES.forEach((module) => {
|
|
30
|
-
expect(http[module].install).to.have.been.calledOnce;
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const {
|
|
6
|
-
DataflowTag: {
|
|
7
|
-
UNTRUSTED,
|
|
8
|
-
LIMITED_CHARS
|
|
9
|
-
},
|
|
10
|
-
primordials: { UtilInspect }
|
|
11
|
-
} = require('@contrast/common');
|
|
12
|
-
|
|
13
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
14
|
-
|
|
15
|
-
const modules = {
|
|
16
|
-
http: {
|
|
17
|
-
request() { }
|
|
18
|
-
},
|
|
19
|
-
https: {
|
|
20
|
-
request() { }
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getReq = function (strOrObj, key, trackedString) {
|
|
25
|
-
if (strOrObj === 'str') {
|
|
26
|
-
if (key === 'protocol') {
|
|
27
|
-
return trackedString.concat('://foo.com');
|
|
28
|
-
} else {
|
|
29
|
-
return 'http://'.concat(trackedString).concat('.com');
|
|
30
|
-
}
|
|
31
|
-
} else {
|
|
32
|
-
const req = {};
|
|
33
|
-
req[key] = trackedString;
|
|
34
|
-
return req;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
['http', 'https'].forEach((module) => {
|
|
39
|
-
describe(`assess dataflow sinks ${module}.request`, function () {
|
|
40
|
-
let core, simulateRequestScope, trackString, reportFindings;
|
|
41
|
-
|
|
42
|
-
beforeEach(function () {
|
|
43
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
44
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
45
|
-
|
|
46
|
-
core.assess.dataflow.propagation.stringInstrumentation.concat.install();
|
|
47
|
-
core.assess.dataflow.propagation.stringInstrumentation.substring.install();
|
|
48
|
-
core.assess.dataflow.propagation.stringInstrumentation.split.install();
|
|
49
|
-
core.assess.dataflow.propagation.urlInstrumentation.url.install();
|
|
50
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'url' })).yield(require('url'));
|
|
51
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: module })).yields(modules[module]);
|
|
52
|
-
|
|
53
|
-
require('./request')(core).install();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
57
|
-
modules[module].request({
|
|
58
|
-
protocol: `${module}:`,
|
|
59
|
-
hostname: 'foo',
|
|
60
|
-
});
|
|
61
|
-
expect(reportFindings).to.not.have.been.called;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('skips instrumentation if payload is missing', function () {
|
|
65
|
-
simulateRequestScope(function () {
|
|
66
|
-
modules[module].request();
|
|
67
|
-
expect(reportFindings).to.not.have.been.called;
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('skips instrumentation if the string is not tracked', function () {
|
|
72
|
-
simulateRequestScope(function () {
|
|
73
|
-
modules[module].request({
|
|
74
|
-
protocol: `${module}:`,
|
|
75
|
-
hostname: 'foo',
|
|
76
|
-
});
|
|
77
|
-
expect(reportFindings).to.not.have.been.called;
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('skips instrumentation if the string is safe', function () {
|
|
82
|
-
simulateRequestScope(function() {
|
|
83
|
-
const extern = trackString('foo', {
|
|
84
|
-
tags: {
|
|
85
|
-
[UNTRUSTED]: [0, 2],
|
|
86
|
-
[LIMITED_CHARS]: [0, 2],
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
modules[module].request({
|
|
91
|
-
protocol: `${module}:`,
|
|
92
|
-
hostname: extern,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
expect(reportFindings).to.not.have.been.called;
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('skips instrumentation if stack contains trusted lib', function () {
|
|
100
|
-
simulateRequestScope(function() {
|
|
101
|
-
const extern = trackString('foo', {
|
|
102
|
-
tags: {
|
|
103
|
-
[UNTRUSTED]: [0, 2],
|
|
104
|
-
},
|
|
105
|
-
stack: [
|
|
106
|
-
{ file: 'path/http/file.js' }
|
|
107
|
-
]
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
modules[module].request({
|
|
111
|
-
protocol: `${module}:`,
|
|
112
|
-
hostname: extern,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
expect(reportFindings).to.not.have.been.called;
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
describe('request obj', function () {
|
|
120
|
-
['protocol', 'host', 'localAddress', 'hostname'].forEach((key) => {
|
|
121
|
-
it(`reports a ssrf vulnerability when ${key} is tainted`, function () {
|
|
122
|
-
simulateRequestScope(function() {
|
|
123
|
-
const value = 'foo';
|
|
124
|
-
const extern = trackString('foo');
|
|
125
|
-
|
|
126
|
-
const req = getReq('obj', key, extern);
|
|
127
|
-
modules[module].request(req);
|
|
128
|
-
|
|
129
|
-
const strReq = UtilInspect(req);
|
|
130
|
-
const startIdx = strReq.indexOf(value);
|
|
131
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
132
|
-
ruleId: 'ssrf',
|
|
133
|
-
sinkEvent: {
|
|
134
|
-
name: `${module}.request`,
|
|
135
|
-
moduleName: module,
|
|
136
|
-
methodName: 'request',
|
|
137
|
-
context: `${module}.request(${strReq})`,
|
|
138
|
-
object: {
|
|
139
|
-
value: module,
|
|
140
|
-
tracked: false,
|
|
141
|
-
},
|
|
142
|
-
args: [{ value: strReq, tracked: true }],
|
|
143
|
-
tags: { [UNTRUSTED]: [startIdx, startIdx + value.length - 1] },
|
|
144
|
-
source: 'P0',
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('request string', function () {
|
|
153
|
-
['protocol', 'host', 'hostname'].forEach((key) => {
|
|
154
|
-
it(`reports a ssrf vulnerability when ${key} is tainted`, function () {
|
|
155
|
-
simulateRequestScope(function() {
|
|
156
|
-
const value = 'foo';
|
|
157
|
-
const extern = trackString(value);
|
|
158
|
-
|
|
159
|
-
const req = getReq('str', key, extern);
|
|
160
|
-
modules[module].request(req);
|
|
161
|
-
const startIdx = req.indexOf(value);
|
|
162
|
-
|
|
163
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
164
|
-
ruleId: 'ssrf',
|
|
165
|
-
sinkEvent: {
|
|
166
|
-
name: `${module}.request`,
|
|
167
|
-
moduleName: module,
|
|
168
|
-
methodName: 'request',
|
|
169
|
-
context: `${module}.request(${req})`,
|
|
170
|
-
object: {
|
|
171
|
-
value: module,
|
|
172
|
-
tracked: false,
|
|
173
|
-
},
|
|
174
|
-
args: [{ value: req, tracked: true }],
|
|
175
|
-
tags: { [UNTRUSTED]: [startIdx, startIdx + value.length - 1] },
|
|
176
|
-
source: 'P0',
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const {
|
|
6
|
-
DataflowTag: {
|
|
7
|
-
UNTRUSTED,
|
|
8
|
-
LIMITED_CHARS,
|
|
9
|
-
}
|
|
10
|
-
} = require('@contrast/common');
|
|
11
|
-
|
|
12
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
13
|
-
|
|
14
|
-
describe('assess dataflow sinks http, http2, spdy', function () {
|
|
15
|
-
let core, simulateRequestScope, trackString, tracker, reportFindings, reportSafePositive;
|
|
16
|
-
|
|
17
|
-
class ServerResponse {
|
|
18
|
-
end() { }
|
|
19
|
-
write() { }
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class Http2ServerResponse {
|
|
23
|
-
end() { }
|
|
24
|
-
write() { }
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const response = {
|
|
28
|
-
end: sinon.stub(),
|
|
29
|
-
spdyStream: {
|
|
30
|
-
once: sinon.stub()
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
beforeEach(function () {
|
|
34
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
35
|
-
tracker = core.assess.dataflow.tracker;
|
|
36
|
-
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
37
|
-
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
38
|
-
|
|
39
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'http' })).yields({ ServerResponse });
|
|
40
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'http2' })).yields({ Http2ServerResponse });
|
|
41
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'spdy' })).yields(response);
|
|
42
|
-
|
|
43
|
-
require('./server-response')(core).install();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
[
|
|
47
|
-
{ moduleName: 'http', response: ServerResponse.prototype, responseName: 'ServerResponse' },
|
|
48
|
-
{ moduleName: 'http2', response: Http2ServerResponse.prototype, responseName: 'Http2ServerResponse' },
|
|
49
|
-
{ moduleName: 'spdy', response, responseName: 'response' },
|
|
50
|
-
].forEach(({ moduleName, response, responseName }) => {
|
|
51
|
-
describe(moduleName, function() {
|
|
52
|
-
['end', 'write'].forEach((method) => {
|
|
53
|
-
if (moduleName === 'spdy' && method === 'write') return;
|
|
54
|
-
const methodName = `${responseName + (moduleName !== 'spdy' ? '.prototype' : '')}.${method}`;
|
|
55
|
-
describe(method, function() {
|
|
56
|
-
it('skips instrumentation if assess store is missing', function () {
|
|
57
|
-
response[method]('hello world');
|
|
58
|
-
expect(reportFindings).to.not.have.been.called;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('skips instrumentation if payload is missing', function () {
|
|
62
|
-
simulateRequestScope(function () {
|
|
63
|
-
response[method]();
|
|
64
|
-
expect(reportFindings).to.not.have.been.called;
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('skips instrumentation if the string is not tracked', function () {
|
|
69
|
-
simulateRequestScope(function () {
|
|
70
|
-
response[method]('hello world');
|
|
71
|
-
expect(reportFindings).to.not.have.been.called;
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('skips instrumentation if the content-type is safe', function () {
|
|
76
|
-
simulateRequestScope(function () {
|
|
77
|
-
core.scopes.sources.getStore().assess.responseData.contentType = 'application/json';
|
|
78
|
-
|
|
79
|
-
const str = trackString('hello world');
|
|
80
|
-
const { extern } = tracker.getData(str);
|
|
81
|
-
|
|
82
|
-
response[method](extern);
|
|
83
|
-
expect(reportFindings).to.not.have.been.called;
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('skips instrumentation if the string is safe', function () {
|
|
88
|
-
simulateRequestScope(function () {
|
|
89
|
-
const extern = trackString('hello world', {
|
|
90
|
-
tags: {
|
|
91
|
-
[UNTRUSTED]: [0, 10],
|
|
92
|
-
[LIMITED_CHARS]: [0, 10],
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
response[method](extern);
|
|
97
|
-
|
|
98
|
-
expect(reportFindings).to.not.have.been.called;
|
|
99
|
-
expect(reportSafePositive).to.have.been.called;
|
|
100
|
-
|
|
101
|
-
expect(reportSafePositive).to.have.been.calledWith({
|
|
102
|
-
name: `${moduleName}.${methodName}`,
|
|
103
|
-
ruleId: 'reflected-xss',
|
|
104
|
-
safeTags: [LIMITED_CHARS],
|
|
105
|
-
strInfo: {
|
|
106
|
-
value: 'hello world',
|
|
107
|
-
tags: {
|
|
108
|
-
UNTRUSTED: [0, 10],
|
|
109
|
-
LIMITED_CHARS: [0, 10]
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('skips instrumentation if the event is not created', function () {
|
|
117
|
-
sinon.stub(core.assess.eventFactory, 'createSinkEvent');
|
|
118
|
-
|
|
119
|
-
const store = {
|
|
120
|
-
assess: { responseData: { contentType: 'application/json' } },
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
simulateRequestScope(function () {
|
|
124
|
-
const extern = trackString('hello world');
|
|
125
|
-
|
|
126
|
-
response[method](extern);
|
|
127
|
-
expect(reportFindings).to.not.have.been.called;
|
|
128
|
-
}, store);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('report a reflected-xss vulnerability', function () {
|
|
132
|
-
simulateRequestScope(function () {
|
|
133
|
-
const value = 'hello world';
|
|
134
|
-
const extern = trackString(value);
|
|
135
|
-
|
|
136
|
-
response[method](extern);
|
|
137
|
-
expect(reportFindings).to.have.been.calledWithMatch({
|
|
138
|
-
ruleId: 'reflected-xss',
|
|
139
|
-
sinkEvent: {
|
|
140
|
-
name: `${moduleName}.${methodName}`,
|
|
141
|
-
moduleName,
|
|
142
|
-
methodName,
|
|
143
|
-
context: `res.${method}('${extern}')`,
|
|
144
|
-
object: {
|
|
145
|
-
value: `${moduleName}.${responseName}`,
|
|
146
|
-
tracked: false,
|
|
147
|
-
},
|
|
148
|
-
args: [{ value, tracked: true }],
|
|
149
|
-
tags: { [UNTRUSTED]: [0, 10] },
|
|
150
|
-
source: 'P0',
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
});
|
|
@@ -1,32 +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 koa', function () {
|
|
11
|
-
let core, koa;
|
|
12
|
-
|
|
13
|
-
beforeEach(function () {
|
|
14
|
-
core = mocks.core();
|
|
15
|
-
core.assess = { dataflow: { sinks: {} } };
|
|
16
|
-
|
|
17
|
-
const moduleMock = (name) => (deps) => {
|
|
18
|
-
deps.assess.dataflow.sinks.koa[name] = { install: sinon.stub() };
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
koa = proxyquire('.', {
|
|
22
|
-
'./unvalidated-redirect': moduleMock('unvalidatedRedirect'),
|
|
23
|
-
})(core);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('installs its components', function () {
|
|
27
|
-
koa.install();
|
|
28
|
-
MODULES.forEach((module) => {
|
|
29
|
-
expect(koa[module].install).to.have.been.calledOnce;
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|