@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
package/lib/index.test.js DELETED
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const proxyquire = require('proxyquire');
6
- const mocks = require('@contrast/test/mocks');
7
-
8
- const moduleMock = (moduleName, mock) => (deps) => {
9
- deps.assess[moduleName] = mock[moduleName];
10
- };
11
-
12
- describe('assess', function () {
13
- let core, assessMock, assessModule, modulesWithInstall;
14
-
15
- beforeEach(function () {
16
- assessMock = mocks.assess();
17
- core = mocks.core();
18
- core.config = mocks.config();
19
- core.logger = mocks.logger();
20
- core.rewriter = mocks.rewriter();
21
- core.scopes = mocks.scopes();
22
- core.config.assess.enable = true;
23
- core.sources = {
24
- addHook: sinon.stub(),
25
- };
26
-
27
- assessModule = proxyquire('.', {
28
- './session-configuration': moduleMock('sessionConfiguration', assessMock),
29
- './dataflow': moduleMock('dataflow', assessMock),
30
- './response-scanning': moduleMock('responseScanning', assessMock),
31
- './crypto-analysis': moduleMock('cryptoAnalysis', assessMock),
32
- });
33
- modulesWithInstall = ['sessionConfiguration', 'dataflow', 'responseScanning', 'cryptoAnalysis'];
34
- });
35
-
36
- it('installs the components', function () {
37
- core.config.getEffectiveValue.withArgs('assess.enable').returns(true);
38
-
39
- assessModule(core).install();
40
- modulesWithInstall.forEach((module) => {
41
- expect(assessMock[module].install).to.have.been.calledOnce;
42
- });
43
- expect(core.rewriter.install).to.have.been.calledWith('assess');
44
- });
45
- });
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
- const mocks = require('@contrast/test/mocks');
7
-
8
- describe('assess makeSourceContext', function () {
9
- let core;
10
-
11
- beforeEach(function () {
12
- ({ core } = initAssessFixture());
13
- });
14
-
15
- it('will return `null` and log error when passed insufficient parameters', function() {
16
- const assessCtx = core.assess.makeSourceContext({});
17
- expect(assessCtx).to.be.null;
18
- expect(core.logger.error).to.have.been.calledWithMatch({
19
- err: sinon.match.has('message'),
20
- }, 'unable to construct assess store. assess will be disabled for request.');
21
- });
22
-
23
- it('construct the store correctly given req and res', function() {
24
- const mockSourceData = {
25
- store: {},
26
- incomingMessage: mocks.incomingMessage()
27
- };
28
- const assessCtx = core.assess.makeSourceContext(mockSourceData);
29
- expect(assessCtx).to.deep.include({
30
- propagationEventsCount: 0,
31
- sampleInfo: null,
32
- sourceEventsCount: 0,
33
- reqData: {
34
- contentType: 'text/html',
35
- headers: {
36
- 'content-type': 'text/html',
37
- referer: 'http://fake.url.foo',
38
- language: 'en',
39
- },
40
- httpVersion: '1.1',
41
- ip: '127.0.0.1',
42
- method: 'get',
43
- queries: '_id=123',
44
- uriPath: '/index',
45
- },
46
- responseData: {},
47
- });
48
- expect(assessCtx.policy.enabledRules).to.have.length.greaterThan(5);
49
- });
50
- });
@@ -1,419 +0,0 @@
1
- 'use strict';
2
-
3
- const { expect } = require('chai');
4
- const sinon = require('sinon');
5
- const { initAssessFixture } = require('@contrast/test/fixtures');
6
- const handlers = require('.');
7
-
8
- describe('assess response scanning handlers', function () {
9
- let core,
10
- simulateRequestScope,
11
- reportFindings,
12
- handleAutoCompleteMissing,
13
- handleCacheControlsMissing,
14
- handleClickJackingControlsMissing,
15
- handleParameterPollution,
16
- handleCspHeader,
17
- handleHstsHeaderMissing,
18
- handleXPoweredByHeader,
19
- handleXContentTypeHeaderMissing,
20
- handleXxsProtectionHeaderDisabled;
21
-
22
- beforeEach(function () {
23
- ({ core, simulateRequestScope } = initAssessFixture());
24
-
25
- sinon.stub(core.assess.responseScanning, 'reportFindings');
26
-
27
- ({
28
- handleAutoCompleteMissing,
29
- handleCacheControlsMissing,
30
- handleClickJackingControlsMissing,
31
- handleParameterPollution,
32
- handleCspHeader,
33
- handleHstsHeaderMissing,
34
- handleXPoweredByHeader,
35
- handleXContentTypeHeaderMissing,
36
- handleXxsProtectionHeaderDisabled,
37
- reportFindings,
38
- } = handlers(core));
39
- });
40
-
41
- describe('handleAutoCompleteMissing', function () {
42
- const responseHeaders = { 'content-type': 'text/html' };
43
-
44
- it('returns undefined if we are not checking html content', function () {
45
- simulateRequestScope(() => {
46
- handleAutoCompleteMissing(core.assess.getSourceContext(), {
47
- responseHeaders: { 'content-type': 'application/json' },
48
- responseBody: 'test'
49
- });
50
-
51
- expect(reportFindings).to.not.have.been.called;
52
- });
53
- });
54
-
55
- it('does not report anything if the auto-complete options is set to "off"', function () {
56
- simulateRequestScope(() => {
57
- const sc = core.assess.getSourceContext();
58
- handleAutoCompleteMissing(sc, { responseHeaders, responseBody: '<form autocomplete="off"></form>' });
59
-
60
- expect(reportFindings).to.not.have.been.called;
61
- });
62
- });
63
-
64
- it('reports when the auto-complete option is not set to "off"', function () {
65
- simulateRequestScope(() => {
66
- const sc = core.assess.getSourceContext();
67
- handleAutoCompleteMissing(
68
- sc,
69
- responseHeaders,
70
- '<form autocomplete="off"></form><form></form><form autocomplete="o"></form>'
71
- );
72
-
73
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
74
- ruleId: 'autocomplete-missing',
75
- vulnerabilityMetadata: {
76
- attribute: undefined,
77
- html: '&lt;form&gt;',
78
- start: 0,
79
- end: 6
80
- }
81
- });
82
- });
83
- });
84
- });
85
-
86
- describe('handleCacheControlsMissing', function () {
87
- it('does not report anything if there is no body and the result is parsable', function () {
88
- simulateRequestScope(() => {
89
- const sc = core.assess.getSourceContext();
90
-
91
- handleCacheControlsMissing(sc, {}, '');
92
-
93
- expect(reportFindings).to.not.have.been.called;
94
- });
95
- });
96
-
97
- it('does not report if there are cache control headers', function () {
98
- simulateRequestScope(() => {
99
- const sc = core.assess.getSourceContext();
100
- handleCacheControlsMissing(
101
- sc,
102
- { 'cache-control': 'no-cache; no-store' },
103
- 'test'
104
- );
105
-
106
- expect(reportFindings).to.not.have.been.called;
107
- });
108
- });
109
-
110
- it('reports if there is a pragma header', function () {
111
- simulateRequestScope(() => {
112
- const sc = core.assess.getSourceContext();
113
- handleCacheControlsMissing(
114
- sc,
115
- { pragma: 'no-cache' },
116
- 'test'
117
- );
118
-
119
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
120
- ruleId: 'cache-controls-missing',
121
- vulnerabilityMetadata: {
122
- data: JSON.stringify([{ type: 'Header', name: 'pragma', value: 'no-cache' }])
123
- }
124
- });
125
- });
126
- });
127
-
128
- it('reports the cache-control header and the meta tags if they are not fully safe', function () {
129
- simulateRequestScope(() => {
130
- const sc = core.assess.getSourceContext();
131
- handleCacheControlsMissing(
132
- sc,
133
- { 'cache-control': 'no-store' },
134
- '<meta http-equiv="cache-control">'
135
- );
136
-
137
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
138
- ruleId: 'cache-controls-missing',
139
- vulnerabilityMetadata: {
140
- data: JSON.stringify([
141
- { type: 'Header', name: 'cache-control', value: 'no-store' },
142
- { type: 'META tag', name: 'cache-control', value: '<meta http-equiv="cache-control">' },
143
- ])
144
- }
145
- });
146
- });
147
- });
148
- });
149
-
150
- describe('handleClickJackingControlsMissing', function () {
151
- it('does not report when we have the correct x-frame-options header', function () {
152
- simulateRequestScope(() => {
153
- const sc = core.assess.getSourceContext();
154
- handleClickJackingControlsMissing(sc, {
155
- 'x-frame-options': 'DENY'
156
- });
157
- handleClickJackingControlsMissing(sc, {
158
- 'x-frame-options': 'SAMEORIGIN'
159
- });
160
-
161
- expect(reportFindings).to.not.have.been.called;
162
- });
163
- });
164
-
165
- it('reports when there is no x-frame-options header', function () {
166
- simulateRequestScope(() => {
167
- const sc = core.assess.getSourceContext();
168
- handleClickJackingControlsMissing(sc, {});
169
-
170
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
171
- ruleId: 'clickjacking-control-missing'
172
- });
173
- });
174
- });
175
-
176
- it('reports when the x-frame-options header is with a not safe value', function () {
177
- simulateRequestScope(() => {
178
- const sc = core.assess.getSourceContext();
179
- handleClickJackingControlsMissing(sc, {
180
- 'x-frame-options': 'ALLOW-FROM origin'
181
- });
182
-
183
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
184
- ruleId: 'clickjacking-control-missing'
185
- });
186
- });
187
- });
188
- });
189
-
190
- describe('handleParameterPollution', function () {
191
- it('does not report if all form elements have an action attribute', function () {
192
- simulateRequestScope(() => {
193
- const sc = core.assess.getSourceContext();
194
-
195
- handleParameterPollution(sc, '<form action="foo.com"></form><form action="bar.com"></form>');
196
-
197
- expect(reportFindings).to.not.have.been.called;
198
- });
199
- });
200
-
201
- it('reports when one of the form elements does not have an acton attribute', function () {
202
- simulateRequestScope(() => {
203
- const sc = core.assess.getSourceContext();
204
- handleParameterPollution(sc, '<form action="foo.com"></form><form></form>');
205
-
206
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
207
- ruleId: 'parameter-pollution',
208
- vulnerabilityMetadata: {
209
- attribute: undefined,
210
- html: '&lt;form&gt;'
211
- }
212
- });
213
- });
214
- });
215
- });
216
-
217
- describe('handleCspHeader', function () {
218
- it('does not report when we have a secure csp header', function () {
219
- simulateRequestScope(() => {
220
- const sc = core.assess.getSourceContext();
221
- handleCspHeader(sc, {
222
- 'content-security-policy': 'default-src "self"; base-uri "foobar"; form-action "foobar"; frame-ancestors "foobar"; plugin-types "foobar"'
223
- });
224
-
225
- expect(reportFindings).to.not.have.been.called;
226
- });
227
- });
228
-
229
- it('reports when there are no csp headers', function () {
230
- simulateRequestScope(() => {
231
- const sc = core.assess.getSourceContext();
232
-
233
- handleCspHeader(sc, {});
234
-
235
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
236
- ruleId: 'csp-header-missing'
237
- });
238
- });
239
- });
240
-
241
- it('reports whent the csp headers are not all secure', function () {
242
- simulateRequestScope(() => {
243
- const sc = core.assess.getSourceContext();
244
- handleCspHeader(sc, {
245
- 'content-security-policy': 'default-src "self"; form-action "foobar"; frame-ancestors "foobar"; plugin-types "foobar"'
246
- });
247
-
248
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
249
- ruleId: 'csp-header-insecure',
250
- vulnerabilityMetadata: {
251
- data: JSON.stringify({
252
- defaultSrcSecure: true,
253
- defaultSrcValue: '"self"',
254
- childSrcSecure: true,
255
- childSrcValue: '',
256
- connectSrcSecure: true,
257
- connectSrcValue: '',
258
- frameSrcSecure: true,
259
- frameSrcValue: '',
260
- mediaSrcSecure: true,
261
- mediaSrcValue: '',
262
- objectSrcSecure: true,
263
- objectSrcValue: '',
264
- scriptSrcSecure: true,
265
- scriptSrcValue: '',
266
- styleSrcSecure: true,
267
- styleSrcValue: '',
268
- baseUriSecure: false,
269
- baseUriValue: '',
270
- formActionSecure: true,
271
- formActionValue: '"foobar"',
272
- frameAncestorsSecure: true,
273
- frameAncestorsValue: '"foobar"',
274
- })
275
- }
276
- });
277
- });
278
- });
279
- });
280
-
281
- describe('handleHstsHeaderMissing', function () {
282
- it('does not report when the max age is set properly on the hsts header', function () {
283
- const sc = core.assess.getSourceContext();
284
- handleHstsHeaderMissing(sc, {
285
- 'strict-transport-security': 'max-age=1'
286
- });
287
-
288
- expect(reportFindings).to.not.have.been.called;
289
- });
290
-
291
- it('reports when the max age is not set properly on the hsts header', function () {
292
- simulateRequestScope(() => {
293
- const sc = core.assess.getSourceContext();
294
- handleHstsHeaderMissing(sc, {
295
- 'strict-transport-security': 'max-age=0;'
296
- });
297
-
298
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
299
- ruleId: 'hsts-header-missing',
300
- vulnerabilityMetadata: { data: '0' }
301
- });
302
- });
303
- });
304
-
305
-
306
- it('reports when the hsts headers is not set at all', function () {
307
- simulateRequestScope(() => {
308
- const sc = core.assess.getSourceContext();
309
- handleHstsHeaderMissing(sc, {});
310
-
311
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
312
- ruleId: 'hsts-header-missing',
313
- vulnerabilityMetadata: { data: '' }
314
- });
315
- });
316
- });
317
- });
318
-
319
- describe('handleXPoweredByHeader', function () {
320
- it('does not report if the x-powered-by header is not set', function () {
321
- simulateRequestScope(() => {
322
- handleXPoweredByHeader(core.assess.getSourceContext(), {});
323
-
324
- expect(reportFindings).to.not.have.been.called;
325
- });
326
- });
327
-
328
- it('reports when the x-powered-by header is set', function () {
329
- simulateRequestScope(() => {
330
- const sc = core.assess.getSourceContext();
331
- handleXPoweredByHeader(sc, {
332
- 'x-powered-by': 'nginx'
333
- });
334
-
335
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
336
- ruleId: 'x-powered-by-header',
337
- vulnerabilityMetadata: { platform: 'nginx' }
338
- });
339
- });
340
- });
341
-
342
- describe('handleXContentTypeHeaderMissing', function () {
343
- it('does not report if the x-content-type-options header is set to "nosniff"', function () {
344
- simulateRequestScope(() => {
345
- handleXContentTypeHeaderMissing(core.assess.getSourceContext(), {
346
- 'x-content-type-options': 'nosniff'
347
- });
348
-
349
- expect(reportFindings).to.not.have.been.called;
350
- });
351
- });
352
-
353
- it('reports if the x-content-type-options header is set to an unsafe value', function () {
354
- simulateRequestScope(() => {
355
- const sc = core.assess.getSourceContext();
356
- handleXContentTypeHeaderMissing(sc, {
357
- 'x-content-type-options': 'unsafe'
358
- });
359
-
360
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
361
- ruleId: 'xcontenttype-header-missing',
362
- vulnerabilityMetadata: { data: 'unsafe' }
363
- });
364
- });
365
- });
366
-
367
- it('reports when the x-content-type-options header is not set', function () {
368
- simulateRequestScope(() => {
369
- const sc = core.assess.getSourceContext();
370
- handleXContentTypeHeaderMissing(sc, {
371
- responseHeaders: {}
372
- });
373
-
374
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
375
- ruleId: 'xcontenttype-header-missing',
376
- vulnerabilityMetadata: { data: '' }
377
- });
378
- });
379
- });
380
- });
381
-
382
- describe('handleXxsProtectionHeaderDisabled', function () {
383
- it('does not report if the x-xss-protection header value starts with 1', function () {
384
- simulateRequestScope(() => {
385
- handleXxsProtectionHeaderDisabled(core.assess.getSourceContext(), {
386
- responseHeaders: {
387
- 'x-xss-protection': '1'
388
- }
389
- });
390
-
391
- expect(reportFindings).to.not.have.been.called;
392
- });
393
- });
394
-
395
- it('reports if the x-xss-protection header is set to an unsafe value', function () {
396
- simulateRequestScope(() => {
397
- const sc = core.assess.getSourceContext();
398
- handleXxsProtectionHeaderDisabled(sc, {
399
- 'x-xss-protection': '0'
400
- });
401
-
402
- expect(reportFindings).to.have.been.calledOnceWith(sc, {
403
- ruleId: 'xxssprotection-header-disabled',
404
- vulnerabilityMetadata: { data: '0' }
405
- });
406
- });
407
- });
408
-
409
- it('reports when the x-xss-protection header is not set', function () {
410
- simulateRequestScope(() => {
411
- const sc = core.assess.getSourceContext();
412
- handleXxsProtectionHeaderDisabled(sc, {});
413
-
414
- expect(reportFindings).not.to.have.been.called;
415
- });
416
- });
417
- });
418
- });
419
- });