@contrast/assess 1.46.1 → 1.46.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,501 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const {
6
- DataflowTag,
7
- InputType
8
- } = require('@contrast/common');
9
- const { initAssessFixture } = require('@contrast/test/fixtures');
10
-
11
- describe('assess dataflow sources handler', function () {
12
- let core, simulateRequestScope, sources, tracker;
13
-
14
- beforeEach(function () {
15
- ({ core, simulateRequestScope } = initAssessFixture());
16
- core.config.assess.max_context_source_events = 100;
17
-
18
- // we want to remove previous calls to `logger` methods from before these tests.
19
- sinon.reset();
20
-
21
- sources = core.assess.dataflow.sources;
22
- tracker = core.assess.dataflow.tracker;
23
-
24
- sinon.spy(tracker, 'track');
25
- core.assess.dataflow.propagation.bufferInstrumentation.install();
26
- });
27
-
28
- it('composes methods on core correctly', function () {
29
- expect(sources.createTags).to.be.a('function');
30
- expect(sources.handle).to.be.a('function');
31
- });
32
-
33
- describe('createTags', function () {
34
- [
35
- {
36
- arg: {
37
- value: ''
38
- },
39
- expected: null,
40
- },
41
- {
42
- arg: {
43
- value: undefined
44
- },
45
- expected: null,
46
- },
47
- {
48
- arg: {
49
- inputType: InputType.QUERYSTRING,
50
- name: 'foo',
51
- value: 'a',
52
- },
53
- expected: {
54
- [DataflowTag.UNTRUSTED]: [0, 0]
55
- }
56
- },
57
- {
58
- arg: {
59
- inputType: InputType.QUERYSTRING,
60
- fieldName: 'foo',
61
- value: 'ab',
62
- },
63
- expected: {
64
- [DataflowTag.UNTRUSTED]: [0, 1]
65
- }
66
- },
67
- {
68
- arg: {
69
- inputType: InputType.HEADER,
70
- fieldName: 'foo',
71
- value: 'abcd',
72
- },
73
- expected: {
74
- [DataflowTag.UNTRUSTED]: [0, 3]
75
- }
76
- },
77
- {
78
- arg: {
79
- inputType: InputType.HEADER,
80
- fieldName: 'referer',
81
- value: 'abcd',
82
- tagNames: ['excluded:sql-injection'],
83
- },
84
- expected: {
85
- [DataflowTag.HEADER]: [0, 3],
86
- [DataflowTag.UNTRUSTED]: [0, 3],
87
- ['excluded:sql-injection']: [0, 3],
88
- }
89
- }
90
- ].forEach(({ arg, expected }) => {
91
- it('creates expected tags based on name, value, and input type', function () {
92
- const result = sources.createTags(arg);
93
- expect(result).to.deep.equal(expected);
94
- });
95
- });
96
- });
97
-
98
- describe('handle', function () {
99
- it('does not handle when no assess source context is active', function () {
100
- const result = sources.handle({
101
- name: 'test-source-name',
102
- inputType: InputType.QUERYSTRING,
103
- data: {
104
- prop1: 'foo',
105
- }
106
- });
107
- expect(result).to.be.null;
108
- });
109
-
110
- it('does nothing when async store\'s assess policy is null', function () {
111
- simulateRequestScope(() => {
112
- const sourceContext = core.scopes.sources.getStore()?.assess;
113
- const trackedObj = sources.handle({
114
- name: 'test-source-name',
115
- inputType: InputType.QUERYSTRING,
116
- sourceContext
117
- });
118
-
119
- expect(trackedObj).to.be.undefined;
120
- expect(core.logger.trace).not.to.have.been.called;
121
- expect(core.logger.warn).not.to.have.been.called;
122
- expect(tracker.track).not.to.have.been.called;
123
- }, { assess: { policy: null } });
124
- });
125
-
126
- it('does nothing when no data is passed', function () {
127
- simulateRequestScope(() => {
128
- const sourceContext = core.scopes.sources.getStore()?.assess;
129
- const trackedObj = sources.handle({
130
- name: 'test-source-name',
131
- inputType: InputType.QUERYSTRING,
132
- sourceContext
133
- });
134
-
135
- expect(trackedObj).to.be.undefined;
136
- expect(core.logger.trace).not.to.have.been.called;
137
- expect(core.logger.warn).not.to.have.been.called;
138
- expect(tracker.track).not.to.have.been.called;
139
- });
140
- });
141
-
142
- ['SINK', 'NONE'].forEach((option) => {
143
- it(`does not capture stacktrace for assess.stacktraces=${option}`, function() {
144
- simulateRequestScope(() => {
145
- const sourceContext = core.scopes.sources.getStore()?.assess;
146
- core.config.assess.stacktraces = option;
147
- const trackedObj = sources.handle({
148
- name: 'test-source-name',
149
- inputType: InputType.QUERYSTRING,
150
- data: { prop1: 'foo' },
151
- sourceContext
152
- });
153
-
154
- const trackData = tracker.getData(trackedObj.prop1);
155
- expect(trackData.stack).to.deep.equal([]);
156
- });
157
- });
158
- });
159
-
160
- ['SOME', 'ALL'].forEach((option) => {
161
- it(`captures stacktrace for assess.stacktraces=${option}`, function() {
162
- simulateRequestScope(() => {
163
- const sourceContext = core.scopes.sources.getStore()?.assess;
164
- core.config.assess.stacktraces = option;
165
- const trackedObj = sources.handle({
166
- name: 'test-source-name',
167
- inputType: InputType.QUERYSTRING,
168
- data: { prop1: 'foo' },
169
- sourceContext
170
- });
171
-
172
- const trackData = tracker.getData(trackedObj.prop1);
173
- expect(trackData.stack).to.be.instanceOf(Array);
174
- expect(trackData.stack.length).to.be.greaterThan(0);
175
- });
176
- });
177
- });
178
-
179
-
180
- it('traverses objects and tracks string values', function () {
181
- simulateRequestScope(() => {
182
- const sourceContext = core.scopes.sources.getStore()?.assess;
183
- const trackedObj = sources.handle({
184
- name: 'test-source-name',
185
- inputType: InputType.QUERYSTRING,
186
- data: {
187
- prop1: 'foo',
188
- prop2: ['bar', 'bugs'],
189
- },
190
- sourceContext
191
- });
192
-
193
- expect(tracker.getData(trackedObj.prop1)).to.be.like({
194
- name: 'test-source-name',
195
- pathName: 'prop1',
196
- result: { tracked: true, value: 'foo' },
197
- inputType: InputType.QUERYSTRING,
198
- stack: [],
199
- value: 'foo',
200
- tags: {
201
- [DataflowTag.UNTRUSTED]: [0, 2],
202
- },
203
- });
204
-
205
- expect(tracker.getData(trackedObj.prop2[0])).to.be.like({
206
- name: 'test-source-name',
207
- pathName: 'prop2.0',
208
- result: { tracked: true, value: 'bar' },
209
- inputType: InputType.QUERYSTRING,
210
- stack: [],
211
- value: 'bar',
212
- tags: {
213
- [DataflowTag.UNTRUSTED]: [0, 2],
214
- },
215
- });
216
-
217
- expect(tracker.getData(trackedObj.prop2[1])).to.be.like({
218
- name: 'test-source-name',
219
- pathName: 'prop2.1',
220
- result: { tracked: true, value: 'bugs' },
221
- inputType: InputType.QUERYSTRING,
222
- stack: [],
223
- value: 'bugs',
224
- tags: {
225
- [DataflowTag.UNTRUSTED]: [0, 3],
226
- },
227
- });
228
-
229
- core.config.assess.stacktraces = 'ALL';
230
- const anotherTrackedObj = sources.handle({
231
- name: 'test-source-name',
232
- inputType: InputType.QUERYSTRING,
233
- data: { prop1: 'foo' },
234
- sourceContext
235
- });
236
-
237
- const trackData = tracker.getData(anotherTrackedObj.prop1);
238
- expect(trackData).to.be.like({
239
- name: 'test-source-name',
240
- pathName: 'prop1',
241
- result: { tracked: true, value: 'foo' },
242
- inputType: InputType.QUERYSTRING,
243
- value: 'foo',
244
- tags: {
245
- [DataflowTag.UNTRUSTED]: [0, 2],
246
- }
247
- });
248
-
249
- const pathSep = process.platform === 'win32' ? '\\' : '/';
250
-
251
- expect(trackData.stack.some((entry) => entry.file?.includes(`core${pathSep}lib${pathSep}capture-stacktrace.js`))).to.be.true;
252
- expect(trackData.stack.some((entry) => entry.method?.includes('core.createSnapshot'))).to.be.true;
253
- expect(trackData.stack.some((entry) => entry.file?.includes(`assess${pathSep}lib${pathSep}dataflow${pathSep}sources${pathSep}handler.js`))).to.be.true;
254
- expect(trackData.stack.some((entry) => entry.method?.includes('sources.handle'))).to.be.true;
255
- });
256
- });
257
-
258
- it('traverses objects and tracks string values by specific keys', function () {
259
- simulateRequestScope(() => {
260
- const sourceContext = core.scopes.sources.getStore()?.assess;
261
- const trackedObj = sources.handle({
262
- name: 'test-source-name',
263
- keys: ['prop1', 'prop3'],
264
- inputType: InputType.QUERYSTRING,
265
- data: {
266
- prop1: 'foo',
267
- prop2: ['bar', 'bugs'],
268
- prop3: {
269
- foo: 'yellow'
270
- }
271
- },
272
- sourceContext
273
- });
274
-
275
- expect(tracker.getData(trackedObj.prop1)).to.be.like({
276
- name: 'test-source-name',
277
- pathName: 'prop1',
278
- result: { tracked: true, value: 'foo' },
279
- inputType: InputType.QUERYSTRING,
280
- stack: [],
281
- value: 'foo',
282
- tags: {
283
- [DataflowTag.UNTRUSTED]: [0, 2],
284
- },
285
- });
286
- expect(tracker.getData(trackedObj.prop2[0])).to.be.null;
287
- expect(tracker.getData(trackedObj.prop2[1])).to.be.null;
288
- expect(tracker.getData(trackedObj.prop3.foo)).to.be.like({
289
- name: 'test-source-name',
290
- pathName: 'prop3.foo',
291
- result: { tracked: true, value: 'yellow' },
292
- inputType: InputType.QUERYSTRING,
293
- stack: [],
294
- value: 'yellow',
295
- tags: {
296
- [DataflowTag.UNTRUSTED]: [0, 5],
297
- },
298
- });
299
- });
300
- });
301
-
302
- it('traverses objects and tracks Buffer values', function () {
303
- simulateRequestScope(() => {
304
- const sourceContext = core.scopes.sources.getStore()?.assess;
305
- const event = {
306
- name: 'test-source-name',
307
- inputType: InputType.QUERYSTRING,
308
- data: {
309
- prop1: Buffer.from('foo'),
310
- prop2: Buffer.from('ascii', 'ascii'),
311
- prop3: Buffer.from('base64', 'base64'),
312
- prop4: Buffer.from('binary', 'binary'),
313
- prop5: {
314
- foo: Buffer.from('yellow'),
315
- },
316
- prop6: 'a string value',
317
- },
318
- sourceContext
319
- };
320
-
321
- sources.handle(event);
322
-
323
- expect(tracker.getData(event.data.prop1.toString())).to.be.ok;
324
- expect(tracker.getData(event.data.prop2.toString())).to.be.ok;
325
- expect(tracker.getData(event.data.prop3.toString())).to.be.ok;
326
- expect(tracker.getData(event.data.prop4.toString())).to.be.ok;
327
- expect(tracker.getData(event.data.prop5.foo.toString())).to.be.ok;
328
- expect(tracker.getData(event.data.prop6)).to.be.ok;
329
- // we don't cache metadata since buffer's content can change
330
- expect(
331
- tracker.getData(event.data.prop1.toString())
332
- ).not.to.equal(
333
- tracker.getData(event.data.prop1.toString())
334
- );
335
- });
336
- });
337
-
338
- it('appropriately tracks when data param is Buffer instance', function () {
339
- simulateRequestScope(() => {
340
- const sourceContext = core.scopes.sources.getStore()?.assess;
341
- const event = {
342
- name: 'test-source-name',
343
- inputType: InputType.QUERYSTRING,
344
- data: Buffer.from('foo'),
345
- sourceContext
346
- };
347
-
348
- sources.handle(event);
349
-
350
- expect(tracker.getData(event.data)).to.be.ok;
351
- });
352
- });
353
-
354
- it('exits source handling when configured max source events is reached', function () {
355
- core.config.assess.max_context_source_events = 1;
356
- simulateRequestScope(() => {
357
- const name = 'test-source-name';
358
- const sourceContext = core.scopes.sources.getStore()?.assess;
359
- const trackedObj = sources.handle({
360
- name,
361
- inputType: InputType.QUERYSTRING,
362
- data: {
363
- prop1: 'foo',
364
- prop2: ['bar', 'bugs'],
365
- },
366
- sourceContext
367
- });
368
-
369
- expect(tracker.getData(trackedObj.prop1)).to.be.like({
370
- name: 'test-source-name',
371
- pathName: 'prop1',
372
- result: { tracked: true, value: 'foo' },
373
- inputType: InputType.QUERYSTRING,
374
- stack: [],
375
- value: 'foo',
376
- tags: {
377
- [DataflowTag.UNTRUSTED]: [0, 2],
378
- },
379
- });
380
-
381
- expect(tracker.getData(trackedObj.prop2[0])).to.be.null;
382
- expect(tracker.getData(trackedObj.prop2[1])).to.be.null;
383
- expect(core.logger.trace).to.have.been.calledWith(
384
- { sourceName: name, inputType: InputType.QUERYSTRING },
385
- 'exiting assess source handling - %s max events exceeded',
386
- 1
387
- );
388
- });
389
- });
390
-
391
- it('logs an error when cannot create an event', function () {
392
- simulateRequestScope(() => {
393
- const name = 'test-source-name';
394
- const sourceContext = core.scopes.sources.getStore()?.assess;
395
- sources.handle({
396
- name,
397
- inputType: 'wrong-input-type',
398
- data: {
399
- prop1: 'foo',
400
- },
401
- sourceContext
402
- });
403
-
404
- expect(tracker.track).not.to.have.been.called;
405
- expect(core.logger.trace).not.to.have.been.called;
406
- expect(core.logger.warn).to.have.been.calledOnceWith(
407
- { inputType: 'wrong-input-type', sourceName: 'test-source-name', pathName: 'prop1', value: 'foo' },
408
- 'unable to create source event',
409
- );
410
- });
411
- });
412
- });
413
-
414
- describe('traversal', function () {
415
- const { traverse } = require('./handler');
416
- let visitorSpy;
417
-
418
- beforeEach(function () {
419
- visitorSpy = sinon.stub();
420
- });
421
-
422
- it('doesn\'t revist seen references', function () {
423
- const obj = {
424
- prop1: 'foo',
425
- prop2: { foo: 'bar' },
426
- prop3: [
427
- 'hello',
428
- ['world'],
429
- { key: 'val' },
430
- ]
431
- };
432
-
433
- obj.circ = obj;
434
-
435
- traverse(obj, (path, key, value) => {
436
- // copy path, otherwise it will be empty by assertion time
437
- visitorSpy(Array.from(path), key, value);
438
- });
439
-
440
- const visitorArgs = [
441
- [['prop1'], 'prop1', 'foo'],
442
- [['prop2', 'foo'], 'foo', 'bar'],
443
- [['prop3', '0'], '0', 'hello'],
444
- [['prop3', '1', '0'], '0', 'world'],
445
- [['prop3', '2', 'key'], 'key', 'val'],
446
- [['circ', 'prop1'], 'prop1', 'foo'],
447
- ];
448
-
449
- visitorArgs.forEach((args) => {
450
- expect(visitorSpy).to.have.been.calledWithMatch(...args);
451
- });
452
- expect(visitorSpy).to.have.callCount(visitorArgs.length);
453
- });
454
-
455
- it('will not recurse into buffers or visit numbers, null, Maps, Sets, or undefined', function () {
456
- const b = Buffer.from('buffer content');
457
-
458
- traverse({
459
- b,
460
- numberThree: 3,
461
- numberNine: Number('9'),
462
- null: null,
463
- undefined,
464
- set: new Set(['frog', 'beetle']),
465
- map: new Map([['k', 'v']])
466
- }, (path, key, value) => {
467
- visitorSpy(Array.from(path), key, value);
468
- });
469
-
470
- expect(visitorSpy).to.have.been.calledWithMatch(['b'], 'b', b).and.have.callCount(1);
471
- });
472
-
473
- it('visits and traverses objects created by Object.create(null)', function () {
474
- const o = Object.create(null);
475
- o.foo = 'bar';
476
- o.x = Object.assign(Object.create(null), { abc: 'xyz' });
477
-
478
- traverse(o, (path, key, value) => {
479
- visitorSpy(Array.from(path), key, value);
480
- });
481
-
482
- [
483
- [['foo'], 'foo', 'bar'],
484
- [['x'], 'x', { abc: 'xyz' }],
485
- [['x', 'abc'], 'abc', 'xyz']
486
- ].forEach((args) => {
487
- expect(visitorSpy).to.have.been.calledWithMatch(...args);
488
- });
489
- });
490
-
491
-
492
- it('halts when callback returns `false`', function () {
493
- traverse({ values: ['one', 'two'] }, (path, key, value, obj) => {
494
- visitorSpy();
495
- return false;
496
- });
497
-
498
- expect(visitorSpy).to.have.callCount(1);
499
- });
500
- });
501
- });
@@ -1,60 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const proxyquire = require('proxyquire');
5
- const mocks = require('@contrast/test/mocks');
6
-
7
- const moduleMock = (moduleName, mock) => (deps) => {
8
- deps.assess.dataflow.sources[moduleName] = mock[moduleName];
9
- };
10
-
11
- describe('assess dataflow sources', function () {
12
- let core, sourcesMock, sourcesModule, modulesWithInstall;
13
-
14
- beforeEach(function () {
15
- core = mocks.core();
16
- core.assess = mocks.assess();
17
- core.logger = mocks.logger();
18
- sourcesMock = core.assess.dataflow.sources;
19
- sourcesModule = proxyquire('.', {
20
- './install/http': moduleMock('httpSourcesInstr', sourcesMock),
21
- './install/express': moduleMock('expressInstrumentation', sourcesMock),
22
- './install/fastify': moduleMock('fastifyInstrumentation', sourcesMock),
23
- './install/hapi': moduleMock('hapiInstrumentation', sourcesMock),
24
- './install/koa': moduleMock('koaInstrumentation', sourcesMock),
25
- './install/restify': moduleMock('restifyInstrumentation', sourcesMock),
26
- './install/body-parser1': moduleMock('bodyParser1Instrumentation', sourcesMock),
27
- './install/cookie-parser1': moduleMock('cookieParser1Instrumentation', sourcesMock),
28
- './install/busboy': moduleMock('busboyInstrumentation', sourcesMock),
29
- './install/multer1': moduleMock('multer1Instrumentation', sourcesMock),
30
- './install/formidable1': moduleMock('formidable1Instrumentation', sourcesMock),
31
- './install/graphql-http': moduleMock('graphqlHttpInstrumentation', sourcesMock),
32
- './install/qs6': moduleMock('qs6Instrumentation', sourcesMock),
33
- './install/querystring': moduleMock('querystringInstrumentation', sourcesMock),
34
- });
35
- modulesWithInstall = [
36
- 'httpSourcesInstr',
37
- 'expressInstrumentation',
38
- 'fastifyInstrumentation',
39
- 'hapiInstrumentation',
40
- 'koaInstrumentation',
41
- 'restifyInstrumentation',
42
- 'bodyParser1Instrumentation',
43
- 'busboyInstrumentation',
44
- 'multer1Instrumentation',
45
- 'cookieParser1Instrumentation',
46
- 'formidable1Instrumentation',
47
- 'graphqlHttpInstrumentation',
48
- 'qs6Instrumentation',
49
- 'querystringInstrumentation',
50
- ];
51
- });
52
-
53
- it('installs the components', function () {
54
- sourcesModule(core).install();
55
- modulesWithInstall.forEach((module) => {
56
- expect(sourcesMock[module].install).to.have.been.calledOnce;
57
- });
58
- });
59
- });
60
-