@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,361 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { inspect } = require('util');
|
|
5
|
+
const { DataflowTag: { UNTRUSTED } } = require('@contrast/common');
|
|
6
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
+
|
|
8
|
+
describe('assess dataflow propagation string match', function () {
|
|
9
|
+
let core, simulateRequestScope, trackString, tracker;
|
|
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.regExpExec.install();
|
|
21
|
+
core.assess.dataflow.propagation.stringInstrumentation.match.install();
|
|
22
|
+
core.assess.dataflow.propagation.stringInstrumentation.substring.install();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(function () {
|
|
26
|
+
core.assess.dataflow.propagation.regExpExec.uninstall();
|
|
27
|
+
core.assess.dataflow.propagation.stringInstrumentation.match.uninstall();
|
|
28
|
+
core.assess.dataflow.propagation.stringInstrumentation.substring.uninstall();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('base cases', function () {
|
|
32
|
+
[
|
|
33
|
+
[],
|
|
34
|
+
[undefined],
|
|
35
|
+
['']
|
|
36
|
+
].forEach((val) => {
|
|
37
|
+
it(`returns empty string match for ${inspect(val[0])}`, function () {
|
|
38
|
+
simulateRequestScope(() => {
|
|
39
|
+
const ret = 'foo'.match(val[0]);
|
|
40
|
+
expect(ret[0]).to.equal('');
|
|
41
|
+
expect(tracker.getData(ret[0])).to.be.null;
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns null when no match is found', function () {
|
|
47
|
+
simulateRequestScope(() => {
|
|
48
|
+
const ret = ''.match('foo');
|
|
49
|
+
expect(ret).to.be.null;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('returns first match string', function () {
|
|
54
|
+
simulateRequestScope(() => {
|
|
55
|
+
const ret = 'foo'.match(/f/);
|
|
56
|
+
expect(ret).to.deep.equal(['f']);
|
|
57
|
+
expect(tracker.getData(ret[0])).to.be.null;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('returns all match strings', function () {
|
|
62
|
+
simulateRequestScope(() => {
|
|
63
|
+
const ret = 'foo'.match(/o/g);
|
|
64
|
+
expect(ret).to.deep.equal(['o', 'o']);
|
|
65
|
+
ret.forEach((val) => {
|
|
66
|
+
expect(tracker.getData(val)).to.be.null;
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('converts string to regex and returns match ', function () {
|
|
72
|
+
simulateRequestScope(() => {
|
|
73
|
+
const ret = 'foo'.match('f');
|
|
74
|
+
expect(ret).to.deep.equal(['f']);
|
|
75
|
+
expect(tracker.getData(ret[0])).to.be.null;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('returns first match string using capture groups', function () {
|
|
80
|
+
simulateRequestScope(() => {
|
|
81
|
+
const ret = 'foo'.match(/(f)|(o)/);
|
|
82
|
+
expect(ret).to.deep.equal(['f', 'f', undefined]);
|
|
83
|
+
expect(ret.groups).to.be.undefined;
|
|
84
|
+
ret.forEach((val) => {
|
|
85
|
+
expect(tracker.getData(val)).to.be.null;
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns first match string using named capture groups', function () {
|
|
91
|
+
simulateRequestScope(() => {
|
|
92
|
+
const ret = 'foo'.match(/(?<foo>f)|(?<bar>o)/);
|
|
93
|
+
expect(ret).to.deep.equal(['f', 'f', undefined]);
|
|
94
|
+
expect(ret.groups.foo).to.equal('f');
|
|
95
|
+
ret.forEach((val) => {
|
|
96
|
+
expect(tracker.getData(val)).to.be.null;
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('returns match from custom matcher', function () {
|
|
102
|
+
simulateRequestScope(() => {
|
|
103
|
+
const ret = 'foo'.match({
|
|
104
|
+
[Symbol.match](_str) {
|
|
105
|
+
return ['foo'];
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
expect(ret).to.deep.equal(['foo']);
|
|
109
|
+
expect(tracker.getData(ret[0])).to.be.null;
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('propagation', function () {
|
|
115
|
+
it('keeps track of tracked first matched string', function () {
|
|
116
|
+
simulateRequestScope(() => {
|
|
117
|
+
const extern = trackString('foobarfoo');
|
|
118
|
+
|
|
119
|
+
const ret = extern.match(/foo/);
|
|
120
|
+
const retFirstArgInfo = tracker.getData(ret[0]);
|
|
121
|
+
|
|
122
|
+
expect(ret).to.deep.equal(['foo']);
|
|
123
|
+
expect(retFirstArgInfo.tags).to.deep.equal({
|
|
124
|
+
[UNTRUSTED]: [0, 2]
|
|
125
|
+
});
|
|
126
|
+
expect(retFirstArgInfo.name).to.equal('String.prototype.match');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('keeps track of tracked of all globally matched strings', function () {
|
|
131
|
+
simulateRequestScope(() => {
|
|
132
|
+
const extern = trackString('foobarfoo');
|
|
133
|
+
|
|
134
|
+
const ret = extern.match(/foo/g);
|
|
135
|
+
|
|
136
|
+
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
137
|
+
ret.forEach((val) => {
|
|
138
|
+
const valInfo = tracker.getData(val);
|
|
139
|
+
|
|
140
|
+
expect(valInfo.tags).to.deep.equal({
|
|
141
|
+
[UNTRUSTED]: [0, 2]
|
|
142
|
+
});
|
|
143
|
+
expect(valInfo.name).to.equal('String.prototype.match');
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('keeps track of partially tracked matched strings', function () {
|
|
149
|
+
simulateRequestScope(() => {
|
|
150
|
+
const extern = trackString('foobarfoo', {
|
|
151
|
+
tags: {
|
|
152
|
+
[UNTRUSTED]: [0, 5]
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const ret = extern.match(/foo/g);
|
|
157
|
+
const retFirstArgInfo = tracker.getData(ret[0]);
|
|
158
|
+
|
|
159
|
+
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
160
|
+
expect(retFirstArgInfo.tags).to.deep.equal({
|
|
161
|
+
[UNTRUSTED]: [0, 2]
|
|
162
|
+
});
|
|
163
|
+
expect(retFirstArgInfo.name).to.equal('String.prototype.match');
|
|
164
|
+
expect(tracker.getData(ret[1])).to.be.null;
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('keeps track of tracked strings with multiple ranges', function () {
|
|
169
|
+
simulateRequestScope(() => {
|
|
170
|
+
const extern = trackString('foobarfoo', {
|
|
171
|
+
tags: {
|
|
172
|
+
foo: [0, 2, 6, 8],
|
|
173
|
+
bar: [3, 5],
|
|
174
|
+
foobar: [0, 5],
|
|
175
|
+
barfoo: [3, 8]
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const ret = extern.match(/foo/g);
|
|
180
|
+
const retFirstArgInfo = tracker.getData(ret[0]);
|
|
181
|
+
const retSecondArgInfo = tracker.getData(ret[1]);
|
|
182
|
+
|
|
183
|
+
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
184
|
+
expect(retFirstArgInfo.tags).to.deep.equal({
|
|
185
|
+
foo: [0, 2],
|
|
186
|
+
foobar: [0, 2]
|
|
187
|
+
});
|
|
188
|
+
expect(retFirstArgInfo.name).to.equal('String.prototype.match');
|
|
189
|
+
expect(retSecondArgInfo.tags).to.deep.equal({
|
|
190
|
+
foo: [0, 2],
|
|
191
|
+
barfoo: [0, 2]
|
|
192
|
+
});
|
|
193
|
+
expect(retSecondArgInfo.name).to.equal('String.prototype.match');
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('empty or full matches', function () {
|
|
198
|
+
it('handles full string matches', function () {
|
|
199
|
+
simulateRequestScope(() => {
|
|
200
|
+
const extern = trackString('foobar');
|
|
201
|
+
|
|
202
|
+
const ret = extern.match(/(?<full>foobar)/);
|
|
203
|
+
const matchInfo = tracker.getData(ret[0]);
|
|
204
|
+
const captrueMatchInfo = tracker.getData(ret[1]);
|
|
205
|
+
const fullGroupInfo = tracker.getData(ret.groups.full);
|
|
206
|
+
|
|
207
|
+
expect(ret).to.deep.equal([
|
|
208
|
+
'foobar',
|
|
209
|
+
'foobar',
|
|
210
|
+
]);
|
|
211
|
+
expect(matchInfo.tags).to.deep.equal({
|
|
212
|
+
[UNTRUSTED]: [0, 5]
|
|
213
|
+
});
|
|
214
|
+
expect(matchInfo.name).to.equal('String.prototype.match');
|
|
215
|
+
expect(captrueMatchInfo.tags).to.deep.equal({
|
|
216
|
+
[UNTRUSTED]: [0, 5]
|
|
217
|
+
});
|
|
218
|
+
expect(captrueMatchInfo.name).to.equal('String.prototype.match');
|
|
219
|
+
expect(ret.groups.full).to.equal('foobar');
|
|
220
|
+
expect(fullGroupInfo.tags).to.deep.equal({
|
|
221
|
+
[UNTRUSTED]: [0, 5]
|
|
222
|
+
});
|
|
223
|
+
expect(fullGroupInfo.name).to.equal('String.prototype.match');
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('handles empty string matches', function () {
|
|
228
|
+
simulateRequestScope(() => {
|
|
229
|
+
const extern = trackString('foobar');
|
|
230
|
+
|
|
231
|
+
const ret = extern.match(/(?<empty>)/);
|
|
232
|
+
const matchInfo = tracker.getData(ret[0]);
|
|
233
|
+
const captrueMatchInfo = tracker.getData(ret[1]);
|
|
234
|
+
const emptyGroupInfo = tracker.getData(ret.groups.empty);
|
|
235
|
+
|
|
236
|
+
expect(ret).to.deep.equal([
|
|
237
|
+
'',
|
|
238
|
+
'',
|
|
239
|
+
]);
|
|
240
|
+
expect(matchInfo).to.be.null;
|
|
241
|
+
expect(captrueMatchInfo).to.be.null;
|
|
242
|
+
expect(ret.groups.empty).to.equal('');
|
|
243
|
+
expect(emptyGroupInfo).to.be.null;
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
describe('capture groups', function () {
|
|
249
|
+
it('keeps track of tracked strings within matched capture groups', function () {
|
|
250
|
+
simulateRequestScope(() => {
|
|
251
|
+
const extern = trackString('foobar');
|
|
252
|
+
|
|
253
|
+
const ret = extern.match(/(foo)|(bar)/);
|
|
254
|
+
const retFirstArgInfo = tracker.getData(ret[0]);
|
|
255
|
+
const retSecondArgInfo = tracker.getData(ret[1]);
|
|
256
|
+
|
|
257
|
+
expect(ret).to.deep.equal(['foo', 'foo', undefined]);
|
|
258
|
+
expect(ret.groups).to.be.undefined;
|
|
259
|
+
expect(retFirstArgInfo.tags).to.deep.equal({
|
|
260
|
+
[UNTRUSTED]: [0, 2]
|
|
261
|
+
});
|
|
262
|
+
expect(retFirstArgInfo.name).to.equal('String.prototype.match');
|
|
263
|
+
expect(retSecondArgInfo.tags).to.deep.equal({
|
|
264
|
+
[UNTRUSTED]: [0, 2]
|
|
265
|
+
});
|
|
266
|
+
expect(retSecondArgInfo.name).to.equal('String.prototype.match');
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('keeps track of tracked strings within matched named capture groups', function () {
|
|
271
|
+
simulateRequestScope(() => {
|
|
272
|
+
const extern = trackString('foobar');
|
|
273
|
+
|
|
274
|
+
const ret = extern.match(/(?<fooOrBar>foo|bar)/);
|
|
275
|
+
const retFirstArgInfo = tracker.getData(ret[0]);
|
|
276
|
+
const retSecondArgInfo = tracker.getData(ret[1]);
|
|
277
|
+
const groupsValueInfo = tracker.getData(ret.groups.fooOrBar);
|
|
278
|
+
|
|
279
|
+
expect(ret).to.deep.equal(['foo', 'foo']);
|
|
280
|
+
expect(ret.groups.fooOrBar).to.equal('foo');
|
|
281
|
+
expect(retFirstArgInfo.tags).to.deep.equal({
|
|
282
|
+
[UNTRUSTED]: [0, 2]
|
|
283
|
+
});
|
|
284
|
+
expect(retFirstArgInfo.name).to.equal('String.prototype.match');
|
|
285
|
+
expect(retSecondArgInfo.tags).to.deep.equal({
|
|
286
|
+
[UNTRUSTED]: [0, 2]
|
|
287
|
+
});
|
|
288
|
+
expect(retSecondArgInfo.name).to.equal('String.prototype.match');
|
|
289
|
+
expect(groupsValueInfo.tags).to.deep.equal({
|
|
290
|
+
[UNTRUSTED]: [0, 2]
|
|
291
|
+
});
|
|
292
|
+
expect(groupsValueInfo.name).to.equal('String.prototype.match');
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('keeps track of tracked strings within multiple matched named capture groups', function () {
|
|
297
|
+
simulateRequestScope(() => {
|
|
298
|
+
const extern = trackString('foobar');
|
|
299
|
+
|
|
300
|
+
const ret = extern.match(/(?<fizzOrBuzz>fizz|buzz)|(?<fooOrBar>foo|bar)/);
|
|
301
|
+
const retFirstArgInfo = tracker.getData(ret[0]);
|
|
302
|
+
const retThirdArgInfo = tracker.getData(ret[2]);
|
|
303
|
+
const groupsValueInfo = tracker.getData(ret.groups.fooOrBar);
|
|
304
|
+
|
|
305
|
+
expect(ret).to.deep.equal(['foo', undefined, 'foo']);
|
|
306
|
+
expect(ret.groups).to.deep.equal({ fizzOrBuzz: undefined, fooOrBar: 'foo' });
|
|
307
|
+
expect(retFirstArgInfo.tags).to.deep.equal({
|
|
308
|
+
[UNTRUSTED]: [0, 2]
|
|
309
|
+
});
|
|
310
|
+
expect(retFirstArgInfo.name).to.equal('String.prototype.match');
|
|
311
|
+
expect(retThirdArgInfo.tags).to.deep.equal({
|
|
312
|
+
[UNTRUSTED]: [0, 2]
|
|
313
|
+
});
|
|
314
|
+
expect(retThirdArgInfo.name).to.equal('String.prototype.match');
|
|
315
|
+
expect(groupsValueInfo.tags).to.deep.equal({
|
|
316
|
+
[UNTRUSTED]: [0, 2]
|
|
317
|
+
});
|
|
318
|
+
expect(groupsValueInfo.name).to.equal('String.prototype.match');
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe('custom matcher', function () {
|
|
324
|
+
it('keeps track of tracked string returned by custom matcher', function () {
|
|
325
|
+
simulateRequestScope(() => {
|
|
326
|
+
const extern = trackString('foo');
|
|
327
|
+
|
|
328
|
+
const ret = 'foo'.match({
|
|
329
|
+
[Symbol.match](_str) {
|
|
330
|
+
return [extern];
|
|
331
|
+
},
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
expect(ret).to.deep.equal(['foo']);
|
|
335
|
+
expect(tracker.getData(ret[0]).tags).to.deep.equal({
|
|
336
|
+
[UNTRUSTED]: [0, 2]
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
it('keeps track of tracked string copied by custom matcher', function () {
|
|
342
|
+
simulateRequestScope(() => {
|
|
343
|
+
const extern = trackString('foobar');
|
|
344
|
+
|
|
345
|
+
const ret = extern.match({
|
|
346
|
+
[Symbol.match](str) {
|
|
347
|
+
return [str.substring(0, 3)];
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
const retInfo = tracker.getData(ret[0]);
|
|
351
|
+
|
|
352
|
+
expect(ret).to.deep.equal(['foo']);
|
|
353
|
+
expect(retInfo.tags).to.deep.equal({
|
|
354
|
+
[UNTRUSTED]: [0, 2]
|
|
355
|
+
});
|
|
356
|
+
expect(retInfo.history[0].name).to.equal('String.prototype.match');
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|