@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,601 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { inspect } = require('util');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow propagation string replace', 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
|
-
|
|
20
|
-
core.assess.dataflow.propagation.stringInstrumentation.substring.install();
|
|
21
|
-
core.assess.dataflow.propagation.stringInstrumentation.replace.install();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterEach(function () {
|
|
25
|
-
core.assess.dataflow.propagation.stringInstrumentation.replace.uninstall();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line mocha/no-sibling-hooks
|
|
29
|
-
afterEach(function() {
|
|
30
|
-
core.Perf.fromAllToMap('patcher', allPatcher);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
after(function() {
|
|
34
|
-
const stats = core.Perf.getStats(allPatcher);
|
|
35
|
-
for (const [key, { n, totalMicros, mean }] of stats.entries()) {
|
|
36
|
-
console.log(key, n, totalMicros, 'nsec', mean, 'mean');
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
['string', 'function'].forEach((replacerType) => {
|
|
41
|
-
function getReplacement(replacerType, replacement) {
|
|
42
|
-
return replacerType === 'function' ? () => replacement : replacement;
|
|
43
|
-
}
|
|
44
|
-
describe(`string-arg custom ${replacerType} replacer`, function () {
|
|
45
|
-
it('untracked string replace with untracked string', function () {
|
|
46
|
-
simulateRequestScope(() => {
|
|
47
|
-
const val = '?bcd';
|
|
48
|
-
const ret = val.replace('?', getReplacement(replacerType, 'a'));
|
|
49
|
-
expect(ret).to.equal('abcd');
|
|
50
|
-
expect(tracker.getData(ret)).to.be.null;
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
[
|
|
55
|
-
[],
|
|
56
|
-
[undefined],
|
|
57
|
-
[null]
|
|
58
|
-
].forEach((rest) => {
|
|
59
|
-
it(`full replacement with nullish value: ${inspect(rest[0])}`, function () {
|
|
60
|
-
simulateRequestScope(() => {
|
|
61
|
-
const val = 'abcd';
|
|
62
|
-
const extern = trackString(val);
|
|
63
|
-
const ret = extern.replace(val, getReplacement(replacerType, rest[0]));
|
|
64
|
-
expect(ret).to.equal(String(rest[0]));
|
|
65
|
-
expect(tracker.getData(ret)).to.be.null;
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('empty match string', function () {
|
|
71
|
-
simulateRequestScope(() => {
|
|
72
|
-
const extern = trackString('bcde', {
|
|
73
|
-
tags: {
|
|
74
|
-
UNTRUSTED: [0, 3]
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
const ret = extern.replace('', getReplacement(replacerType, 'a'));
|
|
78
|
-
expect(ret).to.equal('abcde');
|
|
79
|
-
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
80
|
-
UNTRUSTED: [1, 4]
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('empty replacer string', function () {
|
|
86
|
-
simulateRequestScope(() => {
|
|
87
|
-
const extern = trackString('abcd', {
|
|
88
|
-
tags: {
|
|
89
|
-
UNTRUSTED: [0, 3]
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
const ret = extern.replace('', getReplacement(replacerType, ''));
|
|
93
|
-
expect(ret).to.equal('abcd');
|
|
94
|
-
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
95
|
-
UNTRUSTED: [0, 3]
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('untracked string replaced with tracked', function () {
|
|
101
|
-
simulateRequestScope(() => {
|
|
102
|
-
const val = '?bcd';
|
|
103
|
-
const replacement = trackString('a', {
|
|
104
|
-
tags: {
|
|
105
|
-
UNTRUSTED: [0, 0]
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
const ret = val.replace('?', getReplacement(replacerType, replacement));
|
|
109
|
-
expect(ret).to.equal('abcd');
|
|
110
|
-
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
111
|
-
UNTRUSTED: [0, 0]
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('does not track return with all tracked values removed', function () {
|
|
117
|
-
simulateRequestScope(() => {
|
|
118
|
-
const extern = trackString('_TT_', {
|
|
119
|
-
tags: {
|
|
120
|
-
UNTRUSTED: [1, 2]
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
const ret = extern.replace('TT', getReplacement(replacerType, '__'));
|
|
124
|
-
expect(ret).to.equal('____');
|
|
125
|
-
expect(tracker.getData(ret)).to.be.null;
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('tracks result highspan', function () {
|
|
130
|
-
simulateRequestScope(() => {
|
|
131
|
-
const extern = trackString('_TT_', {
|
|
132
|
-
tags: {
|
|
133
|
-
UNTRUSTED: [1, 2],
|
|
134
|
-
history: [{ mock: 'sourceEvent' }]
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
const ret = extern.replace('_T', getReplacement(replacerType, '__'));
|
|
138
|
-
expect(ret).to.equal('__T_');
|
|
139
|
-
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
140
|
-
UNTRUSTED: [2, 2]
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
it('tracks result lospan', function () {
|
|
146
|
-
simulateRequestScope(() => {
|
|
147
|
-
const extern = trackString('_TT_', {
|
|
148
|
-
tags: {
|
|
149
|
-
UNTRUSTED: [1, 2],
|
|
150
|
-
history: [{ mock: 'sourceEvent' }]
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
const ret = extern.replace('T_', getReplacement(replacerType, '__'));
|
|
154
|
-
expect(ret).to.equal('_T__');
|
|
155
|
-
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
156
|
-
UNTRUSTED: [1, 1]
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('tracks result highspan tracked replacement', function () {
|
|
162
|
-
simulateRequestScope(() => {
|
|
163
|
-
const extern = trackString('_TT_', {
|
|
164
|
-
tags: {
|
|
165
|
-
UNTRUSTED: [1, 2]
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
const replacement = trackString('TT', {
|
|
169
|
-
tags: {
|
|
170
|
-
UNTRUSTED: [0, 1]
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
const ret = extern.replace('T_', getReplacement(replacerType, replacement));
|
|
174
|
-
expect(ret).to.equal('_TTT');
|
|
175
|
-
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
176
|
-
UNTRUSTED: [1, 3]
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('keeps track of multiple tag ranges', function () {
|
|
182
|
-
simulateRequestScope(() => {
|
|
183
|
-
const extern = trackString('a?cd', {
|
|
184
|
-
tags: {
|
|
185
|
-
UNTRUSTED: [0, 3],
|
|
186
|
-
foo: [1, 2]
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
const replacement = trackString('b', {
|
|
190
|
-
tags: {
|
|
191
|
-
foo: [0, 0],
|
|
192
|
-
bar: [0, 0]
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
const ret = extern.replace('?', getReplacement(replacerType, replacement));
|
|
196
|
-
expect(ret).to.equal('abcd');
|
|
197
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
198
|
-
UNTRUSTED: [0, 0, 2, 3],
|
|
199
|
-
foo: [1, 2],
|
|
200
|
-
bar: [1, 1]
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
describe(`regEx custom ${replacerType} replacer`, function () {
|
|
207
|
-
it('keeps track of tagged strings not replaced', function () {
|
|
208
|
-
simulateRequestScope(() => {
|
|
209
|
-
const extern = trackString('abcd');
|
|
210
|
-
const ret = extern.replace(/e/g, getReplacement(replacerType, 'e'));
|
|
211
|
-
expect(ret).to.equal('abcd');
|
|
212
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
213
|
-
UNTRUSTED: [0, 3]
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('keeps track of tagged strings replaced by untracked strings', function () {
|
|
219
|
-
simulateRequestScope(() => {
|
|
220
|
-
const extern = trackString('a?a?');
|
|
221
|
-
const ret = extern.replace(/\?/g, getReplacement(replacerType, 'b'));
|
|
222
|
-
expect(ret).to.equal('abab');
|
|
223
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
224
|
-
UNTRUSTED: [0, 0, 2, 2]
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('keeps track of tagged strings replaced by larger untracked strings', function () {
|
|
230
|
-
simulateRequestScope(() => {
|
|
231
|
-
const extern = trackString('a?a?');
|
|
232
|
-
const ret = extern.replace(/\?/g, getReplacement(replacerType, 'bbb'));
|
|
233
|
-
expect(ret).to.equal('abbbabbb');
|
|
234
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
235
|
-
UNTRUSTED: [0, 0, 4, 4]
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it('keeps track of tagged strings replaced by smaller untracked strings', function () {
|
|
241
|
-
simulateRequestScope(() => {
|
|
242
|
-
const extern = trackString('a???a???');
|
|
243
|
-
const ret = extern.replace(/\?\?\?/g, getReplacement(replacerType, 'b'));
|
|
244
|
-
expect(ret).to.equal('abab');
|
|
245
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
246
|
-
UNTRUSTED: [0, 0, 2, 2]
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('keeps track of tagged strings replaced by tracked strings', function () {
|
|
252
|
-
simulateRequestScope(() => {
|
|
253
|
-
const extern = trackString('a?a?', {
|
|
254
|
-
tags: {
|
|
255
|
-
UNTRUSTED: [0, 3]
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
const replacement = trackString('b', {
|
|
259
|
-
tags: {
|
|
260
|
-
UNTRUSTED: [0, 0]
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
const ret = extern.replace(/\?/g, getReplacement(replacerType, replacement));
|
|
264
|
-
expect(ret).to.equal('abab');
|
|
265
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
266
|
-
UNTRUSTED: [0, 3]
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('keeps track of tagged strings replaced by larger tracked strings', function () {
|
|
272
|
-
simulateRequestScope(() => {
|
|
273
|
-
const extern = trackString('a?a?', {
|
|
274
|
-
tags: {
|
|
275
|
-
UNTRUSTED: [0, 3]
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
const replacement = trackString('bbb', {
|
|
279
|
-
tags: {
|
|
280
|
-
UNTRUSTED: [0, 2]
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
const ret = extern.replace(/\?/g, getReplacement(replacerType, replacement));
|
|
284
|
-
expect(ret).to.equal('abbbabbb');
|
|
285
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
286
|
-
UNTRUSTED: [0, 7]
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it('keeps track of tagged strings replaced by smaller tracked strings', function () {
|
|
292
|
-
simulateRequestScope(() => {
|
|
293
|
-
const extern = trackString('a???a???', {
|
|
294
|
-
tags: {
|
|
295
|
-
UNTRUSTED: [0, 7]
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
const replacement = trackString('b', {
|
|
299
|
-
tags: {
|
|
300
|
-
UNTRUSTED: [0, 0]
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
const ret = extern.replace(/\?\?\?/g, getReplacement(replacerType, replacement));
|
|
304
|
-
expect(ret).to.equal('abab');
|
|
305
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
306
|
-
UNTRUSTED: [0, 3]
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it('keeps track of multiple tag ranges', function () {
|
|
312
|
-
simulateRequestScope(() => {
|
|
313
|
-
const extern = trackString('a??a??a', {
|
|
314
|
-
tags: {
|
|
315
|
-
UNTRUSTED: [0, 6],
|
|
316
|
-
foo: [0, 2],
|
|
317
|
-
bar: [4, 6]
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
const replacement = trackString('b', {
|
|
321
|
-
tags: {
|
|
322
|
-
foo: [0, 0],
|
|
323
|
-
bar: [0, 0]
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
const ret = extern.replace(/\?/g, replacement);
|
|
327
|
-
expect(ret).to.equal('abbabba');
|
|
328
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
329
|
-
UNTRUSTED: [0, 0, 3, 3, 6, 6],
|
|
330
|
-
foo: [0, 2, 4, 5],
|
|
331
|
-
bar: [1, 2, 4, 6]
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
describe('complex/edge cases', function () {
|
|
339
|
-
it('replacer function returns a non-string', function () {
|
|
340
|
-
simulateRequestScope(() => {
|
|
341
|
-
const extern = trackString('123?', {
|
|
342
|
-
tags: {
|
|
343
|
-
UNTRUSTED: [0, 3]
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
const ret = extern.replace('?', (match, offset) => offset + 1);
|
|
347
|
-
expect(ret).to.equal('1234');
|
|
348
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
349
|
-
UNTRUSTED: [0, 2]
|
|
350
|
-
});
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('replacer operates on capture groups', function () {
|
|
355
|
-
simulateRequestScope(() => {
|
|
356
|
-
const extern = trackString('AaaBbbCcc', {
|
|
357
|
-
tags: {
|
|
358
|
-
UNTRUSTED: [0, 8],
|
|
359
|
-
groupOne: [0, 2],
|
|
360
|
-
groupTwo: [3, 5],
|
|
361
|
-
groupThree: [6, 8]
|
|
362
|
-
}
|
|
363
|
-
});
|
|
364
|
-
const ret = extern.replace(/(A)|(B)|(C)/g, (match => match.toLowerCase()));
|
|
365
|
-
expect(ret).to.equal('aaabbbccc');
|
|
366
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
367
|
-
UNTRUSTED: [1, 2, 4, 5, 7, 8],
|
|
368
|
-
groupOne: [1, 2],
|
|
369
|
-
groupTwo: [4, 5],
|
|
370
|
-
groupThree: [7, 8]
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
it('handles edge case where we have a function that sets the replacement to be a special value',
|
|
376
|
-
function () {
|
|
377
|
-
simulateRequestScope(() => {
|
|
378
|
-
let counter = 0;
|
|
379
|
-
const extern = trackString('SELECT ? FROM ?', {
|
|
380
|
-
tags: {
|
|
381
|
-
UNTRUSTED: [0, 14],
|
|
382
|
-
groupOne: [9, 12],
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
const ret = extern.replace(/(\?)/g, () => `$${counter++}`);
|
|
386
|
-
expect(ret).to.equal('SELECT $0 FROM $1');
|
|
387
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
388
|
-
UNTRUSTED: [0, 6, 9, 14],
|
|
389
|
-
groupOne: [10, 13],
|
|
390
|
-
});
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
it('replacer operates on named capture groups', function () {
|
|
395
|
-
simulateRequestScope(() => {
|
|
396
|
-
const extern = trackString('AaaBbbCcc', {
|
|
397
|
-
tags: {
|
|
398
|
-
UNTRUSTED: [0, 8],
|
|
399
|
-
groupOne: [0, 2],
|
|
400
|
-
groupTwo: [3, 5],
|
|
401
|
-
groupThree: [6, 8]
|
|
402
|
-
}
|
|
403
|
-
});
|
|
404
|
-
const ret = extern.replace(/(?<g1>A)|(?<g2>B)|(?<g3>C)/g, (match => match.toLowerCase()));
|
|
405
|
-
expect(ret).to.equal('aaabbbccc');
|
|
406
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
407
|
-
UNTRUSTED: [1, 2, 4, 5, 7, 8],
|
|
408
|
-
groupOne: [1, 2],
|
|
409
|
-
groupTwo: [4, 5],
|
|
410
|
-
groupThree: [7, 8]
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it('keeps track of multiple overlapping tag ranges over multiple calls', function () {
|
|
416
|
-
simulateRequestScope(() => {
|
|
417
|
-
let ret;
|
|
418
|
-
const extern = trackString('a??cd?g?', {
|
|
419
|
-
tags: {
|
|
420
|
-
UNTRUSTED: [0, 7],
|
|
421
|
-
foo: [0, 2],
|
|
422
|
-
bar: [1, 3],
|
|
423
|
-
fizz: [4, 7],
|
|
424
|
-
buzz: [1, 6]
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
const replB = trackString('b', {
|
|
428
|
-
tags: {
|
|
429
|
-
foo: [0, 0],
|
|
430
|
-
bar: [0, 0]
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
const replEf = trackString('ef', {
|
|
434
|
-
tags: {
|
|
435
|
-
fizz: [0, 0],
|
|
436
|
-
buzz: [1, 1]
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
const replH = trackString('h', {
|
|
440
|
-
tags: {
|
|
441
|
-
foobar: [0, 0]
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
ret = extern.replace('??', replB);
|
|
445
|
-
ret = ret.replace('?', () => replEf);
|
|
446
|
-
ret = ret.replace(/\?/g, replH);
|
|
447
|
-
expect(ret).to.be.equal('abcdefgh');
|
|
448
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
449
|
-
UNTRUSTED: [0, 0, 2, 3, 6, 6],
|
|
450
|
-
foo: [0, 1],
|
|
451
|
-
bar: [1, 2],
|
|
452
|
-
fizz: [3, 4, 6, 6],
|
|
453
|
-
buzz: [2, 3, 5, 6],
|
|
454
|
-
foobar: [7, 7]
|
|
455
|
-
});
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
it('keeps track of replacement history', function () {
|
|
460
|
-
simulateRequestScope(() => {
|
|
461
|
-
const extern = trackString('aa??');
|
|
462
|
-
const replacementOne = trackString('bb');
|
|
463
|
-
const replacementTwo = trackString('cc');
|
|
464
|
-
const replacements = ['', '', replacementOne, replacementTwo];
|
|
465
|
-
const ret = extern.replace(/\?/g, (match, offset) => replacements[offset]);
|
|
466
|
-
expect(ret).to.equal('aabbcc');
|
|
467
|
-
expect(tracker.getData(ret).history.length).to.equal(3);
|
|
468
|
-
expect(tracker.getData(ret).history).to.be.like([
|
|
469
|
-
{ value: 'aa??', tags: { UNTRUSTED: [0, 3] } },
|
|
470
|
-
{ value: 'bb', tags: { UNTRUSTED: [0, 1] } },
|
|
471
|
-
{ value: 'cc', tags: { UNTRUSTED: [0, 1] } }
|
|
472
|
-
]);
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
describe('special characters', function () {
|
|
478
|
-
it('replaces and handles $$', function () {
|
|
479
|
-
simulateRequestScope(() => {
|
|
480
|
-
const extern = trackString('foo?foo');
|
|
481
|
-
const ret = extern.replace('?', '$$ $$');
|
|
482
|
-
expect(ret).to.equal('foo$ $foo');
|
|
483
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
484
|
-
UNTRUSTED: [0, 2, 6, 8]
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
it('replaces and handles untracked $&', function () {
|
|
490
|
-
simulateRequestScope(() => {
|
|
491
|
-
const extern = trackString('foo bar');
|
|
492
|
-
const ret = extern.replace('bar', '[$&]-[$&]');
|
|
493
|
-
expect(ret).to.equal('foo [bar]-[bar]');
|
|
494
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
495
|
-
UNTRUSTED: [0, 3]
|
|
496
|
-
});
|
|
497
|
-
});
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
it('replaces and handles tracked $&', function () {
|
|
501
|
-
simulateRequestScope(() => {
|
|
502
|
-
const extern = trackString('foo bar');
|
|
503
|
-
const replacement = trackString('bar');
|
|
504
|
-
const ret = extern.replace(replacement, '[$&]-[$&]');
|
|
505
|
-
expect(ret).to.equal('foo [bar]-[bar]');
|
|
506
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
507
|
-
UNTRUSTED: [0, 3, 5, 7, 11, 13]
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
it('replaces and handles $`', function () {
|
|
513
|
-
simulateRequestScope(() => {
|
|
514
|
-
const extern = trackString('foobar');
|
|
515
|
-
const ret = extern.replace('bar', '$`$`');
|
|
516
|
-
expect(ret).to.equal('foofoofoo');
|
|
517
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
518
|
-
UNTRUSTED: [0, 8]
|
|
519
|
-
});
|
|
520
|
-
});
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
it('replaces and handles $\'', function () {
|
|
524
|
-
simulateRequestScope(() => {
|
|
525
|
-
const extern = trackString('foobar');
|
|
526
|
-
const ret = extern.replace('foo', '$\'$\'');
|
|
527
|
-
expect(ret).to.equal('barbarbar');
|
|
528
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
529
|
-
UNTRUSTED: [0, 8]
|
|
530
|
-
});
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
it('replaces and handles $N', function () {
|
|
535
|
-
simulateRequestScope(() => {
|
|
536
|
-
const extern = trackString('aabbcc');
|
|
537
|
-
const ret = extern.replace(/(aa)(bb)/g, '$2$1');
|
|
538
|
-
expect(ret).to.equal('bbaacc');
|
|
539
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
540
|
-
UNTRUSTED: [4, 5]
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
|
-
});
|
|
544
|
-
|
|
545
|
-
it('replaces and handles $name', function () {
|
|
546
|
-
simulateRequestScope(() => {
|
|
547
|
-
const extern = trackString('aabbcc');
|
|
548
|
-
const ret = extern.replace(/(?<g1>aa)(?<g2>bb)/g, '$g2$g1');
|
|
549
|
-
expect(ret).to.equal('bbaacc');
|
|
550
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
551
|
-
UNTRUSTED: [4, 5]
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
it('replaces and handles strings containing multiple special characters', function () {
|
|
557
|
-
simulateRequestScope(() => {
|
|
558
|
-
const extern = trackString('aabbcc');
|
|
559
|
-
const ret = extern.replace('bb', '($&)-($\')-($`)');
|
|
560
|
-
expect(ret).to.equal('aa(bb)-(cc)-(aa)cc');
|
|
561
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
562
|
-
UNTRUSTED: [0, 1, 8, 9, 13, 14, 16, 17]
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
it('replaces and handles strings containing multiple special characters that replace multiple strings', function () {
|
|
568
|
-
simulateRequestScope(() => {
|
|
569
|
-
const extern = trackString('aa?bb?cc?');
|
|
570
|
-
const ret = extern.replace(/(\?)/g, '$$$1');
|
|
571
|
-
expect(ret).to.equal('aa$?bb$?cc$?');
|
|
572
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
573
|
-
UNTRUSTED: [0, 1, 4, 5, 8, 9]
|
|
574
|
-
});
|
|
575
|
-
});
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
it('replaces and handles multiple special characters and tracked strings', function () {
|
|
579
|
-
simulateRequestScope(() => {
|
|
580
|
-
const extern = trackString('foobar');
|
|
581
|
-
const replacement = trackString('bar');
|
|
582
|
-
const ret = extern.replace(replacement, '$$$&$$$&');
|
|
583
|
-
expect(ret).to.equal('foo$bar$bar');
|
|
584
|
-
expect(tracker.getData(ret).tags).to.be.deep.equal({
|
|
585
|
-
UNTRUSTED: [0, 2, 4, 6, 8, 10]
|
|
586
|
-
});
|
|
587
|
-
});
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
// example is from shell-quote
|
|
591
|
-
it('replaces and handles special characters of form $\\d when capture group exists or doesn\'t', function() {
|
|
592
|
-
const s = 'http://example.com?a=1&a=2';
|
|
593
|
-
const expected = s.replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, '$1\\$2');
|
|
594
|
-
simulateRequestScope(() => {
|
|
595
|
-
const result = s.replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@[\\\]^`{|}])/g, '$1\\$2');
|
|
596
|
-
// http\://example.com\?a\=1\&a\=2
|
|
597
|
-
expect(result).to.equal(expected);
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
});
|
|
601
|
-
});
|