@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.
Files changed (154) hide show
  1. package/lib/crypto-analysis/install/crypto.test.js +146 -0
  2. package/lib/crypto-analysis/install/math.test.js +65 -0
  3. package/lib/dataflow/index.test.js +36 -0
  4. package/lib/dataflow/propagation/index.test.js +103 -0
  5. package/lib/dataflow/propagation/install/JSON/index.test.js +50 -0
  6. package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +232 -0
  7. package/lib/dataflow/propagation/install/JSON/parse.test.js +968 -0
  8. package/lib/dataflow/propagation/install/JSON/stringify.test.js +265 -0
  9. package/lib/dataflow/propagation/install/array-prototype-join.test.js +106 -0
  10. package/lib/dataflow/propagation/install/buffer.test.js +109 -0
  11. package/lib/dataflow/propagation/install/contrast-methods/add.test.js +94 -0
  12. package/lib/dataflow/propagation/install/contrast-methods/index.test.js +49 -0
  13. package/lib/dataflow/propagation/install/contrast-methods/number.test.js +50 -0
  14. package/lib/dataflow/propagation/install/contrast-methods/string.test.js +148 -0
  15. package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +145 -0
  16. package/lib/dataflow/propagation/install/decode-uri-component.test.js +78 -0
  17. package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +69 -0
  18. package/lib/dataflow/propagation/install/ejs/template.test.js +62 -0
  19. package/lib/dataflow/propagation/install/encode-uri.test.js +83 -0
  20. package/lib/dataflow/propagation/install/escape-html.test.js +71 -0
  21. package/lib/dataflow/propagation/install/escape.test.js +73 -0
  22. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +71 -0
  23. package/lib/dataflow/propagation/install/isnumeric-0.test.js +58 -0
  24. package/lib/dataflow/propagation/install/joi/any.test.js +270 -0
  25. package/lib/dataflow/propagation/install/joi/array.test.js +912 -0
  26. package/lib/dataflow/propagation/install/joi/boolean.test.js +103 -0
  27. package/lib/dataflow/propagation/install/joi/expression.test.js +76 -0
  28. package/lib/dataflow/propagation/install/joi/index.test.js +39 -0
  29. package/lib/dataflow/propagation/install/joi/number.test.js +103 -0
  30. package/lib/dataflow/propagation/install/joi/object.test.js +119 -0
  31. package/lib/dataflow/propagation/install/joi/ref.test.js +607 -0
  32. package/lib/dataflow/propagation/install/joi/string-schema.test.js +513 -0
  33. package/lib/dataflow/propagation/install/mongoose/index.test.js +42 -0
  34. package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +348 -0
  35. package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +512 -0
  36. package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +160 -0
  37. package/lib/dataflow/propagation/install/mustache-escape.test.js +62 -0
  38. package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +74 -0
  39. package/lib/dataflow/propagation/install/parse-int.test.js +48 -0
  40. package/lib/dataflow/propagation/install/path/basename.test.js +143 -0
  41. package/lib/dataflow/propagation/install/path/dirname.test.js +167 -0
  42. package/lib/dataflow/propagation/install/path/extname.test.js +141 -0
  43. package/lib/dataflow/propagation/install/path/format.test.js +250 -0
  44. package/lib/dataflow/propagation/install/path/index.test.js +45 -0
  45. package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +485 -0
  46. package/lib/dataflow/propagation/install/path/normalize.test.js +176 -0
  47. package/lib/dataflow/propagation/install/path/parse.test.js +238 -0
  48. package/lib/dataflow/propagation/install/path/relative.test.js +239 -0
  49. package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +158 -0
  50. package/lib/dataflow/propagation/install/pug/index.test.js +55 -0
  51. package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +69 -0
  52. package/lib/dataflow/propagation/install/querystring/escape.test.js +63 -0
  53. package/lib/dataflow/propagation/install/querystring/index.test.js +40 -0
  54. package/lib/dataflow/propagation/install/querystring/parse.test.js +272 -0
  55. package/lib/dataflow/propagation/install/querystring/stringify.test.js +301 -0
  56. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +281 -0
  57. package/lib/dataflow/propagation/install/send.test.js +63 -0
  58. package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +73 -0
  59. package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +130 -0
  60. package/lib/dataflow/propagation/install/sql-template-strings.test.js +100 -0
  61. package/lib/dataflow/propagation/install/string/concat.test.js +132 -0
  62. package/lib/dataflow/propagation/install/string/format-methods.test.js +61 -0
  63. package/lib/dataflow/propagation/install/string/html-methods.test.js +164 -0
  64. package/lib/dataflow/propagation/install/string/index.test.js +103 -0
  65. package/lib/dataflow/propagation/install/string/match-all.test.js +399 -0
  66. package/lib/dataflow/propagation/install/string/match.test.js +361 -0
  67. package/lib/dataflow/propagation/install/string/replace.test.js +588 -0
  68. package/lib/dataflow/propagation/install/string/slice.test.js +265 -0
  69. package/lib/dataflow/propagation/install/string/split.test.js +500 -0
  70. package/lib/dataflow/propagation/install/string/substring.test.js +238 -0
  71. package/lib/dataflow/propagation/install/string/trim.test.js +122 -0
  72. package/lib/dataflow/propagation/install/unescape.test.js +78 -0
  73. package/lib/dataflow/propagation/install/url/domain-parsers.test.js +63 -0
  74. package/lib/dataflow/propagation/install/url/parse.test.js +391 -0
  75. package/lib/dataflow/propagation/install/url/searchParams.test.js +538 -0
  76. package/lib/dataflow/propagation/install/url/url.test.js +466 -0
  77. package/lib/dataflow/propagation/install/util-format.test.js +336 -0
  78. package/lib/dataflow/propagation/install/validator/hooks.test.js +211 -0
  79. package/lib/dataflow/sinks/index.test.js +78 -0
  80. package/lib/dataflow/sinks/install/child-process.test.js +338 -0
  81. package/lib/dataflow/sinks/install/eval.test.js +95 -0
  82. package/lib/dataflow/sinks/install/express/index.test.js +33 -0
  83. package/lib/dataflow/sinks/install/express/reflected-xss.js +55 -57
  84. package/lib/dataflow/sinks/install/express/reflected-xss.test.js +109 -0
  85. package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +144 -0
  86. package/lib/dataflow/sinks/install/fastify/index.test.js +32 -0
  87. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +130 -0
  88. package/lib/dataflow/sinks/install/fs.test.js +138 -0
  89. package/lib/dataflow/sinks/install/function.test.js +103 -0
  90. package/lib/dataflow/sinks/install/hapi/index.test.js +32 -0
  91. package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +130 -0
  92. package/lib/dataflow/sinks/install/http/index.test.js +33 -0
  93. package/lib/dataflow/sinks/install/http/request.test.js +184 -0
  94. package/lib/dataflow/sinks/install/http/server-response.test.js +162 -0
  95. package/lib/dataflow/sinks/install/koa/index.test.js +32 -0
  96. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +200 -0
  97. package/lib/dataflow/sinks/install/libxmljs.test.js +158 -0
  98. package/lib/dataflow/sinks/install/marsdb.test.js +166 -0
  99. package/lib/dataflow/sinks/install/mongodb.test.js +621 -0
  100. package/lib/dataflow/sinks/install/mssql.test.js +136 -0
  101. package/lib/dataflow/sinks/install/mysql.test.js +233 -0
  102. package/lib/dataflow/sinks/install/node-serialize.test.js +85 -0
  103. package/lib/dataflow/sinks/install/postgres.test.js +158 -0
  104. package/lib/dataflow/sinks/install/restify.test.js +142 -0
  105. package/lib/dataflow/sinks/install/sequelize.test.js +100 -0
  106. package/lib/dataflow/sinks/install/sqlite3.test.js +118 -0
  107. package/lib/dataflow/sinks/install/vm.test.js +326 -0
  108. package/lib/dataflow/sources/handler.test.js +463 -0
  109. package/lib/dataflow/sources/index.test.js +58 -0
  110. package/lib/dataflow/sources/install/body-parser1.test.js +248 -0
  111. package/lib/dataflow/sources/install/busboy.test.js +152 -0
  112. package/lib/dataflow/sources/install/cookie-parser1.test.js +143 -0
  113. package/lib/dataflow/sources/install/express/params.test.js +105 -0
  114. package/lib/dataflow/sources/install/express/parsedUrl.test.js +65 -0
  115. package/lib/dataflow/sources/install/fastify/fastify.test.js +210 -0
  116. package/lib/dataflow/sources/install/fastify/index.test.js +33 -0
  117. package/lib/dataflow/sources/install/formidable1.test.js +119 -0
  118. package/lib/dataflow/sources/install/hapi/hapi.test.js +172 -0
  119. package/lib/dataflow/sources/install/hapi/index.test.js +33 -0
  120. package/lib/dataflow/sources/install/http.test.js +155 -0
  121. package/lib/dataflow/sources/install/koa/index.test.js +40 -0
  122. package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +161 -0
  123. package/lib/dataflow/sources/install/koa/koa-multer.test.js +197 -0
  124. package/lib/dataflow/sources/install/koa/koa-routers.test.js +146 -0
  125. package/lib/dataflow/sources/install/koa/koa2.test.js +145 -0
  126. package/lib/dataflow/sources/install/multer1.test.js +145 -0
  127. package/lib/dataflow/sources/install/qs6.test.js +131 -0
  128. package/lib/dataflow/sources/install/querystring.test.js +82 -0
  129. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +88 -0
  130. package/lib/dataflow/sources/install/restify/index.test.js +38 -0
  131. package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +144 -0
  132. package/lib/dataflow/sources/install/restify/router.test.js +83 -0
  133. package/lib/dataflow/tag-utils-complete.test.js +27 -0
  134. package/lib/dataflow/tag-utils.test.js +192 -0
  135. package/lib/dataflow/tracker.test.js +216 -0
  136. package/lib/dataflow/utils/is-safe-content-type.test.js +16 -0
  137. package/lib/dataflow/utils/is-vulnerable.test.js +115 -0
  138. package/lib/event-factory.test.js +321 -0
  139. package/lib/get-policy.test.js +194 -0
  140. package/lib/get-source-context.test.js +108 -0
  141. package/lib/index.test.js +41 -0
  142. package/lib/make-source-context.test.js +50 -0
  143. package/lib/response-scanning/handlers/index.test.js +425 -0
  144. package/lib/response-scanning/handlers/utils.test.js +391 -0
  145. package/lib/response-scanning/index.test.js +41 -0
  146. package/lib/response-scanning/install/http.test.js +175 -0
  147. package/lib/rule-scopes.test.js +27 -0
  148. package/lib/session-configuration/handlers.test.js +84 -0
  149. package/lib/session-configuration/index.test.js +36 -0
  150. package/lib/session-configuration/install/express-session.test.js +220 -0
  151. package/lib/session-configuration/install/fastify-cookie.test.js +65 -0
  152. package/lib/session-configuration/install/hapi.test.js +269 -0
  153. package/lib/session-configuration/install/koa.test.js +92 -0
  154. package/package.json +2 -2
@@ -0,0 +1,466 @@
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
+ const keys = [
9
+ 'hash',
10
+ 'host',
11
+ 'hostname',
12
+ 'href',
13
+ 'origin',
14
+ 'password',
15
+ 'pathname',
16
+ 'port',
17
+ 'protocol',
18
+ 'search',
19
+ 'username'
20
+ ];
21
+
22
+ describe('assess dataflow propagation url.URL', function () {
23
+ let core, trackString, simulateRequestScope, tracker, matchURL;
24
+
25
+ beforeEach(function () {
26
+ ({
27
+ core,
28
+ simulateRequestScope,
29
+ trackString
30
+ } = initAssessFixture());
31
+
32
+ tracker = core.assess.dataflow.tracker;
33
+ core.assess.dataflow.propagation.stringInstrumentation.concat.install();
34
+ core.assess.dataflow.propagation.stringInstrumentation.substring.install();
35
+ core.assess.dataflow.propagation.stringInstrumentation.split.install();
36
+ core.assess.dataflow.propagation.urlInstrumentation.searchParams.install();
37
+ core.assess.dataflow.propagation.urlInstrumentation.url.install();
38
+ core.depHooks.resolve.yield(url);
39
+
40
+ matchURL = {
41
+ href: 'https://user:pass@foo.com:3000/path?query=input#hash',
42
+ origin: 'https://foo.com:3000',
43
+ protocol: 'https:',
44
+ username: 'user',
45
+ password: 'pass',
46
+ host: 'foo.com:3000',
47
+ hostname: 'foo.com',
48
+ port: '3000',
49
+ pathname: '/path',
50
+ search: '?query=input',
51
+ hash: '#hash'
52
+ };
53
+ });
54
+
55
+ afterEach(function () {
56
+ sinon.resetHistory();
57
+ core.assess.dataflow.propagation.stringInstrumentation.concat.uninstall();
58
+ core.assess.dataflow.propagation.stringInstrumentation.substring.uninstall();
59
+ });
60
+
61
+ it('will not propagate if nothing in url is tracked', function () {
62
+ simulateRequestScope(function () {
63
+ const result = new url.URL('http://foo:3000/path');
64
+ keys.forEach((key) => {
65
+ expect(tracker.getData(result[key])).to.be.null;
66
+ });
67
+ });
68
+ });
69
+
70
+ it('will not propagate if there is no assess context', function () {
71
+ simulateRequestScope(function () {
72
+ const value = trackString('foo');
73
+ const result = new url.URL('http://'.concat(value, ':3000/path'));
74
+ keys.forEach((key) => {
75
+ expect(tracker.getData(result[key])).to.be.null;
76
+ });
77
+ }, {});
78
+ });
79
+
80
+ it('will not propagate if there instrumentation is locked', function () {
81
+ simulateRequestScope(function () {
82
+ core.scopes.instrumentation.run({ lock: true }, function () {
83
+ const value = trackString('foo');
84
+ const result = new url.URL('http://'.concat(value, ':3000/path'));
85
+ keys.forEach((key) => {
86
+ expect(tracker.getData(result[key])).to.be.null;
87
+ });
88
+ });
89
+ });
90
+ });
91
+
92
+ describe('URL properties', function () {
93
+ it('propagates vulnerable protocol', function () {
94
+ simulateRequestScope(function () {
95
+ const value = trackString('https');
96
+ const result = new url.URL(value.concat('://user:pass@foo.com:3000/path?query=input#hash'));
97
+ keys.forEach((key) => {
98
+ expect(result[key]).to.be.equal(matchURL[key]);
99
+ });
100
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
101
+ UNTRUSTED: [0, 4]
102
+ });
103
+
104
+ expect(tracker.getData(result.origin).tags).to.be.deep.equal({
105
+ UNTRUSTED: [0, 4]
106
+ });
107
+
108
+ expect(tracker.getData(result.protocol).tags).to.be.deep.equal({
109
+ UNTRUSTED: [0, 4]
110
+ });
111
+
112
+ ['username', 'password', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'].forEach((prop) => {
113
+ expect(tracker.getData(result[prop])).to.be.null;
114
+ });
115
+ });
116
+ });
117
+
118
+ it('propagates vulnerable username', function () {
119
+ simulateRequestScope(function () {
120
+ const value = trackString('user');
121
+ const result = new url.URL('https://'.concat(value, ':pass@foo.com:3000/path?query=input#hash'));
122
+
123
+ keys.forEach((key) => {
124
+ expect(result[key]).to.be.equal(matchURL[key]);
125
+ });
126
+
127
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
128
+ UNTRUSTED: [8, 11]
129
+ });
130
+
131
+ expect(tracker.getData(result.username).tags).to.be.deep.equal({
132
+ UNTRUSTED: [0, 3]
133
+ });
134
+
135
+ ['origin', 'protocol', 'password', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'].forEach((prop) => {
136
+ expect(tracker.getData(result[prop])).to.be.null;
137
+ });
138
+ });
139
+ });
140
+
141
+ it('propagates vulnerable password', function () {
142
+ simulateRequestScope(function () {
143
+ const value = trackString('pass');
144
+ const result = new url.URL('https://user:'.concat(value, '@foo.com:3000/path?query=input#hash'));
145
+
146
+ keys.forEach((key) => {
147
+ expect(result[key]).to.be.equal(matchURL[key]);
148
+ });
149
+
150
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
151
+ UNTRUSTED: [13, 16]
152
+ });
153
+
154
+ expect(tracker.getData(result.password).tags).to.be.deep.equal({
155
+ UNTRUSTED: [0, 3]
156
+ });
157
+
158
+ ['protocol', 'origin', 'username', 'host', 'hostname', 'port', 'pathname', 'search', 'hash'].forEach((prop) => {
159
+ expect(tracker.getData(result[prop])).to.be.null;
160
+ });
161
+ });
162
+ });
163
+
164
+ it('propagates vulnerable hostname', function () {
165
+ simulateRequestScope(function () {
166
+ const value = trackString('foo');
167
+ const result = new url.URL('https://user:pass@'.concat(value, '.com:3000/path?query=input#hash'));
168
+
169
+ keys.forEach((key) => {
170
+ expect(result[key]).to.be.equal(matchURL[key]);
171
+ });
172
+
173
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
174
+ UNTRUSTED: [18, 20]
175
+ });
176
+
177
+ expect(tracker.getData(result.origin).tags).to.be.deep.equal({
178
+ UNTRUSTED: [8, 10]
179
+ });
180
+
181
+ expect(tracker.getData(result.hostname).tags).to.be.deep.equal({
182
+ UNTRUSTED: [0, 2]
183
+ });
184
+
185
+ expect(tracker.getData(result.host).tags).to.be.deep.equal({
186
+ UNTRUSTED: [0, 2]
187
+ });
188
+
189
+ ['protocol', 'username', 'password', 'port', 'pathname', 'search', 'hash'].forEach((prop) => {
190
+ expect(tracker.getData(result[prop])).to.be.null;
191
+ });
192
+ });
193
+ });
194
+
195
+ it('propagates vulnerable port', function () {
196
+ simulateRequestScope(function () {
197
+ const value = trackString('3000');
198
+ const result = new url.URL('https://user:pass@foo.com:'.concat(value, '/path?query=input#hash'));
199
+
200
+ keys.forEach((key) => {
201
+ expect(result[key]).to.be.equal(matchURL[key]);
202
+ });
203
+
204
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
205
+ UNTRUSTED: [26, 29]
206
+ });
207
+
208
+ expect(tracker.getData(result.origin).tags).to.be.deep.equal({
209
+ UNTRUSTED: [16, 19]
210
+ });
211
+
212
+ expect(tracker.getData(result.host).tags).to.be.deep.equal({
213
+ UNTRUSTED: [8, 11]
214
+ });
215
+
216
+ expect(tracker.getData(result.port).tags).to.be.deep.equal({
217
+ UNTRUSTED: [0, 3]
218
+ });
219
+
220
+ ['protocol', 'username', 'password', 'hostname', 'pathname', 'search', 'hash'].forEach((prop) => {
221
+ expect(tracker.getData(result[prop])).to.be.null;
222
+ });
223
+ });
224
+ });
225
+
226
+ it('propagates vulnerable pathname', function () {
227
+ simulateRequestScope(function () {
228
+ const value = trackString('path');
229
+ const result = new url.URL('https://user:pass@foo.com:3000/'.concat(value, '?query=input#hash'));
230
+
231
+ keys.forEach((key) => {
232
+ expect(result[key]).to.be.equal(matchURL[key]);
233
+ });
234
+
235
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
236
+ UNTRUSTED: [31, 34]
237
+ });
238
+
239
+ expect(tracker.getData(result.pathname).tags).to.be.deep.equal({
240
+ UNTRUSTED: [1, 4]
241
+ });
242
+
243
+ ['protocol', 'origin', 'username', 'password', 'host', 'hostname', 'port', 'search', 'hash'].forEach((prop) => {
244
+ expect(tracker.getData(result[prop])).to.be.null;
245
+ });
246
+ });
247
+ });
248
+
249
+ it('propagates vulnerable search', function () {
250
+ simulateRequestScope(function () {
251
+ const value = trackString('input');
252
+ const result = new url.URL('https://user:pass@foo.com:3000/path?query='.concat(value, '#hash'));
253
+
254
+ keys.forEach((key) => {
255
+ expect(result[key]).to.be.equal(matchURL[key]);
256
+ });
257
+
258
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
259
+ UNTRUSTED: [42, 46]
260
+ });
261
+
262
+ expect(tracker.getData(result.search).tags).to.be.deep.equal({
263
+ UNTRUSTED: [7, 11]
264
+ });
265
+
266
+ ['protocol', 'origin', 'username', 'password', 'host', 'hostname', 'port', 'pathname', 'hash'].forEach((prop) => {
267
+ expect(tracker.getData(result[prop])).to.be.null;
268
+ });
269
+ });
270
+ });
271
+
272
+ it('propagates vulnerable hash', function () {
273
+ simulateRequestScope(function () {
274
+ const value = trackString('hash');
275
+ const result = new url.URL('https://user:pass@foo.com:3000/path?query=input#'.concat(value));
276
+
277
+ keys.forEach((key) => {
278
+ expect(result[key]).to.be.equal(matchURL[key]);
279
+ });
280
+
281
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
282
+ UNTRUSTED: [48, 51]
283
+ });
284
+
285
+ expect(tracker.getData(result.hash).tags).to.be.deep.equal({
286
+ UNTRUSTED: [1, 4]
287
+ });
288
+
289
+ ['protocol', 'origin', 'username', 'password', 'host', 'hostname', 'port', 'pathname', 'search'].forEach((prop) => {
290
+ expect(tracker.getData(result[prop])).to.be.null;
291
+ });
292
+ });
293
+ });
294
+
295
+ it('propagates multiple vulnerable properties', function () {
296
+ simulateRequestScope(function () {
297
+ const protocol = trackString('https');
298
+ const user = trackString('user');
299
+ const pass = trackString('pass');
300
+ const hostname = trackString('foo');
301
+ const port = trackString('3000');
302
+ const path = trackString('path');
303
+ const query = trackString('input');
304
+ const hash = trackString('hash');
305
+ const result = new url.URL(protocol.concat('://', user, ':', pass, '@', hostname, '.com:', port, '/', path, '?query=', query, '#', hash));
306
+
307
+ keys.forEach((key) => {
308
+ expect(result[key]).to.be.equal(matchURL[key]);
309
+ });
310
+
311
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
312
+ UNTRUSTED: [0, 4, 8, 11, 13, 16, 18, 20, 26, 29, 31, 34, 42, 46, 48, 51]
313
+ });
314
+
315
+ expect(tracker.getData(result.origin).tags).to.be.deep.equal({
316
+ UNTRUSTED: [0, 4, 8, 10, 16, 19]
317
+ });
318
+
319
+ expect(tracker.getData(result.protocol).tags).to.be.deep.equal({
320
+ UNTRUSTED: [0, 4]
321
+ });
322
+
323
+ expect(tracker.getData(result.username).tags).to.be.deep.equal({
324
+ UNTRUSTED: [0, 3]
325
+ });
326
+
327
+ expect(tracker.getData(result.password).tags).to.be.deep.equal({
328
+ UNTRUSTED: [0, 3]
329
+ });
330
+
331
+ expect(tracker.getData(result.host).tags).to.be.deep.equal({
332
+ UNTRUSTED: [0, 2, 8, 11]
333
+ });
334
+
335
+ expect(tracker.getData(result.hostname).tags).to.be.deep.equal({
336
+ UNTRUSTED: [0, 2]
337
+ });
338
+
339
+ expect(tracker.getData(result.port).tags).to.be.deep.equal({
340
+ UNTRUSTED: [0, 3]
341
+ });
342
+
343
+ expect(tracker.getData(result.pathname).tags).to.be.deep.equal({
344
+ UNTRUSTED: [1, 4]
345
+ });
346
+
347
+ expect(tracker.getData(result.search).tags).to.be.deep.equal({
348
+ UNTRUSTED: [7, 11]
349
+ });
350
+
351
+ expect(tracker.getData(result.hash).tags).to.be.deep.equal({
352
+ UNTRUSTED: [1, 4]
353
+ });
354
+ });
355
+ });
356
+ });
357
+
358
+ describe('searchParams', function () {
359
+ it('maintains correct setters and getters for searchParams', function () {
360
+ simulateRequestScope(function () {
361
+ const result = new url.URL('https://user:pass@foo.com:3000/path?query1=input1&query2=input2');
362
+ expect(result.searchParams.get('query1')).to.be.equal('input1');
363
+ expect(result.searchParams.get('query2')).to.be.equal('input2');
364
+
365
+ result.searchParams.set('query1', 'input2');
366
+ result.searchParams.set('query2', 'input1');
367
+ expect(result.searchParams.get('query1')).to.be.equal('input2');
368
+ expect(result.searchParams.get('query2')).to.be.equal('input1');
369
+ });
370
+ });
371
+
372
+ it('propagates to searchParams', function () {
373
+ simulateRequestScope(function () {
374
+ const value1 = trackString('input1');
375
+ const value2 = trackString('input2');
376
+ const result = new url.URL('https://user:pass@foo.com:3000/path?query1='.concat(value1).concat('&query2=', value2, '#hash'));
377
+
378
+ expect(tracker.getData(result.searchParams.get('query1')).tags).to.be.deep.equal({
379
+ UNTRUSTED: [0, 5]
380
+ });
381
+ expect(tracker.getData(result.searchParams.get('query2')).tags).to.be.deep.equal({
382
+ UNTRUSTED: [0, 5]
383
+ });
384
+ });
385
+ });
386
+ });
387
+
388
+ describe('basename', function () {
389
+ it('does not include basename in result if input is absolute', function () {
390
+ simulateRequestScope(function () {
391
+ const result = new url.URL('https://foo.com', 'http://bar.org');
392
+ expect(result.toString()).to.be.equal('https://foo.com/');
393
+ });
394
+ });
395
+
396
+ it('concatenates basename if input is not absolute', function () {
397
+ simulateRequestScope(function () {
398
+ const result = new url.URL('/foo', 'http://bar.org');
399
+ expect(result.toString()).to.be.equal('http://bar.org/foo');
400
+ });
401
+ });
402
+
403
+ it('concatenates basename protocol if input is absolute but missing protocol', function () {
404
+ simulateRequestScope(function () {
405
+ const result = new url.URL('//foo', 'http://bar.org');
406
+ expect(result.toString()).to.be.equal('http://foo/');
407
+ });
408
+ });
409
+
410
+ it('concatenates basename protocol if input is absolute but missing protocol (leading slashes)', function () {
411
+ simulateRequestScope(function () {
412
+ const result = new url.URL('//////foo', 'http://bar.org');
413
+ expect(result.toString()).to.be.equal('http://foo/');
414
+ });
415
+ });
416
+
417
+ it('does not propagate tracked basename if input is absolute', function () {
418
+ simulateRequestScope(function () {
419
+ const value = trackString('bar');
420
+ const result = new url.URL('https://foo.com', 'http://'.concat(value, 'org'));
421
+ expect(result.toString()).to.be.equal('https://foo.com/');
422
+ keys.forEach((key) => {
423
+ expect(tracker.getData(result[key])).to.be.null;
424
+ });
425
+ });
426
+ });
427
+
428
+ it('propagates tracked basename if input is not absolute', function () {
429
+ simulateRequestScope(function () {
430
+ const value = trackString('bar');
431
+ const result = new url.URL('/foo', 'http://'.concat(value, '.org'));
432
+ expect(result.toString()).to.be.equal('http://bar.org/foo');
433
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
434
+ UNTRUSTED: [7, 9]
435
+ });
436
+ expect(tracker.getData(result.origin).tags).to.be.deep.equal({
437
+ UNTRUSTED: [7, 9]
438
+ });
439
+ expect(tracker.getData(result.host).tags).to.be.deep.equal({
440
+ UNTRUSTED: [0, 2]
441
+ });
442
+ expect(tracker.getData(result.hostname).tags).to.be.deep.equal({
443
+ UNTRUSTED: [0, 2]
444
+ });
445
+ });
446
+ });
447
+
448
+ it('propagates tracked protocol from basename if input is absolute but missing protocol', function () {
449
+ simulateRequestScope(function () {
450
+ const protocol = trackString('https');
451
+ const value = trackString('bar');
452
+ const result = new url.URL('//foo', protocol.concat('://', value, '.org'));
453
+ expect(result.toString()).to.be.equal('https://foo/');
454
+ expect(tracker.getData(result.href).tags).to.be.deep.equal({
455
+ UNTRUSTED: [0, 4]
456
+ });
457
+ expect(tracker.getData(result.origin).tags).to.be.deep.equal({
458
+ UNTRUSTED: [0, 4]
459
+ });
460
+ expect(tracker.getData(result.protocol).tags).to.be.deep.equal({
461
+ UNTRUSTED: [0, 4]
462
+ });
463
+ });
464
+ });
465
+ });
466
+ });