@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,244 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
- const { InputType } = require('@contrast/common');
7
-
8
- describe('assess dataflow sources body-parser v1', function () {
9
- let core, simulateRequestScope, req, res, next, bodyParser;
10
-
11
- beforeEach(function () {
12
- ({ core, simulateRequestScope } = initAssessFixture());
13
- req = {};
14
- res = {};
15
- next = sinon.stub();
16
-
17
- sinon.stub(core.assess.dataflow.sources, 'handle');
18
-
19
- const bodyParserMock = (body) => (req, res, next) => {
20
- req.body = body;
21
- next();
22
- };
23
- bodyParserMock.json = (body) => (req, res, next) => {
24
- req.body = body;
25
- next();
26
- };
27
- bodyParserMock.raw = (body) => (req, res, next) => {
28
- req.body = body;
29
- next();
30
- };
31
- bodyParserMock.text = (body) => (req, res, next) => {
32
- req.body = body;
33
- next();
34
- };
35
- bodyParserMock.urlencoded = (body) => (req, res, next) => {
36
- req.body = body;
37
- next();
38
- };
39
-
40
- require('./body-parser1')(core).install();
41
- bodyParser = core.depHooks.resolve.yield(bodyParserMock)[0];
42
- });
43
-
44
- // tests are not properly patching the default function
45
- describe('bodyParser', function () {
46
- it('handles a json request body as expected', function () {
47
- const body = { foo: 'bar' };
48
- const middleware = bodyParser(body);
49
- req.headers = { 'content-type': 'application/json' };
50
-
51
- simulateRequestScope(() => {
52
- middleware(req, res, next);
53
-
54
- expect(core.assess.dataflow.sources.handle).to.have.been.calledWithMatch({
55
- context: 'req.body',
56
- name: 'body-parser.bodyParser',
57
- inputType: InputType.JSON_VALUE,
58
- stacktraceOpts: {
59
- constructorOpt: sinon.match.func,
60
- },
61
- data: body,
62
- sourceContext: core.scopes.sources.getStore().assess
63
- });
64
- });
65
- });
66
-
67
- it('handles a urlencoded request body as expected', function () {
68
- const body = { foo: 'bar' };
69
- const middleware = bodyParser(body);
70
- req.headers = { 'content-type': 'application/x-www-form-urlencoded' };
71
-
72
- simulateRequestScope(() => {
73
- middleware(req, res, next);
74
-
75
- expect(core.assess.dataflow.sources.handle).to.have.been.calledWithMatch({
76
- context: 'req.body',
77
- name: 'body-parser.bodyParser',
78
- inputType: InputType.PARAMETER_VALUE,
79
- stacktraceOpts: {
80
- constructorOpt: sinon.match.func,
81
- },
82
- data: body,
83
- sourceContext: core.scopes.sources.getStore().assess
84
- });
85
- });
86
- });
87
-
88
- it('handles an unknown format request body as expected', function () {
89
- const body = 'text';
90
- const middleware = bodyParser(body);
91
-
92
- simulateRequestScope(() => {
93
- middleware(req, res, next);
94
-
95
- expect(core.assess.dataflow.sources.handle).to.have.been.calledWithMatch({
96
- context: 'req',
97
- name: 'body-parser.bodyParser',
98
- inputType: InputType.BODY,
99
- stacktraceOpts: {
100
- constructorOpt: sinon.match.func,
101
- },
102
- data: { body },
103
- sourceContext: core.scopes.sources.getStore().assess
104
- });
105
- });
106
- });
107
-
108
- it('does not handle the request when there is no assess policy in request context', function () {
109
- const middleware = bodyParser('text');
110
-
111
- simulateRequestScope(() => {
112
- middleware(req, res, next);
113
-
114
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
115
- expect(core.logger.trace.callCount).greaterThan(0);
116
- expect(core.logger.trace.lastCall.args[0]).includes('Assess intentionally disabled');
117
- }, { assess: { policy: null } });
118
- });
119
-
120
- it('does not handle the request when already tracked', function () {
121
- const middleware = bodyParser('text');
122
-
123
- simulateRequestScope(() => {
124
- // run twice
125
- middleware(req, res, next);
126
- expect(core.assess.dataflow.sources.handle).to.have.been.calledOnce;
127
- middleware(req, res, next);
128
-
129
- expect(core.assess.dataflow.sources.handle).to.have.been.calledOnce;
130
- expect(core.logger.trace).to.have.been.calledWith(
131
- { funcKey: 'assess-dataflow-source:body-parser.bodyParser' },
132
- 'values already tracked',
133
- );
134
- });
135
- });
136
-
137
- it('logs errors in the handle method', function () {
138
- const middleware = bodyParser('text');
139
- const err = new Error('yikes!');
140
- core.assess.dataflow.sources.handle.throws(err);
141
- simulateRequestScope(() => {
142
- middleware(req, res, next);
143
-
144
- expect(core.logger.error).to.have.been.calledWith(
145
- { err, funcKey: 'assess-dataflow-source:body-parser.bodyParser' },
146
- 'unable to handle source',
147
- );
148
- });
149
- });
150
- });
151
-
152
- [
153
- {
154
- method: 'json',
155
- body: { json: 'body' },
156
- inputType: InputType.JSON_VALUE,
157
- context: 'req.body',
158
- data: { json: 'body' },
159
- },
160
- {
161
- method: 'raw',
162
- body: Buffer.from('raw'),
163
- inputType: InputType.BODY,
164
- context: 'req',
165
- data: { body: Buffer.from('raw') }
166
- },
167
- {
168
- method: 'text',
169
- body: 'text',
170
- inputType: InputType.BODY,
171
- context: 'req',
172
- data: { body: 'text' }
173
- },
174
- {
175
- method: 'urlencoded',
176
- body: { urlencoded: 'yes' },
177
- inputType: InputType.PARAMETER_VALUE,
178
- context: 'req.body',
179
- data: { urlencoded: 'yes' }
180
- },
181
- ].forEach(({ method, body, inputType, context, data }) => {
182
- describe(`bodyParser.${method}`, function () {
183
- let middleware;
184
-
185
- beforeEach(function () {
186
- middleware = bodyParser[method](body);
187
- });
188
-
189
- it('handles the request body as expected', function () {
190
- simulateRequestScope(() => {
191
- middleware(req, res, next);
192
-
193
- expect(core.assess.dataflow.sources.handle).to.have.been.calledWithMatch({
194
- context,
195
- name: `body-parser.${method}.${method}Parser`,
196
- inputType,
197
- stacktraceOpts: {
198
- constructorOpt: sinon.match.func,
199
- },
200
- data,
201
- sourceContext: core.scopes.sources.getStore().assess
202
- });
203
- });
204
- });
205
-
206
- it('does not handle the request when there is in context', function () {
207
- simulateRequestScope(() => {
208
- middleware(req, res, next);
209
-
210
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
211
- expect(core.logger.trace.callCount).greaterThan(0);
212
- expect(core.logger.trace.lastCall.args[0]).includes('Assess intentionally disabled');
213
- }, { assess: { policy: null } });
214
- });
215
-
216
- it('does not handle the request when already tracked', function () {
217
- simulateRequestScope(() => {
218
- core.scopes.sources.getStore().assess.parsedBody = true;
219
- middleware(req, res, next);
220
-
221
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
222
- expect(core.logger.trace).to.have.been.calledWith(
223
- { funcKey: `assess-dataflow-source:body-parser.${method}.${method}Parser` },
224
- 'values already tracked',
225
- );
226
- });
227
- });
228
-
229
- it('logs errors in the handle method', function () {
230
- const err = new Error('yikes!');
231
- core.assess.dataflow.sources.handle.throws(err);
232
-
233
- simulateRequestScope(() => {
234
- middleware(req, res, next);
235
-
236
- expect(core.logger.error).to.have.been.calledWith(
237
- { err, funcKey: `assess-dataflow-source:body-parser.${method}.${method}Parser` },
238
- 'unable to handle source',
239
- );
240
- });
241
- });
242
- });
243
- });
244
- });
@@ -1,152 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
- const { InputType } = require('@contrast/common');
7
- const busboyInstr = require('./busboy');
8
-
9
- describe('assess dataflow sources busboy', function () {
10
- let core, simulateRequestScope, mockBusboy0, mockBusboy1, sources, emitMethodVersions;
11
-
12
- beforeEach(function () {
13
- ({ core, simulateRequestScope } = initAssessFixture());
14
-
15
- mockBusboy0 = function () { };
16
- mockBusboy0.prototype.emit = function () { };
17
-
18
- mockBusboy1 = function () {
19
- return {
20
- emit() { }
21
- };
22
- };
23
- sinon.spy(mockBusboy0.prototype, 'emit');
24
- sinon.spy(core.patcher, 'patch');
25
-
26
- sources = core.assess.dataflow.sources;
27
- sinon.spy(sources, 'handle');
28
-
29
- busboyInstr(core).install();
30
- core.depHooks.resolve.withArgs({ name: 'busboy', version: '<1' }).yield(mockBusboy0);
31
- core.depHooks.resolve.withArgs({ name: 'busboy', version: '1' }).yield(mockBusboy1);
32
- const patchedBusboy1 = core.patcher.patch.getCall(1).returnValue;
33
-
34
- emitMethodVersions = {
35
- 'v0': mockBusboy0.prototype.emit,
36
- 'v1': patchedBusboy1().emit
37
- };
38
- });
39
-
40
- it('calls patcher on the `.emit` method', function () {
41
- expect(core.patcher.patch).to.have.been.calledWithMatch(mockBusboy0.prototype, 'emit', {
42
- name: 'busboy.prototype.emit',
43
- patchType: 'assess-dataflow-source',
44
- pre: sinon.match.func
45
- });
46
-
47
- expect(core.patcher.patch).to.have.been.calledWithMatch(mockBusboy1, {
48
- name: 'busboy',
49
- patchType: 'assess-dataflow-source',
50
- post: sinon.match.func
51
- });
52
- });
53
-
54
- [
55
- { version: 'v0', finalEvent: 'finish' },
56
- { version: 'v1', finalEvent: 'close' }
57
- ].forEach(({ version, finalEvent }) => {
58
- describe(version, function () {
59
- it('calls `.handle` when there are fields of data to be tracked and it is in right context', function () {
60
- let sourceContext;
61
-
62
- simulateRequestScope(() => {
63
- emitMethodVersions[version]('field', 'field1', 'value1');
64
- emitMethodVersions[version]('field', 'field2', 'value2');
65
- emitMethodVersions[version](finalEvent);
66
-
67
- sourceContext = core.scopes.sources.getStore()?.assess;
68
- });
69
-
70
- expect(sources.handle).to.have.been.calledTwice;
71
- expect(sources.handle).to.have.been.calledWithMatch({
72
- context: 'req.body',
73
- name: 'busboy',
74
- stacktraceOpts: {
75
- constructorOpt: sinon.match.func,
76
- prependFrames: [sinon.match.func],
77
- },
78
- inputType: InputType.MULTIPART_VALUE,
79
- data: { field1: 'value1' },
80
- sourceContext
81
- });
82
- expect(sources.handle).to.have.been.calledWithMatch({
83
- context: 'req.body',
84
- name: 'busboy',
85
- stacktraceOpts: {
86
- constructorOpt: sinon.match.func,
87
- prependFrames: [sinon.match.func],
88
- },
89
- inputType: InputType.MULTIPART_VALUE,
90
- data: { field2: 'value2' },
91
- sourceContext
92
- });
93
- });
94
-
95
- it('logs an error when `.handle` throws one', function () {
96
- const err = new Error('test');
97
-
98
- core.assess.dataflow.sources.handle = () => {
99
- throw err;
100
- };
101
-
102
- simulateRequestScope(() => {
103
- emitMethodVersions[version]('field', 'field1', 'value1');
104
- emitMethodVersions[version](finalEvent);
105
- });
106
-
107
- expect(core.logger.error).to.have.been.calledOnceWith(
108
- { err, inputType: InputType.MULTIPART_VALUE, funcKey: sinon.match.string },
109
- 'unable to handle source'
110
- );
111
- });
112
-
113
- it('does not call `.handle` when there is no assess policy in request context', function () {
114
- simulateRequestScope(() => {
115
- emitMethodVersions[version]('field', 'field1', 'value1');
116
- emitMethodVersions[version]('field', 'field2', 'value2');
117
- emitMethodVersions[version](finalEvent);
118
- }, { assess: { policy: null } });
119
-
120
- expect(sources.handle).not.to.have.been.called;
121
- });
122
-
123
- it('does not call `.handle` when the values are already tracked', function () {
124
- simulateRequestScope(() => {
125
- const sourceContext = core.scopes.sources.getStore()?.assess;
126
- sourceContext.parsedBody = true;
127
-
128
- emitMethodVersions[version]('field', 'field1', 'value1');
129
- emitMethodVersions[version]('field', 'field2', 'value2');
130
- emitMethodVersions[version](finalEvent);
131
- });
132
-
133
- expect(sources.handle).not.to.have.been.called;
134
- expect(core.logger.trace).to.have.been.calledWith(
135
- { inputType: InputType.MULTIPART_VALUE, funcKey: sinon.match.string },
136
- 'values already tracked');
137
- });
138
-
139
- it('does not call `.handle` when `.emit` call does not contain field name or data', function () {
140
- simulateRequestScope(() => {
141
- emitMethodVersions[version]('field', null, 'value1');
142
- emitMethodVersions[version]('field', 'field2', null);
143
- emitMethodVersions[version](finalEvent);
144
- }, {});
145
-
146
- expect(sources.handle).not.to.have.been.called;
147
- expect(core.logger.debug).not.to.have.been.called;
148
- });
149
- });
150
- });
151
- });
152
-
@@ -1,141 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
- const { InputType } = require('@contrast/common');
7
-
8
- describe('assess dataflow sources cookie-parser v1', function () {
9
- let core, simulateRequestScope, req, res, next, cookieParser;
10
-
11
- beforeEach(function () {
12
- ({ core, simulateRequestScope } = initAssessFixture());
13
- req = {};
14
- res = {};
15
- next = sinon.stub();
16
-
17
- sinon.stub(core.assess.dataflow.sources, 'handle');
18
-
19
- require('./cookie-parser1')(core).install();
20
- cookieParser = core.depHooks.resolve.yield(
21
- function cookieParser(props = {}) {
22
- return function cookieParser(req, res, next) {
23
- Object.assign(req, props);
24
- next();
25
- };
26
- }
27
- )[0];
28
- });
29
-
30
- it('handles cookies as expected', function () {
31
- const cookies = { foo: 'bar' };
32
- const middleware = cookieParser({ cookies });
33
-
34
- simulateRequestScope(() => {
35
- middleware(req, res, next);
36
-
37
- expect(core.assess.dataflow.sources.handle).to.have.been.calledWith({
38
- context: 'req.cookies',
39
- name: 'cookie-parser.cookieParser',
40
- inputType: InputType.COOKIE_VALUE,
41
- stacktraceOpts: {
42
- constructorOpt: sinon.match.func,
43
- },
44
- data: cookies,
45
- sourceContext: core.scopes.sources.getStore().assess
46
- });
47
- });
48
- });
49
-
50
- it('handles signed cookies as expected', function () {
51
- const cookies = { foo: 'bar' };
52
- const middleware = cookieParser({ signedCookies: cookies });
53
-
54
- simulateRequestScope(() => {
55
- middleware(req, res, next);
56
-
57
- expect(core.assess.dataflow.sources.handle).to.have.been.calledWith({
58
- context: 'req.signedCookies',
59
- name: 'cookie-parser.cookieParser',
60
- inputType: InputType.COOKIE_VALUE,
61
- stacktraceOpts: {
62
- constructorOpt: sinon.match.func,
63
- },
64
- data: cookies,
65
- sourceContext: core.scopes.sources.getStore().assess
66
- });
67
- });
68
- });
69
-
70
- it('does not handle when there is no assess policy in request context', function () {
71
- const middleware = cookieParser();
72
-
73
- simulateRequestScope(() => {
74
- middleware(req, res, next);
75
-
76
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
77
- expect(core.logger.trace.callCount).greaterThan(0);
78
- expect(core.logger.trace.lastCall.args[0]).includes('Assess intentionally disabled');
79
- }, { assess: { policy: null } });
80
- });
81
-
82
- it('does not handle the request when cookies already tracked', function () {
83
- const middleware = cookieParser();
84
-
85
- simulateRequestScope(() => {
86
- core.scopes.sources.getStore().assess.parsedCookies = true;
87
- middleware(req, res, next);
88
-
89
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
90
- expect(core.logger.trace).to.have.been.calledWith(
91
- { funcKey: 'assess-dataflow-source:cookie-parser.cookieParser' },
92
- 'cookies already tracked',
93
- );
94
- });
95
- });
96
-
97
- it('does not handle the request when signed cookies already tracked', function () {
98
- const middleware = cookieParser();
99
-
100
- simulateRequestScope(() => {
101
- core.scopes.sources.getStore().assess.parsedSignedCookies = true;
102
- middleware(req, res, next);
103
-
104
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
105
- expect(core.logger.trace).to.have.been.calledWith(
106
- { funcKey: 'assess-dataflow-source:cookie-parser.cookieParser' },
107
- 'signedCookies already tracked',
108
- );
109
- });
110
- });
111
-
112
- it('logs errors when handling cookies', function () {
113
- const middleware = cookieParser({ cookies: {} });
114
- const err = new Error('yikes!');
115
- core.assess.dataflow.sources.handle.throws(err);
116
-
117
- simulateRequestScope(() => {
118
- middleware(req, res, next);
119
-
120
- expect(core.logger.error).to.have.been.calledWith(
121
- { err, funcKey: 'assess-dataflow-source:cookie-parser.cookieParser' },
122
- 'unable to handle source',
123
- );
124
- });
125
- });
126
-
127
- it('logs errors when handling signed cookies', function () {
128
- const middleware = cookieParser({ signedCookies: {} });
129
- const err = new Error('yikes!');
130
- core.assess.dataflow.sources.handle.throws(err);
131
-
132
- simulateRequestScope(() => {
133
- middleware(req, res, next);
134
-
135
- expect(core.logger.error).to.have.been.calledWith(
136
- { err, funcKey: 'assess-dataflow-source:cookie-parser.cookieParser' },
137
- 'unable to handle source',
138
- );
139
- });
140
- });
141
- });
@@ -1,110 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
- const { InputType } = require('@contrast/common');
7
-
8
- describe('assess dataflow sources express params', function () {
9
- let core, simulateRequestScope, Layer, layer;
10
-
11
- [
12
- { name: 'express', version: '>=4 <5', file: 'lib/router/layer.js' },
13
- { name: 'router', version: '>=2 <3', file: 'lib/layer.js' }
14
- ].forEach((args) => {
15
- describe(`Express${args.name === 'express' ? '4' : '5'}`, function() {
16
- beforeEach(function () {
17
- ({ core, simulateRequestScope } = initAssessFixture());
18
-
19
- sinon.stub(core.assess.dataflow.sources, 'handle');
20
-
21
- const LayerMock = sinon.stub();
22
- LayerMock.prototype.match = sinon.stub().returns(true);
23
-
24
- require('./params')(core).install();
25
- [Layer] = core.depHooks.resolve.withArgs(args).yield(LayerMock);
26
- layer = { keys: ['foo'], params: { foo: 'bar' } };
27
- });
28
-
29
- it('calls `.handle` when `match` adds params (and keys) to the Layer instance', function () {
30
- simulateRequestScope(() => {
31
- Reflect.apply(Layer.prototype.match, layer, ['/bar']);
32
-
33
- expect(core.assess.dataflow.sources.handle).to.have.been.calledWith({
34
- context: 'req.params',
35
- name: 'Layer.prototype.match',
36
- inputType: InputType.PARAMETER_VALUE,
37
- stacktraceOpts: {
38
- constructorOpt: sinon.match.func,
39
- prependFrames: sinon.match.array,
40
- },
41
- data: layer.params,
42
- sourceContext: core.scopes.sources.getStore().assess
43
- });
44
- });
45
- });
46
-
47
- it('does not call `.handle` when `match` returns false', function () {
48
- Layer.prototype.match.returns(false);
49
-
50
- simulateRequestScope(() => {
51
- Reflect.apply(Layer.prototype.match, layer, ['/bar']);
52
-
53
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
54
- });
55
- });
56
-
57
- it('does not call `.handle` when the layer is missing the expected properties', function () {
58
- simulateRequestScope(() => {
59
- Reflect.apply(Layer.prototype.match, {}, ['/bar']);
60
-
61
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
62
- });
63
- });
64
-
65
- it('does not call `.handle` when `match` adds no params or keys', function () {
66
- simulateRequestScope(() => {
67
- Reflect.apply(Layer.prototype.match, { keys: [], params: {} }, ['/bar']);
68
-
69
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
70
- });
71
- });
72
-
73
- it('does not handle when there is no assess policy in request context', function () {
74
- simulateRequestScope(() => {
75
- Reflect.apply(Layer.prototype.match, layer, ['/bar']);
76
-
77
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
78
- }, { assess: { policy: null } });
79
- });
80
-
81
- it('does not call `.handle` when the values are already tracked', function () {
82
- simulateRequestScope(() => {
83
- core.scopes.sources.getStore().assess.parsedParams = true;
84
-
85
- Reflect.apply(Layer.prototype.match, layer, ['/bar']);
86
-
87
- expect(core.assess.dataflow.sources.handle).not.to.have.been.called;
88
- expect(core.logger.trace).to.have.been.calledWith(
89
- { funcKey: 'assess-dataflow-source:Layer.prototype.match' },
90
- 'values already tracked'
91
- );
92
- });
93
- });
94
-
95
- it('handles a case with an error in the `.handle` method', function () {
96
- const err = new Error('test');
97
- core.assess.dataflow.sources.handle.throws(err);
98
-
99
- simulateRequestScope(() => {
100
- Reflect.apply(Layer.prototype.match, layer, ['/bar']);
101
-
102
- expect(core.logger.error).to.have.been.calledWith(
103
- { err, funcKey: 'assess-dataflow-source:Layer.prototype.match' },
104
- 'unable to handle source'
105
- );
106
- });
107
- });
108
- });
109
- });
110
- });