@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,513 +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 split', function () {
|
|
8
|
-
let core, simulateRequestScope, trackString, tracker;
|
|
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
|
-
sinon.spy(tracker, 'track');
|
|
20
|
-
|
|
21
|
-
core.assess.dataflow.propagation.stringInstrumentation.substring.install();
|
|
22
|
-
core.assess.dataflow.propagation.stringInstrumentation.split.install();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(function () {
|
|
26
|
-
tracker.track.restore();
|
|
27
|
-
core.assess.dataflow.propagation.stringInstrumentation.substring.uninstall();
|
|
28
|
-
core.assess.dataflow.propagation.stringInstrumentation.split.uninstall();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line mocha/no-sibling-hooks
|
|
32
|
-
afterEach(function() {
|
|
33
|
-
core.Perf.fromAllToMap('patcher', allPatcher);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
after(function() {
|
|
37
|
-
const stats = core.Perf.getStats(allPatcher);
|
|
38
|
-
for (const [key, { n, totalMicros, mean }] of stats.entries()) {
|
|
39
|
-
console.log(key, n, totalMicros, 'nsec', mean, 'mean');
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('base cases', function () {
|
|
44
|
-
it('normal split on non-tracked string', function () {
|
|
45
|
-
simulateRequestScope(() => {
|
|
46
|
-
const ret = 'foo?foo'.split('?');
|
|
47
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
48
|
-
ret.forEach((str) => {
|
|
49
|
-
expect(tracker.getData(str)).to.be.null;
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('regex split on non-tracked string', function () {
|
|
55
|
-
simulateRequestScope(() => {
|
|
56
|
-
const ret = 'foo?foo'.split(/\?/);
|
|
57
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
58
|
-
ret.forEach((str) => {
|
|
59
|
-
expect(tracker.getData(str)).to.be.null;
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('array split on non-tracked string', function () {
|
|
65
|
-
simulateRequestScope(() => {
|
|
66
|
-
const ret = 'foo?,?foo'.split(['?', '?']);
|
|
67
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
68
|
-
ret.forEach((str) => {
|
|
69
|
-
expect(tracker.getData(str)).to.be.null;
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('apply split on non-tracked string', function () {
|
|
75
|
-
simulateRequestScope(() => {
|
|
76
|
-
const ret = String.prototype.split.apply('foo?foo', ['?']);
|
|
77
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
78
|
-
ret.forEach((str) => {
|
|
79
|
-
expect(tracker.getData(str)).to.be.null;
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('limited split on non-tracked string', function () {
|
|
85
|
-
simulateRequestScope(() => {
|
|
86
|
-
const ret = 'foo?foo?foo'.split('?', 2);
|
|
87
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
88
|
-
ret.forEach((str) => {
|
|
89
|
-
expect(tracker.getData(str)).to.be.null;
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('split on empty string', function () {
|
|
95
|
-
simulateRequestScope(() => {
|
|
96
|
-
const ret = ''.split('?');
|
|
97
|
-
expect(ret).to.deep.equal(['']);
|
|
98
|
-
expect(tracker.getData(ret[0])).to.be.null;
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('split on object', function () {
|
|
103
|
-
simulateRequestScope(() => {
|
|
104
|
-
const ret = String.prototype.split.apply({ foo: 'foo' }, ['foo']);
|
|
105
|
-
expect(ret).to.deep.equal(['[object Object]']);
|
|
106
|
-
expect(tracker.getData(ret[0])).to.be.null;
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('undefined/empty separators', function () {
|
|
112
|
-
[
|
|
113
|
-
[],
|
|
114
|
-
[undefined],
|
|
115
|
-
[null]
|
|
116
|
-
].forEach((rest) => {
|
|
117
|
-
it(`handles ${rest[0]} separator`, function () {
|
|
118
|
-
simulateRequestScope(() => {
|
|
119
|
-
const extern = trackString('foo');
|
|
120
|
-
const ret = extern.split(rest[0]);
|
|
121
|
-
expect(ret).to.deep.equal(['foo']);
|
|
122
|
-
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
123
|
-
UNTRUSTED: [0, 2]
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('handles empty separator for a fully tracked string', function () {
|
|
130
|
-
simulateRequestScope(() => {
|
|
131
|
-
const extern = trackString('foo');
|
|
132
|
-
const ret = extern.split('');
|
|
133
|
-
expect(ret).to.deep.equal(['f', 'o', 'o']);
|
|
134
|
-
ret.forEach((str) => {
|
|
135
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
136
|
-
UNTRUSTED: [0, 0]
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('handles empty separator for a partially tracked string', function () {
|
|
143
|
-
simulateRequestScope(() => {
|
|
144
|
-
const extern = trackString('foo', {
|
|
145
|
-
tags: {
|
|
146
|
-
UNTRUSTED: [1, 1]
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
const ret = extern.split('');
|
|
150
|
-
expect(ret).to.deep.equal(['f', 'o', 'o']);
|
|
151
|
-
expect(tracker.getData(ret[0])).to.be.null;
|
|
152
|
-
expect(tracker.getData(ret[1]).tags).to.deep.equal({
|
|
153
|
-
UNTRUSTED: [0, 0]
|
|
154
|
-
});
|
|
155
|
-
expect(tracker.getData(ret[2])).to.be.null;
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('handles empty separator for a tracked string with different named ranges', function () {
|
|
160
|
-
simulateRequestScope(() => {
|
|
161
|
-
const extern = trackString('foo', {
|
|
162
|
-
tags: {
|
|
163
|
-
foo: [0, 0],
|
|
164
|
-
bar: [1, 2]
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
const ret = extern.split('');
|
|
168
|
-
expect(ret).to.deep.equal(['f', 'o', 'o']);
|
|
169
|
-
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
170
|
-
foo: [0, 0]
|
|
171
|
-
});
|
|
172
|
-
expect(tracker.getData(ret[1]).tags).to.deep.equal({
|
|
173
|
-
bar: [0, 0]
|
|
174
|
-
});
|
|
175
|
-
expect(tracker.getData(ret[2]).tags).to.deep.equal({
|
|
176
|
-
bar: [0, 0]
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('string separators', function () {
|
|
183
|
-
|
|
184
|
-
it('keeps track of an unsplit string', function () {
|
|
185
|
-
simulateRequestScope(() => {
|
|
186
|
-
const extern = trackString('foo', {
|
|
187
|
-
tags: {
|
|
188
|
-
untrusted: [0, 2]
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
const ret = extern.split('?');
|
|
192
|
-
expect(ret).to.deep.equal(['foo']);
|
|
193
|
-
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
194
|
-
untrusted: [0, 2]
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('handles split limit of 0', function () {
|
|
200
|
-
simulateRequestScope(() => {
|
|
201
|
-
const extern = trackString('foo?foo?foo', {
|
|
202
|
-
tags: {
|
|
203
|
-
untrusted: [0, 10]
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
const ret = extern.split('?', 0);
|
|
207
|
-
expect(ret).to.deep.equal([]);
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it('handles non-zero split limit', function () {
|
|
212
|
-
simulateRequestScope(() => {
|
|
213
|
-
const extern = trackString('foo?foo?foo');
|
|
214
|
-
const ret = extern.split('?', 2);
|
|
215
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
216
|
-
ret.forEach((str) => {
|
|
217
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
218
|
-
UNTRUSTED: [0, 2]
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
it('keeps track of a tracked split string', function () {
|
|
225
|
-
simulateRequestScope(() => {
|
|
226
|
-
const extern = trackString('foo?foo?foo');
|
|
227
|
-
const ret = extern.split('?');
|
|
228
|
-
expect(ret).to.deep.equal(['foo', 'foo', 'foo']);
|
|
229
|
-
|
|
230
|
-
ret.forEach((str) => {
|
|
231
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
232
|
-
UNTRUSTED: [0, 2]
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('does not call tracker.track if the split result is the original string', function () {
|
|
239
|
-
simulateRequestScope(() => {
|
|
240
|
-
const extern = trackString('foo?foo?foo');
|
|
241
|
-
tracker.track.resetHistory();
|
|
242
|
-
|
|
243
|
-
const ret = extern.split('!');
|
|
244
|
-
expect(ret).to.deep.equal(['foo?foo?foo']);
|
|
245
|
-
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
246
|
-
UNTRUSTED: [0, 10]
|
|
247
|
-
});
|
|
248
|
-
expect(tracker.track).to.not.have.been.called;
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('keeps track of a tracked split string (long separator)', function () {
|
|
253
|
-
simulateRequestScope(() => {
|
|
254
|
-
const extern = trackString('foo?foo?foo');
|
|
255
|
-
const ret = extern.split('?foo?');
|
|
256
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
257
|
-
ret.forEach((str) => {
|
|
258
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
259
|
-
UNTRUSTED: [0, 2]
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
it('keeps track of a partially tracked split string', function () {
|
|
266
|
-
simulateRequestScope(() => {
|
|
267
|
-
const extern = trackString('foo?foo?foo', {
|
|
268
|
-
tags: {
|
|
269
|
-
untrusted: [0, 2, 8, 10]
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
const ret = extern.split('?');
|
|
273
|
-
expect(ret).to.deep.equal(['foo', 'foo', 'foo']);
|
|
274
|
-
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
275
|
-
untrusted: [0, 2]
|
|
276
|
-
});
|
|
277
|
-
expect(tracker.getData(ret[1])).to.be.null;
|
|
278
|
-
expect(tracker.getData(ret[2]).tags).to.deep.equal({
|
|
279
|
-
untrusted: [0, 2]
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it('keeps track of a tracked split string with different tag range names', function () {
|
|
285
|
-
simulateRequestScope(() => {
|
|
286
|
-
const extern = trackString('foo?foo?foo', {
|
|
287
|
-
tags: {
|
|
288
|
-
untrusted: [0, 2, 8, 10],
|
|
289
|
-
foo: [0, 2],
|
|
290
|
-
bar: [4, 10]
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
const ret = extern.split('?');
|
|
294
|
-
expect(ret).to.deep.equal(['foo', 'foo', 'foo']);
|
|
295
|
-
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
296
|
-
untrusted: [0, 2],
|
|
297
|
-
foo: [0, 2]
|
|
298
|
-
});
|
|
299
|
-
expect(tracker.getData(ret[1]).tags).to.deep.equal({
|
|
300
|
-
bar: [0, 2]
|
|
301
|
-
});
|
|
302
|
-
expect(tracker.getData(ret[2]).tags).to.deep.equal({
|
|
303
|
-
untrusted: [0, 2],
|
|
304
|
-
bar: [0, 2]
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('keeps track of tracked separators', function () {
|
|
310
|
-
simulateRequestScope(() => {
|
|
311
|
-
|
|
312
|
-
const extern = trackString('foo?foo', {
|
|
313
|
-
tags: {
|
|
314
|
-
untrusted: [0, 10]
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
const trackedSep = trackString('?', {
|
|
319
|
-
tags: {
|
|
320
|
-
untrusted: [0, 0]
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
const ret = extern.split(trackedSep);
|
|
324
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
325
|
-
ret.forEach((str) => {
|
|
326
|
-
expect(tracker.getData(str).args).to.deep.equal([{
|
|
327
|
-
value: '?', tracked: true
|
|
328
|
-
}]);
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('reports result as a comma delimited list', function () {
|
|
334
|
-
simulateRequestScope(() => {
|
|
335
|
-
const extern = trackString('foo?foo?foo', {
|
|
336
|
-
tags: {
|
|
337
|
-
untrusted: [0, 10]
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
const ret = extern.split('?');
|
|
341
|
-
expect(ret).to.deep.equal(['foo', 'foo', 'foo']);
|
|
342
|
-
ret.forEach((str) => {
|
|
343
|
-
expect(tracker.getData(str).result).to.deep.equal({
|
|
344
|
-
value: 'foo',
|
|
345
|
-
tracked: true
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
describe('regEx separators', function () {
|
|
353
|
-
it('keeps track of a tracked split string separated by a RegEx', function () {
|
|
354
|
-
simulateRequestScope(() => {
|
|
355
|
-
const extern = trackString('foo?foo?foo', {
|
|
356
|
-
tags: {
|
|
357
|
-
untrusted: [0, 10]
|
|
358
|
-
}
|
|
359
|
-
});
|
|
360
|
-
const ret = extern.split(/\?/g);
|
|
361
|
-
expect(ret).to.deep.equal(['foo', 'foo', 'foo']);
|
|
362
|
-
ret.forEach((str) => {
|
|
363
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
364
|
-
untrusted: [0, 2]
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
it('keeps track of a tracked split string separated by a more complex RegEx', function () {
|
|
371
|
-
simulateRequestScope(() => {
|
|
372
|
-
const extern = trackString('foo1foo2foo', {
|
|
373
|
-
tags: {
|
|
374
|
-
untrusted: [0, 10]
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
const ret = extern.split(/\d/g);
|
|
378
|
-
expect(ret).to.deep.equal(['foo', 'foo', 'foo']);
|
|
379
|
-
ret.forEach((str) => {
|
|
380
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
381
|
-
untrusted: [0, 2]
|
|
382
|
-
});
|
|
383
|
-
});
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it('keeps track of a tracked split string separated by a RegEx containing capturing parentheses', function () {
|
|
388
|
-
simulateRequestScope(() => {
|
|
389
|
-
const extern = trackString('foo?foo?foo', {
|
|
390
|
-
tags: {
|
|
391
|
-
untrusted: [0, 10]
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
const ret = extern.split(/(\?)/g);
|
|
395
|
-
expect(ret).to.deep.equal(['foo', '?', 'foo', '?', 'foo']);
|
|
396
|
-
ret.forEach((str) => {
|
|
397
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
398
|
-
untrusted: [0, str.length - 1]
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
describe('complex/edge cases', function () {
|
|
406
|
-
|
|
407
|
-
it('handles non-english characters', function () {
|
|
408
|
-
simulateRequestScope(() => {
|
|
409
|
-
const extern = trackString('fꙨꙨꙮፈar', {
|
|
410
|
-
tags: {
|
|
411
|
-
untrusted: [0, 10]
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
const ret = extern.split('ꙮ');
|
|
415
|
-
expect(ret).to.deep.equal(['fꙨꙨ', 'ፈar']);
|
|
416
|
-
ret.forEach((str) => {
|
|
417
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
418
|
-
untrusted: [0, 2]
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it('handles multiple calls to split and keeps track of tracked strings with different named ranges', function () {
|
|
425
|
-
simulateRequestScope(() => {
|
|
426
|
-
const extern = trackString('foo?foo?foo', {
|
|
427
|
-
tags: {
|
|
428
|
-
untrusted: [0, 8],
|
|
429
|
-
foo: [0, 2],
|
|
430
|
-
bar: [0, 6],
|
|
431
|
-
foobar: [9, 10]
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
let [foo1, foo2, foo3] = [...extern.split('?')];
|
|
435
|
-
foo1 = foo1.split();
|
|
436
|
-
foo2 = foo2.split('');
|
|
437
|
-
foo3 = foo3.split(/(o)/g);
|
|
438
|
-
|
|
439
|
-
expect(foo1).to.deep.equal(['foo']);
|
|
440
|
-
expect(foo2).to.deep.equal(['f', 'o', 'o']);
|
|
441
|
-
expect(foo3).to.deep.equal(['f', 'o', '', 'o', '']);
|
|
442
|
-
|
|
443
|
-
expect(tracker.getData(foo1[0]).tags).to.deep.equal({
|
|
444
|
-
untrusted: [0, 2],
|
|
445
|
-
foo: [0, 2],
|
|
446
|
-
bar: [0, 2]
|
|
447
|
-
});
|
|
448
|
-
foo2.forEach((char) => {
|
|
449
|
-
expect(tracker.getData(char).tags).to.deep.equal({
|
|
450
|
-
untrusted: [0, 0],
|
|
451
|
-
bar: [0, 0]
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
expect(tracker.getData(foo3[0]).tags).to.deep.equal({
|
|
455
|
-
untrusted: [0, 0]
|
|
456
|
-
});
|
|
457
|
-
expect(tracker.getData(foo3[1]).tags).to.deep.equal({
|
|
458
|
-
foobar: [0, 0]
|
|
459
|
-
});
|
|
460
|
-
expect(tracker.getData(foo3[3]).tags).to.deep.equal({
|
|
461
|
-
foobar: [0, 0]
|
|
462
|
-
});
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it('custom splitter returns tracked strings', function () {
|
|
467
|
-
simulateRequestScope(() => {
|
|
468
|
-
const customSplit = {
|
|
469
|
-
[Symbol.split](str) {
|
|
470
|
-
return [str, str];
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
const extern = trackString('foo', {
|
|
474
|
-
tags: {
|
|
475
|
-
untrusted: [0, 2]
|
|
476
|
-
}
|
|
477
|
-
});
|
|
478
|
-
const ret = extern.split(customSplit);
|
|
479
|
-
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
480
|
-
ret.forEach((str) => {
|
|
481
|
-
expect(tracker.getData(str).tags).to.deep.equal({
|
|
482
|
-
untrusted: [0, 2]
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
it('custom splitter calls split', function () {
|
|
489
|
-
simulateRequestScope(() => {
|
|
490
|
-
const onlySplitFoo = {
|
|
491
|
-
[Symbol.split](str) {
|
|
492
|
-
if (str.includes('foo')) {
|
|
493
|
-
return str.split('?');
|
|
494
|
-
} else {
|
|
495
|
-
return [];
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
const extern = trackString('foo?bar', {
|
|
500
|
-
tags: {
|
|
501
|
-
untrusted: [0, 2]
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
const ret = extern.split(onlySplitFoo);
|
|
505
|
-
expect(ret).to.deep.equal(['foo', 'bar']);
|
|
506
|
-
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
507
|
-
untrusted: [0, 2]
|
|
508
|
-
});
|
|
509
|
-
expect(tracker.getData(ret[1])).to.be.null;
|
|
510
|
-
});
|
|
511
|
-
});
|
|
512
|
-
});
|
|
513
|
-
});
|