@contrast/assess 1.46.1 → 1.46.3

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,218 +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 util = require('util');
7
-
8
- describe('assess session-configuration http', function () {
9
- let core,
10
- expressSession,
11
- simulateRequestScope;
12
-
13
- function ExpressSession(options) {
14
- return (req, res) => true;
15
- }
16
-
17
- beforeEach(function () {
18
- ({ core, simulateRequestScope } = initAssessFixture());
19
- core.depHooks.resolve.yields(ExpressSession);
20
-
21
- sinon.spy(core.assess.sessionConfiguration, 'handleHttpOnly');
22
- sinon.spy(core.assess.sessionConfiguration, 'handleSecure');
23
-
24
- expressSession = require('./express-session')(core).install();
25
- });
26
-
27
- it('skip instrumentation if options are set correctly', function () {
28
- const options = {
29
- secret: 'my-secret',
30
- cookie: { httpOnly: true, secure: true },
31
- };
32
-
33
- expressSession(options);
34
-
35
- expect(core.assess.sessionConfiguration.handleSecure).to.not.have.been.called;
36
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.not.have.been.called;
37
- });
38
-
39
- [
40
- {
41
- title: 'should instrument secure',
42
- sessionOptions: [
43
- undefined,
44
- {},
45
- { cookie: { httpOnly: undefined, secure: undefined } },
46
- { cookie: { httpOnly: true } },
47
- ],
48
- },
49
- ].forEach(({ title, sessionOptions }) => {
50
- sessionOptions.forEach((options) => {
51
- it(`${title} - ${util.inspect(options)}`, function () {
52
- simulateRequestScope(() => {
53
- const httpOnly = options?.cookie?.httpOnly;
54
- const secure = options?.cookie?.secure;
55
-
56
- const middleware = expressSession(options);
57
- const request = {};
58
- const response = {
59
- setHeader: () => true,
60
- };
61
-
62
- middleware(request, response);
63
-
64
- response.setHeader('Set-Cookie', 'hello');
65
-
66
- // for code coverage
67
- response.setHeader('custom-header', 'value');
68
-
69
- const sourceContext = core.scopes.sources.getStore()?.assess;
70
- expect(core.assess.sessionConfiguration.handleSecure).to.have.been.calledWith(
71
- sourceContext,
72
- 'hello',
73
- sinon.match({
74
- args: [
75
- {
76
- tracked: false,
77
- value: `{ cookie: { httpOnly: ${httpOnly}, secure: ${secure} } }`
78
- },
79
- ],
80
- context: `expressSession({ cookie: { httpOnly: ${httpOnly}, secure: ${secure} } })`,
81
- history: [],
82
- name: 'express.hookedSessionConstructor',
83
- moduleName: 'express-session',
84
- methodName: '',
85
- object: {
86
- tracked: false,
87
- value: 'Express.Response',
88
- },
89
- result: {
90
- tracked: false,
91
- value: undefined,
92
- },
93
- source: 'P0',
94
- stack: [],
95
- tags: {},
96
- framework: 'express',
97
- options: { cookie: { httpOnly, secure } },
98
- })
99
- );
100
- });
101
- });
102
- });
103
- });
104
-
105
- [
106
- {
107
- title: 'should not instrument secure',
108
- sessionOptions: [
109
- { cookie: { secure: true } },
110
- ],
111
- },
112
- ].forEach(({ title, sessionOptions }) => {
113
- sessionOptions.forEach((options) => {
114
- it(`${title} - ${util.inspect(options)}`, function () {
115
- simulateRequestScope(() => {
116
- const middleware = expressSession(options);
117
- const request = {};
118
- const response = {
119
- setHeader: () => true,
120
- };
121
-
122
- middleware(request, response);
123
-
124
- response.setHeader('Set-Cookie', 'hello');
125
-
126
- expect(core.assess.sessionConfiguration.handleSecure).to.not.have.been.called;
127
- });
128
- });
129
- });
130
- });
131
-
132
- [
133
- {
134
- title: 'should not instrument httpOnly',
135
- sessionOptions: [
136
- undefined,
137
- {},
138
- { cookie: {} },
139
- { cookie: { httpOnly: true } },
140
- ],
141
- },
142
- ].forEach(({ title, sessionOptions }) => {
143
- sessionOptions.forEach((options) => {
144
- it(`${title} - ${util.inspect(options)}`, function () {
145
- simulateRequestScope(() => {
146
- const middleware = expressSession(options);
147
- const request = {};
148
- const response = {
149
- setHeader: () => true,
150
- };
151
-
152
- middleware(request, response);
153
-
154
- response.setHeader('Set-Cookie', 'hello');
155
-
156
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.not.have.been.called;
157
- });
158
- });
159
- });
160
- });
161
-
162
- [
163
- {
164
- title: 'should instrument httpOnly',
165
- sessionOptions: [
166
- { cookie: { httpOnly: false, secure: undefined } },
167
- ],
168
- },
169
- ].forEach(({ title, sessionOptions }) => {
170
- sessionOptions.forEach((options) => {
171
- it(`${title} - ${util.inspect(options)}`, function () {
172
- simulateRequestScope(() => {
173
- const middleware = expressSession(options);
174
- const request = {};
175
- const response = {
176
- setHeader: () => true,
177
- };
178
-
179
- middleware(request, response);
180
-
181
- response.setHeader('Set-Cookie', 'hello');
182
-
183
- const sourceContext = core.scopes.sources.getStore()?.assess;
184
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.have.been.calledWith(
185
- sourceContext,
186
- 'hello',
187
- sinon.match({
188
- args: [
189
- {
190
- tracked: false,
191
- value: util.inspect(options),
192
- },
193
- ],
194
- context: `expressSession(${util.inspect(options)})`,
195
- history: [],
196
- name: 'express.hookedSessionConstructor',
197
- moduleName: 'express-session',
198
- methodName: '',
199
- object: {
200
- tracked: false,
201
- value: 'Express.Response',
202
- },
203
- result: {
204
- tracked: false,
205
- value: undefined,
206
- },
207
- source: 'P0',
208
- stack: [],
209
- tags: {},
210
- framework: 'express',
211
- options,
212
- })
213
- );
214
- });
215
- });
216
- });
217
- });
218
- });
@@ -1,63 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { SessionConfigurationRule } = require('@contrast/common');
6
- const { initAssessFixture } = require('@contrast/test/fixtures');
7
-
8
- const { HTTPONLY, SECURE_FLAG_MISSING } = SessionConfigurationRule;
9
-
10
- describe('assess session-configuration @fastify/cookie', function () {
11
- let core,
12
- simulateRequestScope,
13
- serverMock,
14
- mockFastifyCookie,
15
- mockExport,
16
- reply;
17
-
18
- beforeEach(function () {
19
- ({ core, simulateRequestScope } = initAssessFixture());
20
-
21
- mockExport = function fastifyCookieMock(server, options) { };
22
- mockExport.default = mockExport;
23
- mockExport.fastifyCookie = mockExport;
24
- reply = { header: sinon.stub() };
25
- serverMock = {
26
- addHook: sinon.stub().yields({}, reply),
27
- };
28
-
29
- core.depHooks.resolve.yields(mockExport);
30
-
31
- sinon.stub(core.assess.sessionConfiguration, 'reportFindings');
32
- core.assess.sessionConfiguration.fastifyCookie.install();
33
-
34
- mockFastifyCookie = mockExport.fastifyCookie;
35
- });
36
-
37
- it('reports httponly and secure-flag-missing when both options are unset', function () {
38
- mockFastifyCookie(serverMock, {});
39
-
40
- simulateRequestScope(() => {
41
- reply.header('Set-Cookie', 'bar');
42
- });
43
-
44
- expect(core.assess.sessionConfiguration.reportFindings).to.have.been.calledWithMatch({
45
- ruleId: HTTPONLY,
46
- sinkEvent: sinon.match({
47
- context: 'fastifyCookie({ parseOptions: { httpOnly: undefined, secure: undefined } })',
48
- }),
49
- });
50
- expect(core.assess.sessionConfiguration.reportFindings).to.have.been.calledWithMatch({
51
- ruleId: SECURE_FLAG_MISSING,
52
- sinkEvent: sinon.match({
53
- context: 'fastifyCookie({ parseOptions: { httpOnly: undefined, secure: undefined } })',
54
- }),
55
- });
56
- });
57
-
58
- it('will not report if instrumentation runs outside of request scope', function () {
59
- mockFastifyCookie(serverMock, {});
60
- reply.header('Set-Cookie', 'bar');
61
- expect(core.assess.sessionConfiguration.reportFindings).not.to.have.been.called;
62
- });
63
- });
@@ -1,269 +0,0 @@
1
- 'use strict';
2
-
3
- const util = require('util');
4
- const sinon = require('sinon');
5
- const { expect } = require('chai');
6
- const { initAssessFixture } = require('@contrast/test/fixtures');
7
-
8
- describe('assess session-configuration hapi', function () {
9
- const hapi = {
10
- server() {
11
- return { state() { }, ext: sinon.stub() };
12
- },
13
- Server() {
14
- return { state() { }, ext: sinon.stub() };
15
- }
16
- };
17
-
18
- let core, hapiServer, simulateRequestScope;
19
-
20
- beforeEach(function () {
21
- ({ core, simulateRequestScope } = initAssessFixture());
22
- core.depHooks.resolve
23
- .withArgs({ name: '@hapi/hapi', version: '>=18 <22' })
24
- .yields(hapi);
25
-
26
- sinon.spy(core.assess.sessionConfiguration, 'handleHttpOnly');
27
- sinon.spy(core.assess.sessionConfiguration, 'handleSecure');
28
-
29
- require('./hapi')(core).install();
30
- });
31
-
32
- ['server', 'Server'].forEach((server) => {
33
- describe(`${server}`, function () {
34
- it('skips instrumentation if options are set correctly', function () {
35
- simulateRequestScope(() => {
36
- const options = {
37
- isHttpOnly: true,
38
- isSecure: true
39
- };
40
-
41
- hapiServer = hapi[server]();
42
- hapiServer.state('data', options);
43
-
44
- expect(core.assess.sessionConfiguration.handleSecure).to.not.have.been.called;
45
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.not.have.been.called;
46
- });
47
- });
48
-
49
- it('does not call handlers when set-cookie is missing in headers', function () {
50
- simulateRequestScope(() => {
51
-
52
- const options = {
53
- isHttpOnly: false,
54
- isSecure: false
55
- };
56
-
57
- hapiServer = hapi[server]();
58
- hapiServer.ext.withArgs('onPostResponse', sinon.match.func).callsFake((string, method) => {
59
- method({
60
- response: {
61
- headers: {}
62
- }
63
- });
64
- });
65
- hapiServer.state('data', options);
66
-
67
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.not.have.been.called;
68
- expect(core.assess.sessionConfiguration.handleSecure).to.not.have.been.called;
69
- });
70
- });
71
-
72
- [
73
- {
74
- isSecure: false
75
- },
76
- {
77
- isSecure: false,
78
- isHttpOnly: true
79
- }
80
- ].forEach((options) => {
81
- it('handles isSecure flag set to false', function () {
82
- simulateRequestScope(() => {
83
-
84
- hapiServer = hapi[server]();
85
- hapiServer.ext.withArgs('onPostResponse', sinon.match.func).callsFake((string, method) => {
86
- method({
87
- response: {
88
- headers: {
89
- 'set-cookie': ['foo']
90
- }
91
- }
92
- });
93
- });
94
- hapiServer.state('data', options);
95
-
96
- const sourceContext = core.scopes.sources.getStore()?.assess;
97
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.not.have.been.called;
98
- expect(core.assess.sessionConfiguration.handleSecure).to.have.been.calledWith(
99
- sourceContext,
100
- 'set-cookie: foo',
101
- sinon.match({
102
- args: [
103
- {
104
- tracked: false,
105
- value: util.inspect(options),
106
- },
107
- ],
108
- context: `state(${util.inspect(['data', options])})`,
109
- history: [],
110
- name: `hapi.${server}.state`,
111
- moduleName: 'hapi',
112
- methodName: '',
113
- object: {
114
- tracked: false,
115
- value: `hapi.${server}`,
116
- },
117
- result: {
118
- tracked: false,
119
- value: undefined,
120
- },
121
- source: 'P1',
122
- framework: 'hapi',
123
- options,
124
- })
125
- );
126
- });
127
- });
128
- });
129
-
130
- [
131
- {
132
- isHttpOnly: false
133
- },
134
- {
135
- isSecure: true,
136
- isHttpOnly: false
137
- }
138
- ].forEach((options) => {
139
- it('handles isHttpOnly flag set to false', function () {
140
- simulateRequestScope(() => {
141
-
142
- hapiServer = hapi[server]();
143
- hapiServer.ext.withArgs('onPostResponse', sinon.match.func).callsFake((string, method) => {
144
- method({
145
- response: {
146
- headers: {
147
- 'set-cookie': ['foo']
148
- }
149
- }
150
- });
151
- });
152
- hapiServer.state('data', options);
153
-
154
- const sourceContext = core.scopes.sources.getStore()?.assess;
155
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.have.been.calledWith(
156
- sourceContext,
157
- 'set-cookie: foo',
158
- sinon.match({
159
- args: [
160
- {
161
- tracked: false,
162
- value: util.inspect(options),
163
- },
164
- ],
165
- context: `state(${util.inspect(['data', options])})`,
166
- history: [],
167
- name: `hapi.${server}.state`,
168
- moduleName: 'hapi',
169
- methodName: '',
170
- object: {
171
- tracked: false,
172
- value: `hapi.${server}`,
173
- },
174
- result: {
175
- tracked: false,
176
- value: undefined,
177
- },
178
- source: 'P1',
179
- framework: 'hapi',
180
- options,
181
- })
182
- );
183
- });
184
- });
185
- });
186
-
187
- it('handles isHttpOnly flag and isSecure set to false', function () {
188
- simulateRequestScope(() => {
189
-
190
- const options = {
191
- isSecure: false,
192
- isHttpOnly: false
193
- };
194
-
195
- hapiServer = hapi[server]();
196
- hapiServer.ext.withArgs('onPostResponse', sinon.match.func).callsFake((string, method) => {
197
- method({
198
- response: {
199
- headers: {
200
- 'set-cookie': ['foo']
201
- }
202
- }
203
- });
204
- });
205
- hapiServer.state('data', options);
206
-
207
- const sourceContext = core.scopes.sources.getStore()?.assess;
208
- expect(core.assess.sessionConfiguration.handleHttpOnly).to.have.been.calledWith(
209
- sourceContext,
210
- 'set-cookie: foo',
211
- sinon.match({
212
- args: [
213
- {
214
- tracked: false,
215
- value: util.inspect(options),
216
- },
217
- ],
218
- context: `state(${util.inspect(['data', options])})`,
219
- history: [],
220
- name: `hapi.${server}.state`,
221
- moduleName: 'hapi',
222
- methodName: '',
223
- object: {
224
- tracked: false,
225
- value: `hapi.${server}`,
226
- },
227
- result: {
228
- tracked: false,
229
- value: undefined,
230
- },
231
- source: 'P1',
232
- framework: 'hapi',
233
- options,
234
- })
235
- );
236
-
237
- expect(core.assess.sessionConfiguration.handleSecure).to.have.been.calledWith(
238
- sourceContext,
239
- 'set-cookie: foo',
240
- sinon.match({
241
- args: [
242
- {
243
- tracked: false,
244
- value: util.inspect(options),
245
- },
246
- ],
247
- context: `state(${util.inspect(['data', options])})`,
248
- history: [],
249
- name: `hapi.${server}.state`,
250
- moduleName: 'hapi',
251
- methodName: '',
252
- object: {
253
- tracked: false,
254
- value: `hapi.${server}`,
255
- },
256
- result: {
257
- tracked: false,
258
- value: undefined,
259
- },
260
- source: 'P1',
261
- framework: 'hapi',
262
- options,
263
- })
264
- );
265
- });
266
- });
267
- });
268
- });
269
- });
@@ -1,92 +0,0 @@
1
- 'use strict';
2
-
3
- const sinon = require('sinon');
4
- const { expect } = require('chai');
5
- const { SessionConfigurationRule } = require('@contrast/common');
6
- const { initAssessFixture } = require('@contrast/test/fixtures');
7
-
8
- const { HTTPONLY, SECURE_FLAG_MISSING } = SessionConfigurationRule;
9
-
10
- describe('assess sessionConfiguration Koa', function () {
11
- let core,
12
- simulateRequestScope,
13
- koaMock,
14
- ctxMock,
15
- patchedMiddleware;
16
-
17
- beforeEach(function () {
18
- ({ core, simulateRequestScope } = initAssessFixture());
19
-
20
- koaMock = {
21
- prototype: {
22
- middleware: [],
23
- use: (fn) => {
24
- koaMock.prototype.middleware.push(fn);
25
- },
26
- }
27
- };
28
-
29
- ctxMock = function() {};
30
- ctxMock.cookies = { set: sinon.stub() };
31
-
32
- core.depHooks.resolve
33
- .withArgs({ name: 'koa', version: '>=2.3.0 <3' })
34
- .yields(koaMock);
35
-
36
- sinon.stub(core.assess.sessionConfiguration, 'reportFindings');
37
- core.assess.sessionConfiguration.koa.install();
38
-
39
- koaMock.prototype.use(ctxMock);
40
- [patchedMiddleware] = koaMock.prototype.middleware;
41
- patchedMiddleware(ctxMock);
42
- });
43
-
44
- it('will not report if instrumentation runs outside of request scope', function() {
45
- patchedMiddleware(ctxMock);
46
- ctxMock.cookies.set('cookie', 'foo', { secure: false });
47
- expect(core.assess.sessionConfiguration.reportFindings).not.to.have.been.called;
48
- });
49
-
50
- it('will not report when both options are set to true', function() {
51
- simulateRequestScope(() => {
52
- ctxMock.cookies.set('cookie', 'foo', { httpOnly: true, secure: true });
53
- expect(core.assess.sessionConfiguration.reportFindings).not.to.have.been.called;
54
- });
55
- });
56
-
57
- it('reports httponly when option is set to false', function() {
58
- simulateRequestScope(() => {
59
- ctxMock.cookies.set('cookie', 'foo', { httpOnly: false });
60
- expect(core.assess.sessionConfiguration.reportFindings).to.have.been.calledWithMatch({
61
- ruleId: HTTPONLY,
62
- sinkEvent: sinon.match({
63
- context: 'ctx.cookies.set({ httpOnly: false })',
64
- }),
65
- });
66
- });
67
- });
68
-
69
- it('reports secure-flag-missing when option is set to false', function() {
70
- simulateRequestScope(() => {
71
- ctxMock.cookies.set('cookie', 'foo', { secure: false });
72
- expect(core.assess.sessionConfiguration.reportFindings).to.have.been.calledWithMatch({
73
- ruleId: SECURE_FLAG_MISSING,
74
- sinkEvent: sinon.match({
75
- context: 'ctx.cookies.set({ secure: false })',
76
- }),
77
- });
78
- });
79
- });
80
-
81
- it('reports httponly and secure-flag-missing when options are not set', function() {
82
- simulateRequestScope(() => {
83
- ctxMock.cookies.set('cookie', 'foo');
84
- expect(core.assess.sessionConfiguration.reportFindings).to.have.been.calledWithMatch({
85
- ruleId: HTTPONLY
86
- });
87
- expect(core.assess.sessionConfiguration.reportFindings).to.have.been.calledWithMatch({
88
- ruleId: SECURE_FLAG_MISSING
89
- });
90
- });
91
- });
92
- });