@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,238 @@
1
+ 'use strict';
2
+
3
+ const { expect } = require('chai');
4
+ const sinon = require('sinon');
5
+ const { initAssessFixture } = require('@contrast/test/fixtures');
6
+
7
+ describe('assess dataflow propagation string substring', function () {
8
+ let core, tracker, trackString, simulateRequestScope;
9
+
10
+ beforeEach(function () {
11
+ ({
12
+ core,
13
+ simulateRequestScope,
14
+ trackString
15
+ } = initAssessFixture());
16
+ tracker = core.assess.dataflow.tracker;
17
+
18
+ core.assess.dataflow.propagation.stringInstrumentation.substring.install();
19
+ });
20
+
21
+ afterEach(function () {
22
+ core.assess.dataflow.propagation.stringInstrumentation.substring.uninstall();
23
+ sinon.resetHistory();
24
+ });
25
+
26
+ [
27
+ {
28
+ desc: 'below',
29
+ str: 'xx-----',
30
+ tags: {
31
+ untrusted: [0, 1]
32
+ },
33
+ args: [2],
34
+ expectedResult: '-----',
35
+ },
36
+ {
37
+ desc: 'above',
38
+ str: '-----xx',
39
+ tags: {
40
+ untrusted: [5, 6]
41
+ },
42
+ args: [0, 3],
43
+ result: '---',
44
+ },
45
+ {
46
+ desc: 'highspan',
47
+ str: '--xxx--',
48
+ tags: {
49
+ untrusted: [2, 4]
50
+ },
51
+ args: [1, 3],
52
+ expected: {
53
+ untrusted: [1, 2]
54
+ },
55
+ expectedResult: '-xx',
56
+ },
57
+ {
58
+ desc: 'within',
59
+ str: '--xxx--',
60
+ tags: {
61
+ untrusted: [2, 4]
62
+ },
63
+ args: [1],
64
+ expected: {
65
+ untrusted: [1, 3]
66
+ },
67
+ result: '-xxx--',
68
+ },
69
+ {
70
+ desc: 'fullSpan',
71
+ str: '--xxx--',
72
+ tags: {
73
+ untrusted: [2, 4]
74
+ },
75
+ args: [2, 2],
76
+ expected: {
77
+ untrusted: [0, 1]
78
+ },
79
+ result: 'xx',
80
+ },
81
+ {
82
+ desc: 'lowspan',
83
+ str: '--xxx--',
84
+ tags: {
85
+ untrusted: [2, 4]
86
+ },
87
+ args: [3, 3],
88
+ expected: {
89
+ untrusted: [0, 1]
90
+ },
91
+ },
92
+ ].forEach(({ desc, str, tags, args, expected }) => {
93
+ it(desc, function () {
94
+ simulateRequestScope(function () {
95
+ const extern = trackString(str, { tags });
96
+ const result = extern.substr(...args);
97
+ const strInfo = tracker.getData(result);
98
+
99
+ if (expected) {
100
+ expect(strInfo.tags).to.deep.equal(expected);
101
+ } else {
102
+ expect(strInfo).to.be.null;
103
+ }
104
+ });
105
+ });
106
+ });
107
+
108
+ [
109
+ {
110
+ desc: 'not tracked',
111
+ str: '-----------',
112
+ args: [0, 2],
113
+ },
114
+ {
115
+ desc: 'below',
116
+ str: 'xx-----',
117
+ tags: {
118
+ untrusted: [0, 1]
119
+ },
120
+ args: [2],
121
+ },
122
+ {
123
+ desc: 'above',
124
+ str: '-----xx',
125
+ tags: {
126
+ untrusted: [5, 6]
127
+ },
128
+ args: [0, 3],
129
+ },
130
+ {
131
+ desc: 'highspan',
132
+ str: '--xxx--',
133
+ tags: {
134
+ untrusted: [2, 4]
135
+ },
136
+ args: {
137
+ substring: [1, 3],
138
+ substr: [1, 2],
139
+ },
140
+ expected: {
141
+ untrusted: [1, 1]
142
+ },
143
+ },
144
+ {
145
+ desc: 'within',
146
+ str: '--xxx--',
147
+ tags: {
148
+ untrusted: [2, 4]
149
+ },
150
+ args: [1],
151
+ expected: {
152
+ untrusted: [1, 3]
153
+ },
154
+ },
155
+ {
156
+ desc: 'fullSpan',
157
+ str: '--xxx--',
158
+ tags: {
159
+ untrusted: [2, 4]
160
+ },
161
+ args: {
162
+ substring: [2, 4],
163
+ substr: [2, 2],
164
+ },
165
+ expected: {
166
+ untrusted: [0, 1]
167
+ },
168
+ },
169
+ {
170
+ desc: 'lowspan',
171
+ str: '--xxx--',
172
+ tags: {
173
+ untrusted: [2, 4]
174
+ },
175
+ args: [3, 6],
176
+ expected: {
177
+ untrusted: [0, 1]
178
+ },
179
+ },
180
+ {
181
+ desc: 'lowspan',
182
+ str: 'xxx--xx',
183
+ tags: {
184
+ untrusted: [0, 2, 5, 6]
185
+ },
186
+ args: {
187
+ substring: [3, 1], // reversed work the same
188
+ substr: [1, 3], // but not for substr method
189
+ },
190
+ expected: {
191
+ untrusted: [0, 1]
192
+ },
193
+ },
194
+ ].forEach(({ desc, str, tags, args, expected }) => {
195
+ ['substring', 'substr'].forEach((method) => {
196
+ it(`${method} ${desc}`, function () {
197
+ simulateRequestScope(function () {
198
+ const extern = desc !== 'not tracked' ? trackString(str, { tags }) : str;
199
+ const methodArgs = args[method] || args;
200
+ const result = extern[method](...methodArgs);
201
+ const strInfo = tracker.getData(result);
202
+
203
+ if (expected) {
204
+ expect(strInfo.tags).to.deep.equal(expected);
205
+ } else {
206
+ expect(strInfo).to.be.null;
207
+ }
208
+ });
209
+ });
210
+ });
211
+ });
212
+
213
+ it('won\'t do anything if the result is the same or not in proper scope', function () {
214
+ const extern = trackString('foo');
215
+
216
+ let result;
217
+
218
+ core.scopes.sources.run({}, function () {
219
+ result = extern.substring(5);
220
+ });
221
+
222
+ expect(tracker.getData(result)).to.be.null;
223
+
224
+ core.scopes.sources.run(null, function () {
225
+ result = extern.substr(0, 2);
226
+ });
227
+
228
+ expect(tracker.getData(result)).to.be.null;
229
+
230
+ core.scopes.instrumentation.run({ lock: true }, function () {
231
+ core.scopes.sources.run({}, function () {
232
+ result = extern.substring(0, 2);
233
+ });
234
+ });
235
+
236
+ expect(tracker.getData(result)).to.be.null;
237
+ });
238
+ });
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ const { expect } = require('chai');
4
+ const sinon = require('sinon');
5
+ const { initAssessFixture } = require('@contrast/test/fixtures');
6
+
7
+ describe('assess dataflow propagation string trim', function () {
8
+ let core, tracker, trackString, simulateRequestScope;
9
+
10
+ beforeEach(function () {
11
+ ({
12
+ core,
13
+ trackString,
14
+ simulateRequestScope,
15
+ } = initAssessFixture());
16
+
17
+ tracker = core.assess.dataflow.tracker;
18
+ core.assess.dataflow.propagation.stringInstrumentation.trim.install();
19
+ });
20
+
21
+ afterEach(function () {
22
+ core.assess.dataflow.propagation.stringInstrumentation.trim.uninstall();
23
+ sinon.resetHistory();
24
+ });
25
+
26
+ [
27
+ {
28
+ str: 'not-tracked',
29
+ expected: {
30
+ trim: undefined,
31
+ trimStart: undefined,
32
+ trimEnd: undefined,
33
+ }
34
+ },
35
+ {
36
+ str: ' foo ',
37
+ tags: {},
38
+ expected: {
39
+ trim: undefined,
40
+ trimStart: undefined,
41
+ trimEnd: undefined,
42
+ }
43
+ },
44
+ {
45
+ str: ' foo ',
46
+ tags: {
47
+ untrusted: [0, 6]
48
+ },
49
+ expected: {
50
+ trim: { untrusted: [0, 2] },
51
+ trimStart: { untrusted: [0, 4] },
52
+ trimEnd: { untrusted: [0, 4] },
53
+ }
54
+ },
55
+ {
56
+ str: ' foo',
57
+ tags: {
58
+ untrusted: [0, 4]
59
+ },
60
+ expected: {
61
+ trim: { untrusted: [0, 2] },
62
+ trimStart: { untrusted: [0, 2] },
63
+ trimEnd: { untrusted: [0, 4] },
64
+ }
65
+ },
66
+ {
67
+ str: 'foo ',
68
+ tags: {
69
+ untrusted: [0, 4]
70
+ },
71
+ expected: {
72
+ trim: { untrusted: [0, 2] },
73
+ trimStart: { untrusted: [0, 4] },
74
+ trimEnd: { untrusted: [0, 2] },
75
+ }
76
+ },
77
+ {
78
+ str: ' foo ',
79
+ tags: {
80
+ untrusted: [2, 4]
81
+ },
82
+ expected: {
83
+ trim: { untrusted: [0, 2] },
84
+ trimStart: { untrusted: [0, 2] },
85
+ trimEnd: { untrusted: [2, 4] },
86
+ }
87
+ },
88
+ ].forEach(({ str, tags, expected = null }) => {
89
+ [
90
+ 'trim',
91
+ 'trimStart',
92
+ 'trimEnd',
93
+ ].forEach((method) => {
94
+ it(method, function () {
95
+ simulateRequestScope(function () {
96
+ const extern = str !== 'not-tracked' ? trackString(str, { tags }) : str;
97
+ const result = extern[method]();
98
+ expect(tracker.getData(result)?.tags).to.deep.equal(expected[method]);
99
+ });
100
+
101
+ });
102
+ });
103
+ });
104
+
105
+ it('won\'t do anything if not in proper scope', function () {
106
+ let result;
107
+ const extern = trackString(' foo', { tags: { untrusted: [0, 2] } });
108
+
109
+ core.scopes.sources.run(null, function () {
110
+ expect(tracker.getData(extern.trim())).to.be.null;
111
+ });
112
+
113
+
114
+ core.scopes.instrumentation.run({ lock: true }, function () {
115
+ core.scopes.sources.run({}, function () {
116
+ expect(tracker.getData(extern.trim())).to.be.null;
117
+ });
118
+ });
119
+
120
+ expect(tracker.getData(result)).to.be.null;
121
+ });
122
+ });
@@ -0,0 +1,78 @@
1
+
2
+ 'use strict';
3
+
4
+ const {
5
+ DataflowTag: { UNTRUSTED, WEAK_URL_ENCODED }
6
+ } = require('@contrast/common');
7
+ const { expect } = require('chai');
8
+ const sinon = require('sinon');
9
+ const { initAssessFixture } = require('@contrast/test/fixtures');
10
+
11
+ describe('assess dataflow propagation unescape', function () {
12
+ let core, trackString, simulateRequestScope, tracker;
13
+
14
+ beforeEach(function () {
15
+ ({
16
+ core,
17
+ simulateRequestScope,
18
+ trackString
19
+ } = initAssessFixture());
20
+
21
+ tracker = core.assess.dataflow.tracker;
22
+ core.assess.dataflow.propagation.unescape.install();
23
+ });
24
+
25
+ afterEach(function () {
26
+ core.assess.dataflow.propagation.unescape.uninstall();
27
+ sinon.resetHistory();
28
+ });
29
+
30
+ [
31
+ {
32
+ str: '%3Ftest%3Dstr',
33
+ tags: {
34
+ [UNTRUSTED]: [0, 12],
35
+ [WEAK_URL_ENCODED]: [0, 12]
36
+ },
37
+ expected: { [UNTRUSTED]: [0, 8] }
38
+ },
39
+ {
40
+ str: '?test=str',
41
+ tags: {
42
+ [UNTRUSTED]: [0, 8]
43
+ },
44
+ expected: { [UNTRUSTED]: [0, 8] }
45
+ },
46
+ {
47
+ str: 'not-tracked',
48
+ }
49
+ ].forEach(({ str, tags, expected }) => {
50
+ it('propagates correctly', function () {
51
+ simulateRequestScope(function () {
52
+ const value = tags ? trackString(str, { tags }) : str;
53
+
54
+ const result = unescape(value);
55
+ const strInfo = tracker.getData(result);
56
+ expect(strInfo?.tags).to.deep.equal(expected);
57
+ });
58
+ });
59
+ });
60
+
61
+ it('will not propagate if there is no assess context', function () {
62
+ simulateRequestScope(function () {
63
+ const value = trackString('%3Ftest%3Dstr');
64
+ const result = unescape(value);
65
+ expect(tracker.getData(result)).to.be.null;
66
+ }, {});
67
+ });
68
+
69
+ it('will not propagate if there instrumentation is locked', function () {
70
+ simulateRequestScope(function () {
71
+ core.scopes.instrumentation.run({ lock: true }, function () {
72
+ const value = trackString('%3Ftest%3Dstr');
73
+ const result = unescape(value);
74
+ expect(tracker.getData(result)).to.be.null;
75
+ });
76
+ });
77
+ });
78
+ });
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ const url = require('url');
4
+ const { expect } = require('chai');
5
+ const sinon = require('sinon');
6
+ const { initAssessFixture } = require('@contrast/test/fixtures');
7
+
8
+ describe('assess dataflow propagation url domain-parsers', function () {
9
+ let core, trackString, simulateRequestScope, tracker;
10
+
11
+ beforeEach(function () {
12
+ ({
13
+ core,
14
+ simulateRequestScope,
15
+ trackString
16
+ } = initAssessFixture());
17
+
18
+
19
+ tracker = core.assess.dataflow.tracker;
20
+ core.assess.dataflow.propagation.urlInstrumentation.domainParsers.install();
21
+ core.depHooks.resolve.yield(url);
22
+ });
23
+
24
+ afterEach(function () {
25
+ sinon.resetHistory();
26
+ });
27
+
28
+ ['domainToASCII', 'domainToUnicode'].forEach((method) => {
29
+ it(method, function () {
30
+ simulateRequestScope(function () {
31
+ const notTrackedValue = 'español.com';
32
+ const trackedValue = trackString('español.com', { tags: { untrusted: [0, 2] } });
33
+
34
+ const notTrackedResult = url[method](notTrackedValue);
35
+ const notTrackedStrInfo = tracker.getData(notTrackedResult);
36
+
37
+ const trackedResult = url[method](trackedValue);
38
+ const trackedStrInfo = tracker.getData(trackedResult);
39
+
40
+ expect(notTrackedStrInfo).to.be.null;
41
+ expect(trackedStrInfo?.tags).to.deep.equal({ untrusted: [0, trackedStrInfo?.value.length - 1] });
42
+ });
43
+ });
44
+ });
45
+
46
+ it('will not propagate if there is no assess context', function () {
47
+ simulateRequestScope(function () {
48
+ const value = trackString('foo');
49
+ const result = url.domainToASCII(value);
50
+ expect(tracker.getData(result)).to.be.null;
51
+ }, {});
52
+ });
53
+
54
+ it('will not propagate if there instrumentation is locked', function () {
55
+ simulateRequestScope(function () {
56
+ core.scopes.instrumentation.run({ lock: true }, function () {
57
+ const value = trackString('foo');
58
+ const result = url.domainToUnicode(value);
59
+ expect(tracker.getData(result)).to.be.null;
60
+ });
61
+ });
62
+ });
63
+ });