@contrast/assess 1.46.0 → 1.46.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/package.json +14 -11
  2. package/lib/crypto-analysis/install/crypto.test.js +0 -146
  3. package/lib/crypto-analysis/install/math.test.js +0 -65
  4. package/lib/dataflow/index.test.js +0 -36
  5. package/lib/dataflow/propagation/index.test.js +0 -103
  6. package/lib/dataflow/propagation/install/JSON/index.test.js +0 -50
  7. package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +0 -232
  8. package/lib/dataflow/propagation/install/JSON/parse.test.js +0 -968
  9. package/lib/dataflow/propagation/install/JSON/stringify.test.js +0 -265
  10. package/lib/dataflow/propagation/install/array-prototype-join.test.js +0 -106
  11. package/lib/dataflow/propagation/install/buffer.test.js +0 -112
  12. package/lib/dataflow/propagation/install/contrast-methods/add.test.js +0 -94
  13. package/lib/dataflow/propagation/install/contrast-methods/index.test.js +0 -49
  14. package/lib/dataflow/propagation/install/contrast-methods/number.test.js +0 -50
  15. package/lib/dataflow/propagation/install/contrast-methods/string.test.js +0 -148
  16. package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +0 -145
  17. package/lib/dataflow/propagation/install/decode-uri-component.test.js +0 -78
  18. package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +0 -69
  19. package/lib/dataflow/propagation/install/ejs/template.test.js +0 -62
  20. package/lib/dataflow/propagation/install/encode-uri.test.js +0 -83
  21. package/lib/dataflow/propagation/install/escape-html.test.js +0 -71
  22. package/lib/dataflow/propagation/install/escape.test.js +0 -73
  23. package/lib/dataflow/propagation/install/fastify-send.test.js +0 -42
  24. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +0 -71
  25. package/lib/dataflow/propagation/install/isnumeric-0.test.js +0 -58
  26. package/lib/dataflow/propagation/install/joi/any.test.js +0 -270
  27. package/lib/dataflow/propagation/install/joi/array.test.js +0 -912
  28. package/lib/dataflow/propagation/install/joi/boolean.test.js +0 -103
  29. package/lib/dataflow/propagation/install/joi/expression.test.js +0 -76
  30. package/lib/dataflow/propagation/install/joi/index.test.js +0 -39
  31. package/lib/dataflow/propagation/install/joi/number.test.js +0 -103
  32. package/lib/dataflow/propagation/install/joi/object.test.js +0 -119
  33. package/lib/dataflow/propagation/install/joi/ref.test.js +0 -607
  34. package/lib/dataflow/propagation/install/joi/string-schema.test.js +0 -513
  35. package/lib/dataflow/propagation/install/mongoose/index.test.js +0 -42
  36. package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +0 -348
  37. package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +0 -511
  38. package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +0 -199
  39. package/lib/dataflow/propagation/install/mustache-escape.test.js +0 -62
  40. package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +0 -74
  41. package/lib/dataflow/propagation/install/parse-int.test.js +0 -48
  42. package/lib/dataflow/propagation/install/path/basename.test.js +0 -143
  43. package/lib/dataflow/propagation/install/path/dirname.test.js +0 -167
  44. package/lib/dataflow/propagation/install/path/extname.test.js +0 -141
  45. package/lib/dataflow/propagation/install/path/format.test.js +0 -250
  46. package/lib/dataflow/propagation/install/path/index.test.js +0 -45
  47. package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +0 -485
  48. package/lib/dataflow/propagation/install/path/normalize.test.js +0 -176
  49. package/lib/dataflow/propagation/install/path/parse.test.js +0 -238
  50. package/lib/dataflow/propagation/install/path/relative.test.js +0 -239
  51. package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +0 -158
  52. package/lib/dataflow/propagation/install/pug/index.test.js +0 -55
  53. package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +0 -69
  54. package/lib/dataflow/propagation/install/querystring/escape.test.js +0 -63
  55. package/lib/dataflow/propagation/install/querystring/index.test.js +0 -40
  56. package/lib/dataflow/propagation/install/querystring/parse.test.js +0 -272
  57. package/lib/dataflow/propagation/install/querystring/stringify.test.js +0 -301
  58. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +0 -283
  59. package/lib/dataflow/propagation/install/send.test.js +0 -63
  60. package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +0 -74
  61. package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +0 -119
  62. package/lib/dataflow/propagation/install/sql-template-strings.test.js +0 -100
  63. package/lib/dataflow/propagation/install/string/concat.test.js +0 -145
  64. package/lib/dataflow/propagation/install/string/format-methods.test.js +0 -74
  65. package/lib/dataflow/propagation/install/string/html-methods.test.js +0 -177
  66. package/lib/dataflow/propagation/install/string/index.test.js +0 -103
  67. package/lib/dataflow/propagation/install/string/match-all.test.js +0 -412
  68. package/lib/dataflow/propagation/install/string/match.test.js +0 -374
  69. package/lib/dataflow/propagation/install/string/replace.test.js +0 -601
  70. package/lib/dataflow/propagation/install/string/slice.test.js +0 -278
  71. package/lib/dataflow/propagation/install/string/split.test.js +0 -513
  72. package/lib/dataflow/propagation/install/string/substring.test.js +0 -251
  73. package/lib/dataflow/propagation/install/string/trim.test.js +0 -135
  74. package/lib/dataflow/propagation/install/unescape.test.js +0 -78
  75. package/lib/dataflow/propagation/install/url/domain-parsers.test.js +0 -63
  76. package/lib/dataflow/propagation/install/url/parse.test.js +0 -391
  77. package/lib/dataflow/propagation/install/url/searchParams.test.js +0 -538
  78. package/lib/dataflow/propagation/install/url/url.test.js +0 -466
  79. package/lib/dataflow/propagation/install/util-format.test.js +0 -336
  80. package/lib/dataflow/propagation/install/validator/hooks.test.js +0 -211
  81. package/lib/dataflow/sinks/index.test.js +0 -78
  82. package/lib/dataflow/sinks/install/child-process.test.js +0 -338
  83. package/lib/dataflow/sinks/install/eval.test.js +0 -95
  84. package/lib/dataflow/sinks/install/express/index.test.js +0 -33
  85. package/lib/dataflow/sinks/install/express/reflected-xss.test.js +0 -109
  86. package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +0 -144
  87. package/lib/dataflow/sinks/install/fastify/index.test.js +0 -32
  88. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +0 -130
  89. package/lib/dataflow/sinks/install/fs.test.js +0 -138
  90. package/lib/dataflow/sinks/install/function.test.js +0 -103
  91. package/lib/dataflow/sinks/install/hapi/index.test.js +0 -32
  92. package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +0 -130
  93. package/lib/dataflow/sinks/install/http/index.test.js +0 -33
  94. package/lib/dataflow/sinks/install/http/request.test.js +0 -184
  95. package/lib/dataflow/sinks/install/http/server-response.test.js +0 -160
  96. package/lib/dataflow/sinks/install/koa/index.test.js +0 -32
  97. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +0 -200
  98. package/lib/dataflow/sinks/install/libxmljs.test.js +0 -158
  99. package/lib/dataflow/sinks/install/marsdb.test.js +0 -166
  100. package/lib/dataflow/sinks/install/mongodb.test.js +0 -617
  101. package/lib/dataflow/sinks/install/mssql.test.js +0 -134
  102. package/lib/dataflow/sinks/install/mysql.test.js +0 -224
  103. package/lib/dataflow/sinks/install/node-serialize.test.js +0 -83
  104. package/lib/dataflow/sinks/install/postgres.test.js +0 -152
  105. package/lib/dataflow/sinks/install/restify.test.js +0 -140
  106. package/lib/dataflow/sinks/install/sequelize.test.js +0 -100
  107. package/lib/dataflow/sinks/install/sqlite3.test.js +0 -118
  108. package/lib/dataflow/sinks/install/vm.test.js +0 -326
  109. package/lib/dataflow/sources/handler.test.js +0 -501
  110. package/lib/dataflow/sources/index.test.js +0 -60
  111. package/lib/dataflow/sources/install/body-parser1.test.js +0 -244
  112. package/lib/dataflow/sources/install/busboy.test.js +0 -152
  113. package/lib/dataflow/sources/install/cookie-parser1.test.js +0 -141
  114. package/lib/dataflow/sources/install/express/params.test.js +0 -110
  115. package/lib/dataflow/sources/install/express/parsedUrl.test.js +0 -107
  116. package/lib/dataflow/sources/install/fastify/fastify.test.js +0 -207
  117. package/lib/dataflow/sources/install/fastify/index.test.js +0 -33
  118. package/lib/dataflow/sources/install/formidable1.test.js +0 -119
  119. package/lib/dataflow/sources/install/graphql-http.test.js +0 -133
  120. package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -171
  121. package/lib/dataflow/sources/install/hapi/index.test.js +0 -33
  122. package/lib/dataflow/sources/install/http.test.js +0 -149
  123. package/lib/dataflow/sources/install/koa/index.test.js +0 -40
  124. package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +0 -160
  125. package/lib/dataflow/sources/install/koa/koa-multer.test.js +0 -197
  126. package/lib/dataflow/sources/install/koa/koa-routers.test.js +0 -146
  127. package/lib/dataflow/sources/install/koa/koa2.test.js +0 -145
  128. package/lib/dataflow/sources/install/multer1.test.js +0 -143
  129. package/lib/dataflow/sources/install/qs6.test.js +0 -131
  130. package/lib/dataflow/sources/install/querystring.test.js +0 -82
  131. package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +0 -86
  132. package/lib/dataflow/sources/install/restify/index.test.js +0 -38
  133. package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +0 -140
  134. package/lib/dataflow/sources/install/restify/router.test.js +0 -81
  135. package/lib/dataflow/tag-utils-complete.test.js +0 -27
  136. package/lib/dataflow/tag-utils.test.js +0 -192
  137. package/lib/dataflow/tracker.test.js +0 -216
  138. package/lib/dataflow/utils/is-safe-content-type.test.js +0 -16
  139. package/lib/dataflow/utils/is-vulnerable.test.js +0 -115
  140. package/lib/event-factory.test.js +0 -326
  141. package/lib/get-policy.test.js +0 -194
  142. package/lib/get-source-context.test.js +0 -161
  143. package/lib/index.test.js +0 -45
  144. package/lib/make-source-context.test.js +0 -50
  145. package/lib/response-scanning/handlers/index.test.js +0 -419
  146. package/lib/response-scanning/handlers/utils.test.js +0 -380
  147. package/lib/response-scanning/index.test.js +0 -41
  148. package/lib/response-scanning/install/http.test.js +0 -175
  149. package/lib/rule-scopes.test.js +0 -27
  150. package/lib/sampler/common.test.js +0 -101
  151. package/lib/sampler/index.test.js +0 -313
  152. package/lib/session-configuration/handlers.test.js +0 -84
  153. package/lib/session-configuration/index.test.js +0 -36
  154. package/lib/session-configuration/install/express-session.test.js +0 -218
  155. package/lib/session-configuration/install/fastify-cookie.test.js +0 -63
  156. package/lib/session-configuration/install/hapi.test.js +0 -269
  157. package/lib/session-configuration/install/koa.test.js +0 -92
@@ -1,301 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const {
5
- DataflowTag: { URL_ENCODED, UNTRUSTED }
6
- } = require('@contrast/common');
7
- const { initAssessFixture } = require('@contrast/test/fixtures');
8
-
9
- describe('assess dataflow propagation querystring stringify', function () {
10
- let core, simulateRequestScope, tracker, trackString, querystring;
11
-
12
- before(function () {
13
- ({ core, trackString, simulateRequestScope } = initAssessFixture());
14
- tracker = core.assess.dataflow.tracker;
15
-
16
- querystring = require('querystring');
17
- core.depHooks.resolve.yields(querystring);
18
-
19
- core.assess.dataflow.propagation.stringInstrumentation.concat.install();
20
- core.assess.dataflow.propagation.querystringInstrumentation.escape.install();
21
- core.assess.dataflow.propagation.querystringInstrumentation.stringify.install();
22
- });
23
-
24
- after(function () {
25
- core.assess.dataflow.propagation.stringInstrumentation.concat.uninstall();
26
- core.assess.dataflow.propagation.querystringInstrumentation.escape.uninstall();
27
- core.assess.dataflow.propagation.querystringInstrumentation.stringify.uninstall();
28
- });
29
-
30
- [
31
- 'stringify',
32
- 'encode',
33
- ].forEach((methodName) => {
34
- const baseEvent = {
35
- moduleName: 'querystring',
36
- methodName: 'stringify',
37
- object: { tracked: false, value: 'querystring' },
38
- source: 'P',
39
- target: 'R',
40
- };
41
-
42
- describe(`querystring.${methodName}`, function () {
43
-
44
- it('no action is taken when result is not a string', function () {
45
- simulateRequestScope(() => {
46
- [null, undefined, 'foo', {}, []].forEach((value) => {
47
- const result = querystring.stringify(value);
48
- expect(tracker.getData(result)).to.be.null;
49
- });
50
- });
51
- });
52
-
53
- it('result should not be tracked if no object values are tracked', function () {
54
- simulateRequestScope(() => {
55
- const obj = {
56
- x: 'abcd',
57
- y: 'bcde',
58
- z: '',
59
- w: 'cdef'
60
- };
61
- const result = querystring.stringify(obj);
62
- expect(tracker.getData(result)).to.be.null;
63
- });
64
- });
65
-
66
- it('should propagate tags correctly for flat object with tracked values (values unchanged)', function () {
67
- simulateRequestScope(() => {
68
- const obj = {
69
- x: trackString('abcd'),
70
- y: trackString('bcde'),
71
- z: '',
72
- w: 'cdef',
73
- aa: ['a', trackString('b')],
74
- bb: { c: 'd' },
75
- };
76
- const result = querystring.stringify(obj);
77
- const strInfo = tracker.getData(result);
78
-
79
- expect(strInfo).to.deep.include({
80
- ...baseEvent,
81
- context: 'querystring.stringify({\n x: \'abcd\',\n y: \'bcde\',\n z: \'\',\n w: \'cdef\',\n aa: [ \'a\', \'b\' ],\n bb: { c: \'d\' }\n})',
82
- result: { tracked: true, value: 'x=abcd&y=bcde&z=&w=cdef&aa=a&aa=b&bb=' },
83
- tags: {
84
- [UNTRUSTED]: [2, 5, 9, 12, 32, 32],
85
- [URL_ENCODED]: [2, 5, 9, 12, 32, 32],
86
- },
87
- value: 'x=abcd&y=bcde&z=&w=cdef&aa=a&aa=b&bb=',
88
- });
89
- expect(strInfo.history).to.have.lengthOf(3);
90
- });
91
- });
92
-
93
- it('should propagate tags correctly for flat object with tracked values (values percent encoded)', function () {
94
- simulateRequestScope(() => {
95
- const obj = {
96
- x: trackString('✓😐🙉'),
97
- y: trackString('/?#'),
98
- z: '',
99
- w: 'cdef'
100
- };
101
- const result = querystring.stringify(obj);
102
- const strInfo = tracker.getData(result);
103
-
104
- expect(strInfo).to.deep.include({
105
- ...baseEvent,
106
- context: 'querystring.stringify({ x: \'✓😐🙉\', y: \'/?#\', z: \'\', w: \'cdef\' })',
107
- result: {
108
- tracked: true,
109
- value: 'x=%E2%9C%93%F0%9F%98%90%F0%9F%99%89&y=%2F%3F%23&z=&w=cdef'
110
- },
111
- tags: {
112
- [UNTRUSTED]: [2, 34, 38, 46],
113
- [URL_ENCODED]: [2, 34, 38, 46],
114
- },
115
- // ✓ 😐 🙉 / ? #
116
- value: 'x=%E2%9C%93%F0%9F%98%90%F0%9F%99%89&y=%2F%3F%23&z=&w=cdef'
117
- });
118
- expect(strInfo.history).to.have.lengthOf(2);
119
- });
120
- });
121
-
122
- it('will propagate tags correctly through custom encoding function (custom validators disabled)', function () {
123
- simulateRequestScope(() => {
124
- const obj = {
125
- foo: ['a', trackString('b'), trackString('c')],
126
- bar: 'baz'
127
- };
128
- const options = {
129
- encodeURIComponent(value) {
130
- return value.concat('_');
131
- }
132
- };
133
- const result = querystring.stringify(obj, false, false, options);
134
- const strInfo = tracker.getData(result);
135
-
136
- expect(strInfo).to.deep.include({
137
- ...baseEvent,
138
- context: 'querystring.stringify({ foo: [ \'a\', \'b\', \'c\' ], bar: \'baz\' }, false, false, { encodeURIComponent: [Function: encodeURIComponent] })',
139
- result: { tracked: true, value: 'foo_=a_&foo_=b_&foo_=c_&bar_=baz_' },
140
- tags: {
141
- [UNTRUSTED]: [13, 14, 21, 22],
142
- },
143
- value: 'foo_=a_&foo_=b_&foo_=c_&bar_=baz_',
144
- });
145
- expect(strInfo.tags).not.to.have.property(URL_ENCODED);
146
- expect(strInfo.history).to.have.lengthOf(2);
147
- });
148
- });
149
-
150
- // NODE-2835
151
- it.skip('will propagate tags correctly through custom encoding function (custom validators enabled)', function () {
152
- core.config.assess.trust_custom_validators = true;
153
- simulateRequestScope(() => {
154
- const obj = {
155
- foo: ['a', trackString('b'), trackString('c')],
156
- bar: 'baz'
157
- };
158
- const options = {
159
- encodeURIComponent(value) {
160
- return value.concat('_');
161
- }
162
- };
163
- const result = querystring.stringify(obj, false, false, options);
164
- const strInfo = tracker.getData(result);
165
-
166
- expect(strInfo).to.deep.include({
167
- ...baseEvent,
168
- context: 'querystring.stringify({ foo: [ \'a\', \'b\', \'c\' ], bar: \'baz\' }, false, false, { encodeURIComponent: [Function: encodeURIComponent] })',
169
- result: { tracked: true, value: 'foo_=a_&foo_=b_&foo_=c_&bar_=baz_' },
170
- tags: {
171
- [UNTRUSTED]: [13, 14, 21, 22],
172
- [URL_ENCODED]: [13, 14, 21, 22],
173
- },
174
- value: 'foo_=a_&foo_=b_&foo_=c_&bar_=baz_',
175
- });
176
- expect(strInfo.history).to.have.lengthOf(2);
177
- });
178
- });
179
-
180
- it('options with encodeURIComponent (add\'l tagged string in escape)', function () {
181
- simulateRequestScope(() => {
182
- const obj = {
183
- foo: trackString('a'),
184
- bar: ['b', 'c']
185
- };
186
- const options = {
187
- encodeURIComponent(value) {
188
- return value.concat(trackString('_'));
189
- }
190
- };
191
- const result = querystring.stringify(obj, false, false, options);
192
- const strInfo = tracker.getData(result);
193
-
194
- expect(strInfo).to.deep.include({
195
- ...baseEvent,
196
- context: 'querystring.stringify({ foo: \'a\', bar: [ \'b\', \'c\' ] }, false, false, { encodeURIComponent: [Function: encodeURIComponent] })',
197
- result: { tracked: true, value: 'foo_=a_&bar_=b_&bar_=c_' },
198
- tags: {
199
- [UNTRUSTED]: [3, 3, 5, 6, 11, 11, 13, 14, 19, 19, 21, 22],
200
- },
201
- value: 'foo_=a_&bar_=b_&bar_=c_',
202
- });
203
- expect(strInfo.history).to.have.lengthOf(5);
204
- });
205
- });
206
-
207
- it('should handle multi-char separators and eq', function () {
208
- simulateRequestScope(() => {
209
- const obj = {
210
- x: trackString('abcd'),
211
- y: trackString('bcde'),
212
- z: '',
213
- w: 'cdef'
214
- };
215
- const result = querystring.stringify(obj, '&&&', '====');
216
- const strInfo = tracker.getData(result);
217
-
218
- expect(strInfo).to.deep.include({
219
- ...baseEvent,
220
- context: 'querystring.stringify({ x: \'abcd\', y: \'bcde\', z: \'\', w: \'cdef\' }, \'&&&\', \'====\')',
221
- result: { tracked: true, value: 'x====abcd&&&y====bcde&&&z====&&&w====cdef' },
222
- tags: {
223
- [UNTRUSTED]: [5, 8, 17, 20],
224
- [URL_ENCODED]: [5, 8, 17, 20],
225
- },
226
- value: 'x====abcd&&&y====bcde&&&z====&&&w====cdef',
227
- });
228
- expect(strInfo.history).to.have.lengthOf(2);
229
- });
230
- });
231
-
232
- it('should propagate if `separator` or `equals` char is also contained in key or value', function () {
233
- simulateRequestScope(() => {
234
- const obj = {
235
- x: trackString('abcd'),
236
- y: trackString('bcde'),
237
- z: '',
238
- w: 'cdef'
239
- };
240
- const result = querystring.stringify(obj, 'a', 'b');
241
- const strInfo = tracker.getData(result);
242
-
243
- expect(strInfo).to.deep.include({
244
- ...baseEvent,
245
- context: 'querystring.stringify({ x: \'abcd\', y: \'bcde\', z: \'\', w: \'cdef\' }, \'a\', \'b\')',
246
- result: { tracked: true, value: 'xbabcdaybbcdeazbawbcdef' },
247
- tags: {
248
- [UNTRUSTED]: [2, 5, 9, 12],
249
- [URL_ENCODED]: [2, 5, 9, 12],
250
- },
251
- value: 'xbabcdaybbcdeazbawbcdef',
252
- });
253
- expect(strInfo.history).to.have.lengthOf(2);
254
- });
255
- });
256
-
257
- it('should handle multiple tag ranges being shifted', function () {
258
- simulateRequestScope(() => {
259
- const obj = {
260
- x: trackString('one😐two🙉three', {
261
- tags: {
262
- tag1: [0, 2],
263
- tag2: [5, 7],
264
- tag3: [10, 14],
265
- }
266
- }),
267
- y: trackString('one#two?three', {
268
- tags: {
269
- tag1: [0, 2],
270
- tag2: [4, 6],
271
- tag3: [8, 12],
272
- }
273
- }),
274
- };
275
- const result = querystring.stringify(obj);
276
- const strInfo = tracker.getData(result);
277
-
278
- expect(strInfo).to.deep.include({
279
- ...baseEvent,
280
- result: { tracked: true, value: 'x=one%F0%9F%98%90two%F0%9F%99%89three&y=one%23two%3Fthree' },
281
- tags: {
282
- tag1: [2, 36, 40, 56],
283
- tag2: [2, 36, 40, 56],
284
- tag3: [2, 36, 40, 56],
285
- [URL_ENCODED]: [2, 36, 40, 56],
286
- },
287
- value: 'x=one%F0%9F%98%90two%F0%9F%99%89three&y=one%23two%3Fthree',
288
- });
289
- expect(strInfo.history).to.have.lengthOf(2);
290
- });
291
- });
292
-
293
- it.skip('should propagate tags from basic keys', function () {
294
- // this is also skipped in v4 b/c tracking object keys causes issues
295
- // const obj = {
296
- // [trackString('x')] = 'abcd',
297
- // };
298
- });
299
- });
300
- });
301
- });
@@ -1,283 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const { inspect } = require('util');
5
- const { DataflowTag: { UNTRUSTED, CUSTOM_ENCODED, LIMITED_CHARS } } = require('@contrast/common');
6
- const { initAssessFixture } = require('@contrast/test/fixtures');
7
-
8
- describe('assess dataflow propagation RegExp exec', function () {
9
- let core, simulateRequestScope, trackString, tracker, instr;
10
-
11
- beforeEach(function () {
12
- ({
13
- core,
14
- trackString,
15
- simulateRequestScope
16
- } = initAssessFixture());
17
-
18
- tracker = core.assess.dataflow.tracker;
19
- instr = require('./reg-exp-prototype-exec')(core);
20
- instr.install();
21
- });
22
-
23
- afterEach(function () {
24
- instr.uninstall();
25
- });
26
-
27
- describe('base cases', function () {
28
- [
29
- [],
30
- [undefined],
31
- ['']
32
- ].forEach((val) => {
33
- it(`returns null when called with ${inspect(val[0])}`, function () {
34
- simulateRequestScope(() => {
35
- const re = /test/;
36
- const ret = re.exec(val[0]);
37
-
38
- expect(ret).to.be.null;
39
- });
40
- });
41
- });
42
-
43
- it('returns null when no match is found', function () {
44
- simulateRequestScope(() => {
45
- const re = /test/;
46
- const ret = re.exec('foo');
47
-
48
- expect(ret).to.be.null;
49
- });
50
- });
51
-
52
- it('returns only the first match string', function () {
53
- simulateRequestScope(() => {
54
- const re = /o/;
55
- const ret = re.exec('foo');
56
-
57
- expect(ret).to.deep.equal(['o']);
58
- expect(tracker.getData(ret[0])).to.be.null;
59
- });
60
- });
61
-
62
- it('returns first match string using capture groups', function () {
63
- simulateRequestScope(() => {
64
- const re = /(f)|(o)/;
65
- const ret = re.exec('foo');
66
- expect(ret).to.deep.equal(['f', 'f', undefined]);
67
- expect(ret.groups).to.be.undefined;
68
- ret.forEach((val) => {
69
- expect(tracker.getData(val)).to.be.null;
70
- });
71
- });
72
- });
73
-
74
- it('returns first match string using named capture groups', function () {
75
- simulateRequestScope(() => {
76
- const re = /(?<foo>f)|(?<bar>o)/;
77
- const ret = re.exec('foo');
78
- expect(ret).to.deep.equal(['f', 'f', undefined]);
79
- expect(ret.groups.foo).to.equal('f');
80
- ret.forEach((val) => {
81
- expect(tracker.getData(val)).to.be.null;
82
- });
83
- });
84
- });
85
- });
86
-
87
- describe('propagation', function () {
88
- it('propagates a fully tracked string', function () {
89
- simulateRequestScope(() => {
90
- const re = /f/;
91
- const extern = trackString('foo');
92
-
93
- const ret = re.exec(extern);
94
- const matchInfo = tracker.getData(ret[0]);
95
-
96
- expect(ret).to.deep.equal(['f']);
97
- expect(matchInfo.tags).to.deep.equal({
98
- [UNTRUSTED]: [0, 0]
99
- });
100
- expect(matchInfo.name).to.equal('RegExp.prototype.exec');
101
- });
102
- });
103
-
104
- it.skip('propagates strings when iteratively called', function() {
105
- simulateRequestScope(() => {
106
- const re = /^\/?$/i;
107
- // eslint-disable-next-line
108
- const extern = trackString('');
109
-
110
- let ret;
111
- while ((ret = re.exec(''))) {
112
- // eslint-disable-next-line
113
- const matchInfo = tracker.getData(ret[0]);
114
- // console.log(re.lastIndex, ret.index, ret.indices);
115
- re.lastIndex += 1;
116
- //console.log(matchInfo);
117
- // check match info...
118
- }
119
- });
120
- });
121
-
122
- it('propagates a partialy tracked string', function () {
123
- simulateRequestScope(() => {
124
- const re = /bar/;
125
- const extern = trackString('foobar', {
126
- tags: {
127
- [UNTRUSTED]: [0, 4]
128
- }
129
- });
130
-
131
- const ret = re.exec(extern);
132
- const matchInfo = tracker.getData(ret[0]);
133
-
134
- expect(ret).to.deep.equal(['bar']);
135
- expect(matchInfo.tags).to.deep.equal({
136
- [UNTRUSTED]: [0, 1]
137
- });
138
- expect(matchInfo.name).to.equal('RegExp.prototype.exec');
139
- });
140
- });
141
-
142
- it('does not propagate if we exeeded the maximum propagation count for a match', function () {
143
- simulateRequestScope(() => {
144
- const re = /foo/;
145
- const extern = trackString('foobar');
146
-
147
- const ret = re.exec(extern);
148
- const matchInfo = tracker.getData(ret[0]);
149
-
150
- expect(ret).to.deep.equal(['foo']);
151
- expect(matchInfo).to.be.null;
152
- }, { assess: { propagationEventsCount: 500 } });
153
- });
154
-
155
- it('does not propagate if we exeeded the maximum propagation count for a group', function () {
156
- simulateRequestScope(() => {
157
- core.scopes.sources.getStore().assess.propagationEventsCount = 498;
158
-
159
- const re = /foo(?<bar>bar)/;
160
- const extern = trackString('foobar');
161
-
162
- const ret = re.exec(extern);
163
- const foobarInfo = tracker.getData(ret[0]);
164
- const barInfo = tracker.getData(ret[1]);
165
- const barGroupInfo = tracker.getData(ret.groups.b);
166
-
167
- expect(ret).to.deep.equal([
168
- 'foobar',
169
- 'bar'
170
- ]);
171
- expect(ret.groups.bar).to.equal('bar');
172
- expect(foobarInfo.tags).to.deep.equal({
173
- [UNTRUSTED]: [0, 5]
174
- });
175
- expect(barInfo.tags).to.deep.equal({
176
- [UNTRUSTED]: [0, 2]
177
- });
178
- expect(barGroupInfo).to.be.null;
179
- });
180
- });
181
-
182
-
183
- it('handles RegExp that matches an empty string', function () {
184
- simulateRequestScope(() => {
185
- const re = /foo(?<empty>)bar/;
186
- const extern = trackString('foobar');
187
-
188
- const ret = re.exec(extern);
189
- const matchInfo = tracker.getData(ret[0]);
190
- const emptyMatchInfo = tracker.getData(ret[1]);
191
- const emptyGroupInfo = tracker.getData(ret.groups.empty);
192
-
193
- expect(ret).to.deep.equal([
194
- 'foobar',
195
- '',
196
- ]);
197
- expect(matchInfo.tags).to.deep.equal({
198
- [UNTRUSTED]: [0, 5]
199
- });
200
- expect(matchInfo.name).to.equal('RegExp.prototype.exec');
201
- expect(emptyMatchInfo).to.be.null;
202
- expect(ret.groups.empty).to.equal('');
203
- expect(emptyGroupInfo).to.be.null;
204
- });
205
- });
206
-
207
- it('handles RegExp that matches the full string', function () {
208
- simulateRequestScope(() => {
209
- const re = /(?<full>foobar)/;
210
- const extern = trackString('foobar');
211
-
212
- const ret = re.exec(extern);
213
- const matchInfo = tracker.getData(ret[0]);
214
- const captrueMatchInfo = tracker.getData(ret[1]);
215
- const fullGroupInfo = tracker.getData(ret.groups.full);
216
-
217
- expect(ret).to.deep.equal([
218
- 'foobar',
219
- 'foobar',
220
- ]);
221
- expect(matchInfo.tags).to.deep.equal({
222
- [UNTRUSTED]: [0, 5]
223
- });
224
- expect(matchInfo.name).to.equal('RegExp.prototype.exec');
225
- expect(captrueMatchInfo.tags).to.deep.equal({
226
- [UNTRUSTED]: [0, 5]
227
- });
228
- expect(captrueMatchInfo.name).to.equal('RegExp.prototype.exec');
229
- expect(ret.groups.full).to.equal('foobar');
230
- expect(fullGroupInfo.tags).to.deep.equal({
231
- [UNTRUSTED]: [0, 5]
232
- });
233
- expect(fullGroupInfo.name).to.equal('RegExp.prototype.exec');
234
- });
235
- });
236
-
237
- it('handles complex cases', function () {
238
- simulateRequestScope(() => {
239
- const re = /quick\s(?<color>brown|black).+?(jumps).+(Black)/gi;
240
- // 01234567890123456789012345678901234567890123456789012345678
241
- const extern = trackString('The Quick Brown Fox Jumps Over The Lazy Black And Brown Dog', {
242
- // 1 2 3 4 5
243
- tags: {
244
- [UNTRUSTED]: [0, 6, 13, 15, 40, 44],
245
- [CUSTOM_ENCODED]: [16, 19],
246
- [LIMITED_CHARS]: [20, 29, 40, 58]
247
- }
248
- });
249
-
250
- const ret = re.exec(extern);
251
- const fullMatchInfo = tracker.getData(ret[0]);
252
- const brownInfo = tracker.getData(ret[1]);
253
- const jumpsInfo = tracker.getData(ret[2]);
254
- const blackInfo = tracker.getData(ret[3]);
255
- const colorGroupInfo = tracker.getData(ret.groups.color);
256
-
257
- expect(ret).to.deep.equal([
258
- 'Quick Brown Fox Jumps Over The Lazy Black',
259
- 'Brown',
260
- 'Jumps',
261
- 'Black'
262
- ]);
263
- expect(ret.groups.color).to.equal('Brown');
264
- expect(fullMatchInfo.tags).to.deep.equal({
265
- [UNTRUSTED]: [0, 2, 9, 11, 36, 40],
266
- [CUSTOM_ENCODED]: [12, 15],
267
- [LIMITED_CHARS]: [16, 25, 36, 40]
268
- });
269
- expect(brownInfo.tags).to.deep.equal({
270
- [UNTRUSTED]: [3, 4],
271
- });
272
- expect(jumpsInfo.tags).to.deep.equal({
273
- [LIMITED_CHARS]: [0, 4]
274
- });
275
- expect(blackInfo.tags).to.deep.equal({
276
- [UNTRUSTED]: [0, 4],
277
- [LIMITED_CHARS]: [0, 4]
278
- });
279
- expect(colorGroupInfo.tags).to.deep.equal(brownInfo.tags);
280
- });
281
- });
282
- });
283
- });
@@ -1,63 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const { initAssessFixture } = require('../../../../../test/fixtures');
6
- const {
7
- DataflowTag: { UNTRUSTED }
8
- } = require('@contrast/common');
9
-
10
- describe('assess send', function() {
11
- let core, simulateRequestScope, mockSend, sendInstanceMock, trackString, tracker;
12
-
13
- beforeEach(function() {
14
- ({
15
- core,
16
- simulateRequestScope,
17
- trackString
18
- } = initAssessFixture());
19
-
20
- tracker = core.assess.dataflow.tracker;
21
-
22
- sendInstanceMock = {
23
- sendFile: sinon.stub()
24
- };
25
-
26
- require('./send')(core).install();
27
-
28
- const result = core.depHooks.resolve.yield(() => sendInstanceMock);
29
- mockSend = result[0];
30
- });
31
-
32
- afterEach(function() {
33
- sinon.resetHistory();
34
- });
35
-
36
- it('should skip instrumentation if it is out of scope', function() {
37
- const path = trackString('foo');
38
- sendInstanceMock.sendFile = (path) => {
39
- expect(tracker.getData(path)).to.be.null;
40
- };
41
-
42
- const { sendFile } = mockSend();
43
- sendFile(path);
44
- });
45
-
46
- it('should create an untagged copy of the string', function() {
47
- simulateRequestScope(() => {
48
- const path = trackString('foo');
49
-
50
- sendInstanceMock.sendFile = (path) => {
51
- expect(tracker.getData(path)).to.be.null;
52
- };
53
-
54
- const { sendFile } = mockSend();
55
- sendFile(path);
56
-
57
- const stringInfo = tracker.getData(path);
58
- expect(stringInfo.tags).to.be.eql({
59
- [UNTRUSTED]: [0, 2]
60
- });
61
- });
62
- });
63
- });