@contrast/assess 1.46.1 → 1.46.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -11
- package/lib/crypto-analysis/install/crypto.test.js +0 -146
- package/lib/crypto-analysis/install/math.test.js +0 -65
- package/lib/dataflow/index.test.js +0 -36
- package/lib/dataflow/propagation/index.test.js +0 -103
- package/lib/dataflow/propagation/install/JSON/index.test.js +0 -50
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +0 -232
- package/lib/dataflow/propagation/install/JSON/parse.test.js +0 -968
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +0 -265
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +0 -106
- package/lib/dataflow/propagation/install/buffer.test.js +0 -112
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +0 -94
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +0 -49
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +0 -50
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +0 -148
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +0 -145
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +0 -78
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +0 -69
- package/lib/dataflow/propagation/install/ejs/template.test.js +0 -62
- package/lib/dataflow/propagation/install/encode-uri.test.js +0 -83
- package/lib/dataflow/propagation/install/escape-html.test.js +0 -71
- package/lib/dataflow/propagation/install/escape.test.js +0 -73
- package/lib/dataflow/propagation/install/fastify-send.test.js +0 -42
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +0 -71
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +0 -58
- package/lib/dataflow/propagation/install/joi/any.test.js +0 -270
- package/lib/dataflow/propagation/install/joi/array.test.js +0 -912
- package/lib/dataflow/propagation/install/joi/boolean.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/expression.test.js +0 -76
- package/lib/dataflow/propagation/install/joi/index.test.js +0 -39
- package/lib/dataflow/propagation/install/joi/number.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/object.test.js +0 -119
- package/lib/dataflow/propagation/install/joi/ref.test.js +0 -607
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +0 -513
- package/lib/dataflow/propagation/install/mongoose/index.test.js +0 -42
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +0 -348
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +0 -511
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +0 -199
- package/lib/dataflow/propagation/install/mustache-escape.test.js +0 -62
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +0 -74
- package/lib/dataflow/propagation/install/parse-int.test.js +0 -48
- package/lib/dataflow/propagation/install/path/basename.test.js +0 -143
- package/lib/dataflow/propagation/install/path/dirname.test.js +0 -167
- package/lib/dataflow/propagation/install/path/extname.test.js +0 -141
- package/lib/dataflow/propagation/install/path/format.test.js +0 -250
- package/lib/dataflow/propagation/install/path/index.test.js +0 -45
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +0 -485
- package/lib/dataflow/propagation/install/path/normalize.test.js +0 -176
- package/lib/dataflow/propagation/install/path/parse.test.js +0 -238
- package/lib/dataflow/propagation/install/path/relative.test.js +0 -239
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +0 -158
- package/lib/dataflow/propagation/install/pug/index.test.js +0 -55
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +0 -69
- package/lib/dataflow/propagation/install/querystring/escape.test.js +0 -63
- package/lib/dataflow/propagation/install/querystring/index.test.js +0 -40
- package/lib/dataflow/propagation/install/querystring/parse.test.js +0 -272
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +0 -301
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +0 -283
- package/lib/dataflow/propagation/install/send.test.js +0 -63
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +0 -74
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +0 -119
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +0 -100
- package/lib/dataflow/propagation/install/string/concat.test.js +0 -145
- package/lib/dataflow/propagation/install/string/format-methods.test.js +0 -74
- package/lib/dataflow/propagation/install/string/html-methods.test.js +0 -177
- package/lib/dataflow/propagation/install/string/index.test.js +0 -103
- package/lib/dataflow/propagation/install/string/match-all.test.js +0 -412
- package/lib/dataflow/propagation/install/string/match.test.js +0 -374
- package/lib/dataflow/propagation/install/string/replace.test.js +0 -601
- package/lib/dataflow/propagation/install/string/slice.test.js +0 -278
- package/lib/dataflow/propagation/install/string/split.test.js +0 -513
- package/lib/dataflow/propagation/install/string/substring.test.js +0 -251
- package/lib/dataflow/propagation/install/string/trim.test.js +0 -135
- package/lib/dataflow/propagation/install/unescape.test.js +0 -78
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +0 -63
- package/lib/dataflow/propagation/install/url/parse.test.js +0 -391
- package/lib/dataflow/propagation/install/url/searchParams.test.js +0 -538
- package/lib/dataflow/propagation/install/url/url.test.js +0 -466
- package/lib/dataflow/propagation/install/util-format.test.js +0 -336
- package/lib/dataflow/propagation/install/validator/hooks.test.js +0 -211
- package/lib/dataflow/sinks/index.test.js +0 -78
- package/lib/dataflow/sinks/install/child-process.test.js +0 -338
- package/lib/dataflow/sinks/install/eval.test.js +0 -95
- package/lib/dataflow/sinks/install/express/index.test.js +0 -33
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +0 -109
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +0 -144
- package/lib/dataflow/sinks/install/fastify/index.test.js +0 -32
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/fs.test.js +0 -138
- package/lib/dataflow/sinks/install/function.test.js +0 -103
- package/lib/dataflow/sinks/install/hapi/index.test.js +0 -32
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/http/index.test.js +0 -33
- package/lib/dataflow/sinks/install/http/request.test.js +0 -184
- package/lib/dataflow/sinks/install/http/server-response.test.js +0 -160
- package/lib/dataflow/sinks/install/koa/index.test.js +0 -32
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +0 -200
- package/lib/dataflow/sinks/install/libxmljs.test.js +0 -158
- package/lib/dataflow/sinks/install/marsdb.test.js +0 -166
- package/lib/dataflow/sinks/install/mongodb.test.js +0 -617
- package/lib/dataflow/sinks/install/mssql.test.js +0 -134
- package/lib/dataflow/sinks/install/mysql.test.js +0 -224
- package/lib/dataflow/sinks/install/node-serialize.test.js +0 -83
- package/lib/dataflow/sinks/install/postgres.test.js +0 -152
- package/lib/dataflow/sinks/install/restify.test.js +0 -140
- package/lib/dataflow/sinks/install/sequelize.test.js +0 -100
- package/lib/dataflow/sinks/install/sqlite3.test.js +0 -118
- package/lib/dataflow/sinks/install/vm.test.js +0 -326
- package/lib/dataflow/sources/handler.test.js +0 -501
- package/lib/dataflow/sources/index.test.js +0 -60
- package/lib/dataflow/sources/install/body-parser1.test.js +0 -244
- package/lib/dataflow/sources/install/busboy.test.js +0 -152
- package/lib/dataflow/sources/install/cookie-parser1.test.js +0 -141
- package/lib/dataflow/sources/install/express/params.test.js +0 -110
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +0 -107
- package/lib/dataflow/sources/install/fastify/fastify.test.js +0 -207
- package/lib/dataflow/sources/install/fastify/index.test.js +0 -33
- package/lib/dataflow/sources/install/formidable1.test.js +0 -119
- package/lib/dataflow/sources/install/graphql-http.test.js +0 -133
- package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -171
- package/lib/dataflow/sources/install/hapi/index.test.js +0 -33
- package/lib/dataflow/sources/install/http.test.js +0 -149
- package/lib/dataflow/sources/install/koa/index.test.js +0 -40
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +0 -160
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +0 -197
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +0 -146
- package/lib/dataflow/sources/install/koa/koa2.test.js +0 -145
- package/lib/dataflow/sources/install/multer1.test.js +0 -143
- package/lib/dataflow/sources/install/qs6.test.js +0 -131
- package/lib/dataflow/sources/install/querystring.test.js +0 -82
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +0 -86
- package/lib/dataflow/sources/install/restify/index.test.js +0 -38
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +0 -140
- package/lib/dataflow/sources/install/restify/router.test.js +0 -81
- package/lib/dataflow/tag-utils-complete.test.js +0 -27
- package/lib/dataflow/tag-utils.test.js +0 -192
- package/lib/dataflow/tracker.test.js +0 -216
- package/lib/dataflow/utils/is-safe-content-type.test.js +0 -16
- package/lib/dataflow/utils/is-vulnerable.test.js +0 -115
- package/lib/event-factory.test.js +0 -326
- package/lib/get-policy.test.js +0 -194
- package/lib/get-source-context.test.js +0 -161
- package/lib/index.test.js +0 -45
- package/lib/make-source-context.test.js +0 -50
- package/lib/response-scanning/handlers/index.test.js +0 -419
- package/lib/response-scanning/handlers/utils.test.js +0 -380
- package/lib/response-scanning/index.test.js +0 -41
- package/lib/response-scanning/install/http.test.js +0 -175
- package/lib/rule-scopes.test.js +0 -27
- package/lib/sampler/common.test.js +0 -101
- package/lib/sampler/index.test.js +0 -313
- package/lib/session-configuration/handlers.test.js +0 -84
- package/lib/session-configuration/index.test.js +0 -36
- package/lib/session-configuration/install/express-session.test.js +0 -218
- package/lib/session-configuration/install/fastify-cookie.test.js +0 -63
- package/lib/session-configuration/install/hapi.test.js +0 -269
- package/lib/session-configuration/install/koa.test.js +0 -92
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow propagation string substring', function () {
|
|
8
|
-
let core, tracker, trackString, simulateRequestScope;
|
|
9
|
-
const allPatcher = new Map();
|
|
10
|
-
|
|
11
|
-
beforeEach(function () {
|
|
12
|
-
({
|
|
13
|
-
core,
|
|
14
|
-
simulateRequestScope,
|
|
15
|
-
trackString
|
|
16
|
-
} = initAssessFixture());
|
|
17
|
-
tracker = core.assess.dataflow.tracker;
|
|
18
|
-
|
|
19
|
-
core.assess.dataflow.propagation.stringInstrumentation.substring.install();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(function () {
|
|
23
|
-
core.assess.dataflow.propagation.stringInstrumentation.substring.uninstall();
|
|
24
|
-
sinon.resetHistory();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line mocha/no-sibling-hooks
|
|
28
|
-
afterEach(function() {
|
|
29
|
-
core.Perf.fromAllToMap('patcher', allPatcher);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
after(function() {
|
|
33
|
-
const stats = core.Perf.getStats(allPatcher);
|
|
34
|
-
for (const [key, { n, totalMicros, mean }] of stats.entries()) {
|
|
35
|
-
console.log(key, n, totalMicros, 'nsec', mean, 'mean');
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
[
|
|
40
|
-
{
|
|
41
|
-
desc: 'below',
|
|
42
|
-
str: 'xx-----',
|
|
43
|
-
tags: {
|
|
44
|
-
untrusted: [0, 1]
|
|
45
|
-
},
|
|
46
|
-
args: [2],
|
|
47
|
-
expectedResult: '-----',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
desc: 'above',
|
|
51
|
-
str: '-----xx',
|
|
52
|
-
tags: {
|
|
53
|
-
untrusted: [5, 6]
|
|
54
|
-
},
|
|
55
|
-
args: [0, 3],
|
|
56
|
-
result: '---',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
desc: 'highspan',
|
|
60
|
-
str: '--xxx--',
|
|
61
|
-
tags: {
|
|
62
|
-
untrusted: [2, 4]
|
|
63
|
-
},
|
|
64
|
-
args: [1, 3],
|
|
65
|
-
expected: {
|
|
66
|
-
untrusted: [1, 2]
|
|
67
|
-
},
|
|
68
|
-
expectedResult: '-xx',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
desc: 'within',
|
|
72
|
-
str: '--xxx--',
|
|
73
|
-
tags: {
|
|
74
|
-
untrusted: [2, 4]
|
|
75
|
-
},
|
|
76
|
-
args: [1],
|
|
77
|
-
expected: {
|
|
78
|
-
untrusted: [1, 3]
|
|
79
|
-
},
|
|
80
|
-
result: '-xxx--',
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
desc: 'fullSpan',
|
|
84
|
-
str: '--xxx--',
|
|
85
|
-
tags: {
|
|
86
|
-
untrusted: [2, 4]
|
|
87
|
-
},
|
|
88
|
-
args: [2, 2],
|
|
89
|
-
expected: {
|
|
90
|
-
untrusted: [0, 1]
|
|
91
|
-
},
|
|
92
|
-
result: 'xx',
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
desc: 'lowspan',
|
|
96
|
-
str: '--xxx--',
|
|
97
|
-
tags: {
|
|
98
|
-
untrusted: [2, 4]
|
|
99
|
-
},
|
|
100
|
-
args: [3, 3],
|
|
101
|
-
expected: {
|
|
102
|
-
untrusted: [0, 1]
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
].forEach(({ desc, str, tags, args, expected }) => {
|
|
106
|
-
it(desc, function () {
|
|
107
|
-
simulateRequestScope(function () {
|
|
108
|
-
const extern = trackString(str, { tags });
|
|
109
|
-
const result = extern.substr(...args);
|
|
110
|
-
const strInfo = tracker.getData(result);
|
|
111
|
-
|
|
112
|
-
if (expected) {
|
|
113
|
-
expect(strInfo.tags).to.deep.equal(expected);
|
|
114
|
-
} else {
|
|
115
|
-
expect(strInfo).to.be.null;
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
[
|
|
122
|
-
{
|
|
123
|
-
desc: 'not tracked',
|
|
124
|
-
str: '-----------',
|
|
125
|
-
args: [0, 2],
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
desc: 'below',
|
|
129
|
-
str: 'xx-----',
|
|
130
|
-
tags: {
|
|
131
|
-
untrusted: [0, 1]
|
|
132
|
-
},
|
|
133
|
-
args: [2],
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
desc: 'above',
|
|
137
|
-
str: '-----xx',
|
|
138
|
-
tags: {
|
|
139
|
-
untrusted: [5, 6]
|
|
140
|
-
},
|
|
141
|
-
args: [0, 3],
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
desc: 'highspan',
|
|
145
|
-
str: '--xxx--',
|
|
146
|
-
tags: {
|
|
147
|
-
untrusted: [2, 4]
|
|
148
|
-
},
|
|
149
|
-
args: {
|
|
150
|
-
substring: [1, 3],
|
|
151
|
-
substr: [1, 2],
|
|
152
|
-
},
|
|
153
|
-
expected: {
|
|
154
|
-
untrusted: [1, 1]
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
desc: 'within',
|
|
159
|
-
str: '--xxx--',
|
|
160
|
-
tags: {
|
|
161
|
-
untrusted: [2, 4]
|
|
162
|
-
},
|
|
163
|
-
args: [1],
|
|
164
|
-
expected: {
|
|
165
|
-
untrusted: [1, 3]
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
desc: 'fullSpan',
|
|
170
|
-
str: '--xxx--',
|
|
171
|
-
tags: {
|
|
172
|
-
untrusted: [2, 4]
|
|
173
|
-
},
|
|
174
|
-
args: {
|
|
175
|
-
substring: [2, 4],
|
|
176
|
-
substr: [2, 2],
|
|
177
|
-
},
|
|
178
|
-
expected: {
|
|
179
|
-
untrusted: [0, 1]
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
{
|
|
183
|
-
desc: 'lowspan',
|
|
184
|
-
str: '--xxx--',
|
|
185
|
-
tags: {
|
|
186
|
-
untrusted: [2, 4]
|
|
187
|
-
},
|
|
188
|
-
args: [3, 6],
|
|
189
|
-
expected: {
|
|
190
|
-
untrusted: [0, 1]
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
desc: 'lowspan',
|
|
195
|
-
str: 'xxx--xx',
|
|
196
|
-
tags: {
|
|
197
|
-
untrusted: [0, 2, 5, 6]
|
|
198
|
-
},
|
|
199
|
-
args: {
|
|
200
|
-
substring: [3, 1], // reversed work the same
|
|
201
|
-
substr: [1, 3], // but not for substr method
|
|
202
|
-
},
|
|
203
|
-
expected: {
|
|
204
|
-
untrusted: [0, 1]
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
].forEach(({ desc, str, tags, args, expected }) => {
|
|
208
|
-
['substring', 'substr'].forEach((method) => {
|
|
209
|
-
it(`${method} ${desc}`, function () {
|
|
210
|
-
simulateRequestScope(function () {
|
|
211
|
-
const extern = desc !== 'not tracked' ? trackString(str, { tags }) : str;
|
|
212
|
-
const methodArgs = args[method] || args;
|
|
213
|
-
const result = extern[method](...methodArgs);
|
|
214
|
-
const strInfo = tracker.getData(result);
|
|
215
|
-
|
|
216
|
-
if (expected) {
|
|
217
|
-
expect(strInfo.tags).to.deep.equal(expected);
|
|
218
|
-
} else {
|
|
219
|
-
expect(strInfo).to.be.null;
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('won\'t do anything if the result is the same or not in proper scope', function () {
|
|
227
|
-
const extern = trackString('foo');
|
|
228
|
-
|
|
229
|
-
let result;
|
|
230
|
-
|
|
231
|
-
core.scopes.sources.run({}, function () {
|
|
232
|
-
result = extern.substring(5);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
expect(tracker.getData(result)).to.be.null;
|
|
236
|
-
|
|
237
|
-
core.scopes.sources.run(null, function () {
|
|
238
|
-
result = extern.substr(0, 2);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
expect(tracker.getData(result)).to.be.null;
|
|
242
|
-
|
|
243
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
244
|
-
core.scopes.sources.run({}, function () {
|
|
245
|
-
result = extern.substring(0, 2);
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
expect(tracker.getData(result)).to.be.null;
|
|
250
|
-
});
|
|
251
|
-
});
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow propagation string trim', function () {
|
|
8
|
-
let core, tracker, trackString, simulateRequestScope;
|
|
9
|
-
const allPatcher = new Map();
|
|
10
|
-
|
|
11
|
-
beforeEach(function () {
|
|
12
|
-
({
|
|
13
|
-
core,
|
|
14
|
-
trackString,
|
|
15
|
-
simulateRequestScope,
|
|
16
|
-
} = initAssessFixture());
|
|
17
|
-
|
|
18
|
-
tracker = core.assess.dataflow.tracker;
|
|
19
|
-
core.assess.dataflow.propagation.stringInstrumentation.trim.install();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
afterEach(function () {
|
|
23
|
-
core.assess.dataflow.propagation.stringInstrumentation.trim.uninstall();
|
|
24
|
-
sinon.resetHistory();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// eslint-disable-next-line mocha/no-sibling-hooks
|
|
28
|
-
afterEach(function() {
|
|
29
|
-
core.Perf.fromAllToMap('patcher', allPatcher);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
after(function() {
|
|
33
|
-
const stats = core.Perf.getStats(allPatcher);
|
|
34
|
-
for (const [key, { n, totalMicros, mean }] of stats.entries()) {
|
|
35
|
-
console.log(key, n, totalMicros, 'nsec', mean, 'mean');
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
[
|
|
40
|
-
{
|
|
41
|
-
str: 'not-tracked',
|
|
42
|
-
expected: {
|
|
43
|
-
trim: undefined,
|
|
44
|
-
trimStart: undefined,
|
|
45
|
-
trimEnd: undefined,
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
str: ' foo ',
|
|
50
|
-
tags: {},
|
|
51
|
-
expected: {
|
|
52
|
-
trim: undefined,
|
|
53
|
-
trimStart: undefined,
|
|
54
|
-
trimEnd: undefined,
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
str: ' foo ',
|
|
59
|
-
tags: {
|
|
60
|
-
untrusted: [0, 6]
|
|
61
|
-
},
|
|
62
|
-
expected: {
|
|
63
|
-
trim: { untrusted: [0, 2] },
|
|
64
|
-
trimStart: { untrusted: [0, 4] },
|
|
65
|
-
trimEnd: { untrusted: [0, 4] },
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
str: ' foo',
|
|
70
|
-
tags: {
|
|
71
|
-
untrusted: [0, 4]
|
|
72
|
-
},
|
|
73
|
-
expected: {
|
|
74
|
-
trim: { untrusted: [0, 2] },
|
|
75
|
-
trimStart: { untrusted: [0, 2] },
|
|
76
|
-
trimEnd: { untrusted: [0, 4] },
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
str: 'foo ',
|
|
81
|
-
tags: {
|
|
82
|
-
untrusted: [0, 4]
|
|
83
|
-
},
|
|
84
|
-
expected: {
|
|
85
|
-
trim: { untrusted: [0, 2] },
|
|
86
|
-
trimStart: { untrusted: [0, 4] },
|
|
87
|
-
trimEnd: { untrusted: [0, 2] },
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
str: ' foo ',
|
|
92
|
-
tags: {
|
|
93
|
-
untrusted: [2, 4]
|
|
94
|
-
},
|
|
95
|
-
expected: {
|
|
96
|
-
trim: { untrusted: [0, 2] },
|
|
97
|
-
trimStart: { untrusted: [0, 2] },
|
|
98
|
-
trimEnd: { untrusted: [2, 4] },
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
].forEach(({ str, tags, expected = null }) => {
|
|
102
|
-
[
|
|
103
|
-
'trim',
|
|
104
|
-
'trimStart',
|
|
105
|
-
'trimEnd',
|
|
106
|
-
].forEach((method) => {
|
|
107
|
-
it(method, function () {
|
|
108
|
-
simulateRequestScope(function () {
|
|
109
|
-
const extern = str !== 'not-tracked' ? trackString(str, { tags }) : str;
|
|
110
|
-
const result = extern[method]();
|
|
111
|
-
expect(tracker.getData(result)?.tags).to.deep.equal(expected[method]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('won\'t do anything if not in proper scope', function () {
|
|
119
|
-
let result;
|
|
120
|
-
const extern = trackString(' foo', { tags: { untrusted: [0, 2] } });
|
|
121
|
-
|
|
122
|
-
core.scopes.sources.run(null, function () {
|
|
123
|
-
expect(tracker.getData(extern.trim())).to.be.null;
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
128
|
-
core.scopes.sources.run({}, function () {
|
|
129
|
-
expect(tracker.getData(extern.trim())).to.be.null;
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
expect(tracker.getData(result)).to.be.null;
|
|
134
|
-
});
|
|
135
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
DataflowTag: { UNTRUSTED, WEAK_URL_ENCODED }
|
|
6
|
-
} = require('@contrast/common');
|
|
7
|
-
const { expect } = require('chai');
|
|
8
|
-
const sinon = require('sinon');
|
|
9
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
-
|
|
11
|
-
describe('assess dataflow propagation unescape', function () {
|
|
12
|
-
let core, trackString, simulateRequestScope, tracker;
|
|
13
|
-
|
|
14
|
-
beforeEach(function () {
|
|
15
|
-
({
|
|
16
|
-
core,
|
|
17
|
-
simulateRequestScope,
|
|
18
|
-
trackString
|
|
19
|
-
} = initAssessFixture());
|
|
20
|
-
|
|
21
|
-
tracker = core.assess.dataflow.tracker;
|
|
22
|
-
core.assess.dataflow.propagation.unescape.install();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(function () {
|
|
26
|
-
core.assess.dataflow.propagation.unescape.uninstall();
|
|
27
|
-
sinon.resetHistory();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
[
|
|
31
|
-
{
|
|
32
|
-
str: '%3Ftest%3Dstr',
|
|
33
|
-
tags: {
|
|
34
|
-
[UNTRUSTED]: [0, 12],
|
|
35
|
-
[WEAK_URL_ENCODED]: [0, 12]
|
|
36
|
-
},
|
|
37
|
-
expected: { [UNTRUSTED]: [0, 8] }
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
str: '?test=str',
|
|
41
|
-
tags: {
|
|
42
|
-
[UNTRUSTED]: [0, 8]
|
|
43
|
-
},
|
|
44
|
-
expected: { [UNTRUSTED]: [0, 8] }
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
str: 'not-tracked',
|
|
48
|
-
}
|
|
49
|
-
].forEach(({ str, tags, expected }) => {
|
|
50
|
-
it('propagates correctly', function () {
|
|
51
|
-
simulateRequestScope(function () {
|
|
52
|
-
const value = tags ? trackString(str, { tags }) : str;
|
|
53
|
-
|
|
54
|
-
const result = unescape(value);
|
|
55
|
-
const strInfo = tracker.getData(result);
|
|
56
|
-
expect(strInfo?.tags).to.deep.equal(expected);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('will not propagate if there is no assess policy in request context', function () {
|
|
62
|
-
simulateRequestScope(function () {
|
|
63
|
-
const value = trackString('%3Ftest%3Dstr');
|
|
64
|
-
const result = unescape(value);
|
|
65
|
-
expect(tracker.getData(result)).to.be.null;
|
|
66
|
-
}, { assess: { policy: null } });
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('will not propagate if there instrumentation is locked', function () {
|
|
70
|
-
simulateRequestScope(function () {
|
|
71
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
72
|
-
const value = trackString('%3Ftest%3Dstr');
|
|
73
|
-
const result = unescape(value);
|
|
74
|
-
expect(tracker.getData(result)).to.be.null;
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const url = require('url');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const sinon = require('sinon');
|
|
6
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
-
|
|
8
|
-
describe('assess dataflow propagation url domain-parsers', function () {
|
|
9
|
-
let core, trackString, simulateRequestScope, tracker;
|
|
10
|
-
|
|
11
|
-
beforeEach(function () {
|
|
12
|
-
({
|
|
13
|
-
core,
|
|
14
|
-
simulateRequestScope,
|
|
15
|
-
trackString
|
|
16
|
-
} = initAssessFixture());
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
tracker = core.assess.dataflow.tracker;
|
|
20
|
-
core.assess.dataflow.propagation.urlInstrumentation.domainParsers.install();
|
|
21
|
-
core.depHooks.resolve.yield(url);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterEach(function () {
|
|
25
|
-
sinon.resetHistory();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
['domainToASCII', 'domainToUnicode'].forEach((method) => {
|
|
29
|
-
it(method, function () {
|
|
30
|
-
simulateRequestScope(function () {
|
|
31
|
-
const notTrackedValue = 'español.com';
|
|
32
|
-
const trackedValue = trackString('español.com', { tags: { untrusted: [0, 2] } });
|
|
33
|
-
|
|
34
|
-
const notTrackedResult = url[method](notTrackedValue);
|
|
35
|
-
const notTrackedStrInfo = tracker.getData(notTrackedResult);
|
|
36
|
-
|
|
37
|
-
const trackedResult = url[method](trackedValue);
|
|
38
|
-
const trackedStrInfo = tracker.getData(trackedResult);
|
|
39
|
-
|
|
40
|
-
expect(notTrackedStrInfo).to.be.null;
|
|
41
|
-
expect(trackedStrInfo?.tags).to.deep.equal({ untrusted: [0, trackedStrInfo?.value.length - 1] });
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('will not propagate if there is no assess store in request context', function () {
|
|
47
|
-
simulateRequestScope(function () {
|
|
48
|
-
const value = trackString('foo');
|
|
49
|
-
const result = url.domainToASCII(value);
|
|
50
|
-
expect(tracker.getData(result)).to.be.null;
|
|
51
|
-
}, { assess: { policy: null } });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('will not propagate if there instrumentation is locked', function () {
|
|
55
|
-
simulateRequestScope(function () {
|
|
56
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
57
|
-
const value = trackString('foo');
|
|
58
|
-
const result = url.domainToUnicode(value);
|
|
59
|
-
expect(tracker.getData(result)).to.be.null;
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
});
|