@contrast/assess 1.31.0 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/crypto-analysis/install/crypto.test.js +146 -0
- package/lib/crypto-analysis/install/math.test.js +65 -0
- package/lib/dataflow/index.test.js +36 -0
- package/lib/dataflow/propagation/index.test.js +103 -0
- package/lib/dataflow/propagation/install/JSON/index.test.js +50 -0
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +232 -0
- package/lib/dataflow/propagation/install/JSON/parse.test.js +968 -0
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +265 -0
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +106 -0
- package/lib/dataflow/propagation/install/buffer.test.js +109 -0
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +94 -0
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +49 -0
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +50 -0
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +148 -0
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +145 -0
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +78 -0
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +69 -0
- package/lib/dataflow/propagation/install/ejs/template.test.js +62 -0
- package/lib/dataflow/propagation/install/encode-uri.test.js +83 -0
- package/lib/dataflow/propagation/install/escape-html.test.js +71 -0
- package/lib/dataflow/propagation/install/escape.test.js +73 -0
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +71 -0
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +58 -0
- package/lib/dataflow/propagation/install/joi/any.test.js +270 -0
- package/lib/dataflow/propagation/install/joi/array.test.js +912 -0
- package/lib/dataflow/propagation/install/joi/boolean.test.js +103 -0
- package/lib/dataflow/propagation/install/joi/expression.test.js +76 -0
- package/lib/dataflow/propagation/install/joi/index.test.js +39 -0
- package/lib/dataflow/propagation/install/joi/number.test.js +103 -0
- package/lib/dataflow/propagation/install/joi/object.test.js +119 -0
- package/lib/dataflow/propagation/install/joi/ref.test.js +607 -0
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +513 -0
- package/lib/dataflow/propagation/install/mongoose/index.test.js +42 -0
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +348 -0
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +512 -0
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +160 -0
- package/lib/dataflow/propagation/install/mustache-escape.test.js +62 -0
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +74 -0
- package/lib/dataflow/propagation/install/parse-int.test.js +48 -0
- package/lib/dataflow/propagation/install/path/basename.test.js +143 -0
- package/lib/dataflow/propagation/install/path/dirname.test.js +167 -0
- package/lib/dataflow/propagation/install/path/extname.test.js +141 -0
- package/lib/dataflow/propagation/install/path/format.test.js +250 -0
- package/lib/dataflow/propagation/install/path/index.test.js +45 -0
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +485 -0
- package/lib/dataflow/propagation/install/path/normalize.test.js +176 -0
- package/lib/dataflow/propagation/install/path/parse.test.js +238 -0
- package/lib/dataflow/propagation/install/path/relative.test.js +239 -0
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +158 -0
- package/lib/dataflow/propagation/install/pug/index.test.js +55 -0
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +69 -0
- package/lib/dataflow/propagation/install/querystring/escape.test.js +63 -0
- package/lib/dataflow/propagation/install/querystring/index.test.js +40 -0
- package/lib/dataflow/propagation/install/querystring/parse.test.js +272 -0
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +301 -0
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +281 -0
- package/lib/dataflow/propagation/install/send.test.js +63 -0
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +73 -0
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +130 -0
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +100 -0
- package/lib/dataflow/propagation/install/string/concat.test.js +132 -0
- package/lib/dataflow/propagation/install/string/format-methods.test.js +61 -0
- package/lib/dataflow/propagation/install/string/html-methods.test.js +164 -0
- package/lib/dataflow/propagation/install/string/index.test.js +103 -0
- package/lib/dataflow/propagation/install/string/match-all.test.js +399 -0
- package/lib/dataflow/propagation/install/string/match.test.js +361 -0
- package/lib/dataflow/propagation/install/string/replace.test.js +588 -0
- package/lib/dataflow/propagation/install/string/slice.test.js +265 -0
- package/lib/dataflow/propagation/install/string/split.test.js +500 -0
- package/lib/dataflow/propagation/install/string/substring.test.js +238 -0
- package/lib/dataflow/propagation/install/string/trim.test.js +122 -0
- package/lib/dataflow/propagation/install/unescape.test.js +78 -0
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +63 -0
- package/lib/dataflow/propagation/install/url/parse.test.js +391 -0
- package/lib/dataflow/propagation/install/url/searchParams.test.js +538 -0
- package/lib/dataflow/propagation/install/url/url.test.js +466 -0
- package/lib/dataflow/propagation/install/util-format.test.js +336 -0
- package/lib/dataflow/propagation/install/validator/hooks.test.js +211 -0
- package/lib/dataflow/sinks/index.test.js +78 -0
- package/lib/dataflow/sinks/install/child-process.test.js +338 -0
- package/lib/dataflow/sinks/install/eval.test.js +95 -0
- package/lib/dataflow/sinks/install/express/index.test.js +33 -0
- package/lib/dataflow/sinks/install/express/reflected-xss.js +55 -57
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +109 -0
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +144 -0
- package/lib/dataflow/sinks/install/fastify/index.test.js +32 -0
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +130 -0
- package/lib/dataflow/sinks/install/fs.test.js +138 -0
- package/lib/dataflow/sinks/install/function.test.js +103 -0
- package/lib/dataflow/sinks/install/hapi/index.test.js +32 -0
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +130 -0
- package/lib/dataflow/sinks/install/http/index.test.js +33 -0
- package/lib/dataflow/sinks/install/http/request.test.js +184 -0
- package/lib/dataflow/sinks/install/http/server-response.test.js +162 -0
- package/lib/dataflow/sinks/install/koa/index.test.js +32 -0
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +200 -0
- package/lib/dataflow/sinks/install/libxmljs.test.js +158 -0
- package/lib/dataflow/sinks/install/marsdb.test.js +166 -0
- package/lib/dataflow/sinks/install/mongodb.test.js +621 -0
- package/lib/dataflow/sinks/install/mssql.test.js +136 -0
- package/lib/dataflow/sinks/install/mysql.test.js +233 -0
- package/lib/dataflow/sinks/install/node-serialize.test.js +85 -0
- package/lib/dataflow/sinks/install/postgres.test.js +158 -0
- package/lib/dataflow/sinks/install/restify.test.js +142 -0
- package/lib/dataflow/sinks/install/sequelize.test.js +100 -0
- package/lib/dataflow/sinks/install/sqlite3.test.js +118 -0
- package/lib/dataflow/sinks/install/vm.test.js +326 -0
- package/lib/dataflow/sources/handler.test.js +463 -0
- package/lib/dataflow/sources/index.test.js +58 -0
- package/lib/dataflow/sources/install/body-parser1.test.js +248 -0
- package/lib/dataflow/sources/install/busboy.test.js +152 -0
- package/lib/dataflow/sources/install/cookie-parser1.test.js +143 -0
- package/lib/dataflow/sources/install/express/params.test.js +105 -0
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +65 -0
- package/lib/dataflow/sources/install/fastify/fastify.test.js +210 -0
- package/lib/dataflow/sources/install/fastify/index.test.js +33 -0
- package/lib/dataflow/sources/install/formidable1.test.js +119 -0
- package/lib/dataflow/sources/install/hapi/hapi.test.js +172 -0
- package/lib/dataflow/sources/install/hapi/index.test.js +33 -0
- package/lib/dataflow/sources/install/http.test.js +155 -0
- package/lib/dataflow/sources/install/koa/index.test.js +40 -0
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +161 -0
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +197 -0
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +146 -0
- package/lib/dataflow/sources/install/koa/koa2.test.js +145 -0
- package/lib/dataflow/sources/install/multer1.test.js +145 -0
- package/lib/dataflow/sources/install/qs6.test.js +131 -0
- package/lib/dataflow/sources/install/querystring.test.js +82 -0
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +88 -0
- package/lib/dataflow/sources/install/restify/index.test.js +38 -0
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +144 -0
- package/lib/dataflow/sources/install/restify/router.test.js +83 -0
- package/lib/dataflow/tag-utils-complete.test.js +27 -0
- package/lib/dataflow/tag-utils.test.js +192 -0
- package/lib/dataflow/tracker.test.js +216 -0
- package/lib/dataflow/utils/is-safe-content-type.test.js +16 -0
- package/lib/dataflow/utils/is-vulnerable.test.js +115 -0
- package/lib/event-factory.test.js +321 -0
- package/lib/get-policy.test.js +194 -0
- package/lib/get-source-context.test.js +108 -0
- package/lib/index.test.js +41 -0
- package/lib/make-source-context.test.js +50 -0
- package/lib/response-scanning/handlers/index.test.js +425 -0
- package/lib/response-scanning/handlers/utils.test.js +391 -0
- package/lib/response-scanning/index.test.js +41 -0
- package/lib/response-scanning/install/http.test.js +175 -0
- package/lib/rule-scopes.test.js +27 -0
- package/lib/session-configuration/handlers.test.js +84 -0
- package/lib/session-configuration/index.test.js +36 -0
- package/lib/session-configuration/install/express-session.test.js +220 -0
- package/lib/session-configuration/install/fastify-cookie.test.js +65 -0
- package/lib/session-configuration/install/hapi.test.js +269 -0
- package/lib/session-configuration/install/koa.test.js +92 -0
- package/package.json +2 -2
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const sinon = require('sinon');
|
|
5
|
+
const {
|
|
6
|
+
DataflowTag: {
|
|
7
|
+
UNTRUSTED,
|
|
8
|
+
URL_ENCODED,
|
|
9
|
+
}
|
|
10
|
+
} = require('@contrast/common');
|
|
11
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
12
|
+
|
|
13
|
+
describe('assess dataflow sinks koa unvalidated-redirect', function () {
|
|
14
|
+
let core, Response, simulateRequestScope, trackString, reportFindings, reportSafePositive;
|
|
15
|
+
|
|
16
|
+
beforeEach(function () {
|
|
17
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
18
|
+
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
19
|
+
reportSafePositive = sinon.stub(core.assess.dataflow.sinks, 'reportSafePositive');
|
|
20
|
+
|
|
21
|
+
Response = {
|
|
22
|
+
ctx: {
|
|
23
|
+
// eslint-disable-next-line object-shorthand
|
|
24
|
+
get: function () {
|
|
25
|
+
return this.referrer;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
redirect: () => { }
|
|
29
|
+
};
|
|
30
|
+
core.depHooks.resolve.yields(Response);
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
require('./unvalidated-redirect')(core).install();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('skips instrumentation if there is no assess store', function () {
|
|
37
|
+
Response.redirect('hello');
|
|
38
|
+
expect(reportFindings).to.not.have.been.called;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('skips instrumentation if url does not exist', function () {
|
|
42
|
+
simulateRequestScope(function () {
|
|
43
|
+
Response.redirect();
|
|
44
|
+
expect(reportFindings).to.not.have.been.called;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('skip instrumentation if url is not string', function () {
|
|
49
|
+
simulateRequestScope(function () {
|
|
50
|
+
Response.redirect(1, 2);
|
|
51
|
+
expect(reportFindings).to.not.have.been.called;
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('skips instrumentation if url is not tracked', function () {
|
|
56
|
+
simulateRequestScope(function () {
|
|
57
|
+
Response.redirect('url');
|
|
58
|
+
expect(reportFindings).to.not.have.been.called;
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('reports a "safe positive" event when safe tags overlap UNTRUSTED', function () {
|
|
63
|
+
simulateRequestScope(function () {
|
|
64
|
+
const value = 'https%3A%2F%2Fhello.com';
|
|
65
|
+
const stop = value.length - 1;
|
|
66
|
+
const extern = trackString(value, {
|
|
67
|
+
tags: {
|
|
68
|
+
[URL_ENCODED]: [0, stop],
|
|
69
|
+
[UNTRUSTED]: [0, stop],
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
Response.redirect(extern);
|
|
74
|
+
|
|
75
|
+
expect(reportSafePositive).to.have.been.calledWithMatch({
|
|
76
|
+
name: 'Koa.Response.redirect',
|
|
77
|
+
ruleId: 'unvalidated-redirect',
|
|
78
|
+
safeTags: [URL_ENCODED],
|
|
79
|
+
strInfo: {
|
|
80
|
+
tags: { [URL_ENCODED]: [0, stop], [UNTRUSTED]: [0, stop] },
|
|
81
|
+
value
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('reports an unvalidated-redirect', function () {
|
|
88
|
+
simulateRequestScope(function () {
|
|
89
|
+
const value = 'https://hello.com';
|
|
90
|
+
const extern = trackString(value, {
|
|
91
|
+
tags: {
|
|
92
|
+
[URL_ENCODED]: [0, 2],
|
|
93
|
+
[UNTRUSTED]: [0, 16],
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
Response.redirect(extern);
|
|
98
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
99
|
+
ruleId: 'unvalidated-redirect',
|
|
100
|
+
sinkEvent: {
|
|
101
|
+
args: [{ value, tracked: true }],
|
|
102
|
+
context: 'response.redirect(\'https://hello.com\')',
|
|
103
|
+
name: 'Koa.Response.redirect',
|
|
104
|
+
moduleName: 'koa',
|
|
105
|
+
methodName: 'Response.redirect',
|
|
106
|
+
object: {
|
|
107
|
+
value: 'Koa.Response',
|
|
108
|
+
tracked: false,
|
|
109
|
+
},
|
|
110
|
+
result: { value: undefined, tracked: false },
|
|
111
|
+
source: 'P0',
|
|
112
|
+
tags: {
|
|
113
|
+
[UNTRUSTED]: [0, 16],
|
|
114
|
+
[URL_ENCODED]: [0, 2],
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('reports an unvalidated-redirect from a Referrer header', function () {
|
|
122
|
+
simulateRequestScope(function () {
|
|
123
|
+
const value = 'https://hello.com';
|
|
124
|
+
const extern = trackString(value, {
|
|
125
|
+
tags: {
|
|
126
|
+
[URL_ENCODED]: [0, 2],
|
|
127
|
+
[UNTRUSTED]: [0, 16],
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
Response.ctx.referrer = extern;
|
|
132
|
+
Response.redirect('back');
|
|
133
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
134
|
+
ruleId: 'unvalidated-redirect',
|
|
135
|
+
sinkEvent: {
|
|
136
|
+
args: [{ value: 'back', tracked: false }, { value, tracked: true }],
|
|
137
|
+
context: 'response.redirect(\'https://hello.com\')',
|
|
138
|
+
name: 'Koa.Response.redirect',
|
|
139
|
+
object: {
|
|
140
|
+
value: 'Koa.Response',
|
|
141
|
+
tracked: false,
|
|
142
|
+
},
|
|
143
|
+
result: { value: undefined, tracked: false },
|
|
144
|
+
source: 'P1',
|
|
145
|
+
tags: {
|
|
146
|
+
[URL_ENCODED]: [0, 2],
|
|
147
|
+
[UNTRUSTED]: [0, 16]
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('reports an unvalidated-redirect from the second argument', function () {
|
|
155
|
+
simulateRequestScope(function () {
|
|
156
|
+
const value = 'https://hello.com';
|
|
157
|
+
const extern = trackString(value, {
|
|
158
|
+
tags: {
|
|
159
|
+
[URL_ENCODED]: [0, 2],
|
|
160
|
+
[UNTRUSTED]: [0, 16],
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
Response.redirect('back', extern);
|
|
165
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
166
|
+
ruleId: 'unvalidated-redirect',
|
|
167
|
+
sinkEvent: {
|
|
168
|
+
args: [{ value: 'back', tracked: false }, { value, tracked: true }],
|
|
169
|
+
context: 'response.redirect(\'https://hello.com\')',
|
|
170
|
+
name: 'Koa.Response.redirect',
|
|
171
|
+
object: {
|
|
172
|
+
value: 'Koa.Response',
|
|
173
|
+
tracked: false,
|
|
174
|
+
},
|
|
175
|
+
result: { value: undefined, tracked: false },
|
|
176
|
+
source: 'P1',
|
|
177
|
+
tags: {
|
|
178
|
+
[URL_ENCODED]: [0, 2],
|
|
179
|
+
[UNTRUSTED]: [0, 16]
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('does not report an unvalidated-redirect if the tainted data is not in the URI path', function () {
|
|
187
|
+
simulateRequestScope(function () {
|
|
188
|
+
const value = 'https://hello.com/query?test=value';
|
|
189
|
+
const extern = trackString(value, {
|
|
190
|
+
tags: {
|
|
191
|
+
[URL_ENCODED]: [0, 2],
|
|
192
|
+
[UNTRUSTED]: [24, 33],
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
Response.redirect(extern);
|
|
197
|
+
expect(reportFindings).to.not.have.been.called;
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const sinon = require('sinon');
|
|
4
|
+
const { expect } = require('chai');
|
|
5
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
+
|
|
7
|
+
describe('assess dataflow sinks libxmljs', function () {
|
|
8
|
+
let modules, core, simulateRequestScope, trackString, reportFindings;
|
|
9
|
+
|
|
10
|
+
beforeEach(function () {
|
|
11
|
+
|
|
12
|
+
modules = {
|
|
13
|
+
'libxmljs@0': {
|
|
14
|
+
parseXml: sinon.stub(),
|
|
15
|
+
parseXmlString: sinon.stub()
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
'libxmljs@1': {
|
|
19
|
+
parseXml: sinon.stub(),
|
|
20
|
+
parseXmlAsync: sinon.stub()
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
'libxmljs2': {
|
|
24
|
+
parseXml: sinon.stub(),
|
|
25
|
+
parseXmlString: sinon.stub()
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
30
|
+
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
31
|
+
|
|
32
|
+
core.depHooks.resolve
|
|
33
|
+
.withArgs({ name: 'libxmljs', version: '<1' })
|
|
34
|
+
.yields(modules['libxmljs@0']);
|
|
35
|
+
|
|
36
|
+
core.depHooks.resolve
|
|
37
|
+
.withArgs({ name: 'libxmljs', version: '>=1' })
|
|
38
|
+
.yields(modules['libxmljs@1']);
|
|
39
|
+
|
|
40
|
+
core.depHooks.resolve
|
|
41
|
+
.withArgs({ name: 'libxmljs2' })
|
|
42
|
+
.yields(modules['libxmljs2']);
|
|
43
|
+
|
|
44
|
+
require('./libxmljs')(core).install();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
[
|
|
48
|
+
{
|
|
49
|
+
module: 'libxmljs@0',
|
|
50
|
+
moduleName: 'libxmljs',
|
|
51
|
+
methods: ['parseXml', 'parseXmlString']
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
module: 'libxmljs@1',
|
|
55
|
+
moduleName: 'libxmljs',
|
|
56
|
+
methods: ['parseXml', 'parseXmlAsync']
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
module: 'libxmljs2',
|
|
60
|
+
moduleName: 'libxmljs2',
|
|
61
|
+
methods: ['parseXml', 'parseXmlString']
|
|
62
|
+
}
|
|
63
|
+
].forEach(({ module, moduleName, methods }) => {
|
|
64
|
+
describe(`${module}`, function() {
|
|
65
|
+
methods.forEach((method) => {
|
|
66
|
+
describe(`${method}`, function() {
|
|
67
|
+
it('skips instrumentation if assess store is missing', function () {
|
|
68
|
+
modules[module][method]('<foo>', { noent: true });
|
|
69
|
+
expect(reportFindings).not.to.have.been.called;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('skips instrumentation if no argument is provided', function () {
|
|
73
|
+
simulateRequestScope(function () {
|
|
74
|
+
modules[module][method]();
|
|
75
|
+
expect(reportFindings).not.to.have.been.called;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('skips instrumentation if instrumentation is locked', function () {
|
|
80
|
+
simulateRequestScope(function () {
|
|
81
|
+
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
82
|
+
modules[module][method]('<foo>', { noent: true });
|
|
83
|
+
expect(reportFindings).not.to.have.been.called;
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('skips instrumentation if the argument is not a string', function () {
|
|
89
|
+
simulateRequestScope(function () {
|
|
90
|
+
modules[module][method](true, { noent: true });
|
|
91
|
+
expect(reportFindings).not.to.have.been.called;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('skips instrumentation if the argument is not tracked', function () {
|
|
96
|
+
simulateRequestScope(function () {
|
|
97
|
+
modules[module][method]('<foo>', { noent: true });
|
|
98
|
+
expect(reportFindings).not.to.have.been.called;
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('skips instrumentation if the argument is safe', function () {
|
|
103
|
+
simulateRequestScope(function () {
|
|
104
|
+
const extern = trackString('<foo>', {
|
|
105
|
+
tags: {
|
|
106
|
+
LIMITED_CHARS: [0, 4],
|
|
107
|
+
UNTRUSTED: [0, 4],
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
modules[module][method](extern, { noent: true });
|
|
112
|
+
expect(reportFindings).not.to.have.been.called;
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('skips instrumentation if noenet is set to false', function () {
|
|
117
|
+
simulateRequestScope(function () {
|
|
118
|
+
const extern = trackString('<foo>', {
|
|
119
|
+
tags: {
|
|
120
|
+
LIMITED_CHARS: [0, 4],
|
|
121
|
+
UNTRUSTED: [0, 4],
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
modules[module][method](extern, { noent: false });
|
|
126
|
+
expect(reportFindings).not.to.have.been.called;
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('reports xxe', function () {
|
|
131
|
+
simulateRequestScope(function () {
|
|
132
|
+
const value = '<xxe>';
|
|
133
|
+
const extern = trackString(value);
|
|
134
|
+
|
|
135
|
+
modules[module][method](extern, { noent: true });
|
|
136
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
137
|
+
ruleId: 'xxe',
|
|
138
|
+
sinkEvent: {
|
|
139
|
+
name: `${moduleName}.${method}`,
|
|
140
|
+
moduleName,
|
|
141
|
+
methodName: method,
|
|
142
|
+
context: `${moduleName}.${method}(<xxe>, { noent: true })`,
|
|
143
|
+
object: {
|
|
144
|
+
value: moduleName,
|
|
145
|
+
tracked: false,
|
|
146
|
+
},
|
|
147
|
+
args: [{ value, tracked: true }],
|
|
148
|
+
tags: { UNTRUSTED: [0, 4] },
|
|
149
|
+
source: 'P0',
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const sinon = require('sinon');
|
|
5
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
+
const {
|
|
7
|
+
DataflowTag: { UNTRUSTED, LIMITED_CHARS },
|
|
8
|
+
Rule,
|
|
9
|
+
} = require('@contrast/common');
|
|
10
|
+
|
|
11
|
+
describe('assess dataflow marsdb', function () {
|
|
12
|
+
let core,
|
|
13
|
+
simulateRequestScope,
|
|
14
|
+
createSinkEvent,
|
|
15
|
+
trackString,
|
|
16
|
+
reportFindings,
|
|
17
|
+
instr;
|
|
18
|
+
|
|
19
|
+
class Collection {
|
|
20
|
+
find() { }
|
|
21
|
+
findOne() { }
|
|
22
|
+
update() { }
|
|
23
|
+
remove() { }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
beforeEach(function () {
|
|
27
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
28
|
+
reportFindings = sinon.stub(core.assess.dataflow.sinks, 'reportFindings');
|
|
29
|
+
createSinkEvent = sinon.stub(
|
|
30
|
+
core.assess.eventFactory,
|
|
31
|
+
'createSinkEvent'
|
|
32
|
+
);
|
|
33
|
+
core.depHooks.resolve.withArgs({ name: 'marsdb' }).yields({ Collection });
|
|
34
|
+
|
|
35
|
+
instr = require('./marsdb')(core);
|
|
36
|
+
instr.install();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
[
|
|
40
|
+
{ subject: Collection, method: 'find' },
|
|
41
|
+
{ subject: Collection, method: 'findOne' },
|
|
42
|
+
{ subject: Collection, method: 'update' },
|
|
43
|
+
{ subject: Collection, method: 'remove' },
|
|
44
|
+
].forEach(({ subject, method }) => {
|
|
45
|
+
describe(`${subject.name}.prototype.${method}()`, function () {
|
|
46
|
+
it('skips instrumentation if assess store is missing', function () {
|
|
47
|
+
const tracked = trackString('foo');
|
|
48
|
+
new subject()[method]({ tracked });
|
|
49
|
+
expect(reportFindings).not.to.have.been.called;
|
|
50
|
+
expect(createSinkEvent).not.to.have.been.called;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('skips instrumentation if instrumentation is locked', function () {
|
|
54
|
+
core.scopes.instrumentation.isLocked = () => true;
|
|
55
|
+
|
|
56
|
+
simulateRequestScope(function () {
|
|
57
|
+
const tracked = trackString('foo');
|
|
58
|
+
new subject()[method]({ tracked });
|
|
59
|
+
expect(reportFindings).not.to.have.been.called;
|
|
60
|
+
expect(createSinkEvent).not.to.have.been.called;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('skips instrumentation if there is no argument', function () {
|
|
65
|
+
simulateRequestScope(function () {
|
|
66
|
+
new subject()[method]();
|
|
67
|
+
expect(reportFindings).not.to.have.been.called;
|
|
68
|
+
expect(createSinkEvent).not.to.have.been.called;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('passing not tracked string', function () {
|
|
73
|
+
simulateRequestScope(function () {
|
|
74
|
+
new subject()[method]({ id: '1231' });
|
|
75
|
+
expect(reportFindings).not.to.have.been.called;
|
|
76
|
+
expect(createSinkEvent).not.to.have.been.called;
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it(`reports vulnerability - ${subject.name}.prototype.${method}()`, function () {
|
|
81
|
+
createSinkEvent.returns(true);
|
|
82
|
+
|
|
83
|
+
simulateRequestScope(function () {
|
|
84
|
+
const tracked = trackString('foo');
|
|
85
|
+
|
|
86
|
+
new subject()[method]({ tracked });
|
|
87
|
+
|
|
88
|
+
expect(reportFindings).to.have.been.calledWithMatch({
|
|
89
|
+
ruleId: Rule.NOSQL_INJECTION_MONGO,
|
|
90
|
+
sinkEvent: true,
|
|
91
|
+
});
|
|
92
|
+
expect(createSinkEvent).to.have.been.calledWithMatch({
|
|
93
|
+
args: [{ value: "{ tracked: 'foo' }", tracked: true }],
|
|
94
|
+
context: `marsdb.Collection.${method}({ tracked: 'foo' })`,
|
|
95
|
+
object: {
|
|
96
|
+
tracked: false,
|
|
97
|
+
value: 'marsdb.Collection',
|
|
98
|
+
},
|
|
99
|
+
name: `marsdb.Collection.prototype.${method}`,
|
|
100
|
+
moduleName: 'marsdb',
|
|
101
|
+
methodName: `Collection.prototype.${method}`,
|
|
102
|
+
result: {
|
|
103
|
+
tracked: true,
|
|
104
|
+
value: 'foo',
|
|
105
|
+
},
|
|
106
|
+
source: 'P0',
|
|
107
|
+
tags: {
|
|
108
|
+
UNTRUSTED: [0, 2],
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should not report in case the input is safe', function () {
|
|
115
|
+
simulateRequestScope(function () {
|
|
116
|
+
const tracked = trackString('foo', {
|
|
117
|
+
tags: {
|
|
118
|
+
[LIMITED_CHARS]: [0, 2],
|
|
119
|
+
[UNTRUSTED]: [0, 2],
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
new subject()[method]({ tracked });
|
|
124
|
+
|
|
125
|
+
expect(reportFindings).not.to.have.been.called;
|
|
126
|
+
expect(createSinkEvent).not.to.have.been.called;
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it(`should not report vulnerability if createSinkEvent returns null - ${subject.name}.prototype.${method}()`, function () {
|
|
131
|
+
createSinkEvent.returns(null);
|
|
132
|
+
|
|
133
|
+
simulateRequestScope(function () {
|
|
134
|
+
const tracked = trackString('foo');
|
|
135
|
+
|
|
136
|
+
new subject()[method]({ tracked });
|
|
137
|
+
|
|
138
|
+
expect(reportFindings).not.to.have.been.called;
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe('installing marsdb', function () {
|
|
146
|
+
let core, instr;
|
|
147
|
+
|
|
148
|
+
it('should log trace error if the method does not exist', function () {
|
|
149
|
+
class Collection {
|
|
150
|
+
find() { }
|
|
151
|
+
findOne() { }
|
|
152
|
+
insert() { }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
({ core } = initAssessFixture());
|
|
156
|
+
core.depHooks.resolve.withArgs({ name: 'marsdb' }).yields({ Collection });
|
|
157
|
+
|
|
158
|
+
instr = require('./marsdb')(core);
|
|
159
|
+
instr.install();
|
|
160
|
+
|
|
161
|
+
expect(core.logger.trace).to.have.been.calledWith(
|
|
162
|
+
'method %s not found - skipping instrumentation',
|
|
163
|
+
'marsdb.Collection.prototype.update',
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
});
|