@contrast/assess 1.31.0 → 1.33.0
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.
- package/lib/crypto-analysis/install/crypto.test.js +146 -0
- package/lib/crypto-analysis/install/math.test.js +65 -0
- package/lib/dataflow/index.test.js +36 -0
- package/lib/dataflow/propagation/index.test.js +103 -0
- package/lib/dataflow/propagation/install/JSON/index.test.js +50 -0
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +232 -0
- package/lib/dataflow/propagation/install/JSON/parse.test.js +968 -0
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +265 -0
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +106 -0
- package/lib/dataflow/propagation/install/buffer.test.js +109 -0
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +94 -0
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +49 -0
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +50 -0
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +148 -0
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +145 -0
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +78 -0
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +69 -0
- package/lib/dataflow/propagation/install/ejs/template.test.js +62 -0
- package/lib/dataflow/propagation/install/encode-uri.test.js +83 -0
- package/lib/dataflow/propagation/install/escape-html.test.js +71 -0
- package/lib/dataflow/propagation/install/escape.test.js +73 -0
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +71 -0
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +58 -0
- package/lib/dataflow/propagation/install/joi/any.test.js +270 -0
- package/lib/dataflow/propagation/install/joi/array.test.js +912 -0
- package/lib/dataflow/propagation/install/joi/boolean.test.js +103 -0
- package/lib/dataflow/propagation/install/joi/expression.test.js +76 -0
- package/lib/dataflow/propagation/install/joi/index.test.js +39 -0
- package/lib/dataflow/propagation/install/joi/number.test.js +103 -0
- package/lib/dataflow/propagation/install/joi/object.test.js +119 -0
- package/lib/dataflow/propagation/install/joi/ref.test.js +607 -0
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +513 -0
- package/lib/dataflow/propagation/install/mongoose/index.test.js +42 -0
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +348 -0
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +512 -0
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +160 -0
- package/lib/dataflow/propagation/install/mustache-escape.test.js +62 -0
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +74 -0
- package/lib/dataflow/propagation/install/parse-int.test.js +48 -0
- package/lib/dataflow/propagation/install/path/basename.test.js +143 -0
- package/lib/dataflow/propagation/install/path/dirname.test.js +167 -0
- package/lib/dataflow/propagation/install/path/extname.test.js +141 -0
- package/lib/dataflow/propagation/install/path/format.test.js +250 -0
- package/lib/dataflow/propagation/install/path/index.test.js +45 -0
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +485 -0
- package/lib/dataflow/propagation/install/path/normalize.test.js +176 -0
- package/lib/dataflow/propagation/install/path/parse.test.js +238 -0
- package/lib/dataflow/propagation/install/path/relative.test.js +239 -0
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +158 -0
- package/lib/dataflow/propagation/install/pug/index.test.js +55 -0
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +69 -0
- package/lib/dataflow/propagation/install/querystring/escape.test.js +63 -0
- package/lib/dataflow/propagation/install/querystring/index.test.js +40 -0
- package/lib/dataflow/propagation/install/querystring/parse.test.js +272 -0
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +301 -0
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +281 -0
- package/lib/dataflow/propagation/install/send.test.js +63 -0
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +73 -0
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +130 -0
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +100 -0
- package/lib/dataflow/propagation/install/string/concat.test.js +132 -0
- package/lib/dataflow/propagation/install/string/format-methods.test.js +61 -0
- package/lib/dataflow/propagation/install/string/html-methods.test.js +164 -0
- package/lib/dataflow/propagation/install/string/index.test.js +103 -0
- package/lib/dataflow/propagation/install/string/match-all.test.js +399 -0
- package/lib/dataflow/propagation/install/string/match.test.js +361 -0
- package/lib/dataflow/propagation/install/string/replace.test.js +588 -0
- package/lib/dataflow/propagation/install/string/slice.test.js +265 -0
- package/lib/dataflow/propagation/install/string/split.test.js +500 -0
- package/lib/dataflow/propagation/install/string/substring.test.js +238 -0
- package/lib/dataflow/propagation/install/string/trim.test.js +122 -0
- package/lib/dataflow/propagation/install/unescape.test.js +78 -0
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +63 -0
- package/lib/dataflow/propagation/install/url/parse.test.js +391 -0
- package/lib/dataflow/propagation/install/url/searchParams.test.js +538 -0
- package/lib/dataflow/propagation/install/url/url.test.js +466 -0
- package/lib/dataflow/propagation/install/util-format.test.js +336 -0
- package/lib/dataflow/propagation/install/validator/hooks.test.js +211 -0
- package/lib/dataflow/sinks/index.test.js +78 -0
- package/lib/dataflow/sinks/install/child-process.test.js +338 -0
- package/lib/dataflow/sinks/install/eval.test.js +95 -0
- package/lib/dataflow/sinks/install/express/index.test.js +33 -0
- package/lib/dataflow/sinks/install/express/reflected-xss.js +55 -57
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +109 -0
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +144 -0
- package/lib/dataflow/sinks/install/fastify/index.test.js +32 -0
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +130 -0
- package/lib/dataflow/sinks/install/fs.test.js +138 -0
- package/lib/dataflow/sinks/install/function.test.js +103 -0
- package/lib/dataflow/sinks/install/hapi/index.test.js +32 -0
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +130 -0
- package/lib/dataflow/sinks/install/http/index.test.js +33 -0
- package/lib/dataflow/sinks/install/http/request.test.js +184 -0
- package/lib/dataflow/sinks/install/http/server-response.test.js +162 -0
- package/lib/dataflow/sinks/install/koa/index.test.js +32 -0
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +200 -0
- package/lib/dataflow/sinks/install/libxmljs.test.js +158 -0
- package/lib/dataflow/sinks/install/marsdb.test.js +166 -0
- package/lib/dataflow/sinks/install/mongodb.test.js +621 -0
- package/lib/dataflow/sinks/install/mssql.test.js +136 -0
- package/lib/dataflow/sinks/install/mysql.test.js +233 -0
- package/lib/dataflow/sinks/install/node-serialize.test.js +85 -0
- package/lib/dataflow/sinks/install/postgres.test.js +158 -0
- package/lib/dataflow/sinks/install/restify.test.js +142 -0
- package/lib/dataflow/sinks/install/sequelize.test.js +100 -0
- package/lib/dataflow/sinks/install/sqlite3.test.js +118 -0
- package/lib/dataflow/sinks/install/vm.test.js +326 -0
- package/lib/dataflow/sources/handler.test.js +463 -0
- package/lib/dataflow/sources/index.test.js +58 -0
- package/lib/dataflow/sources/install/body-parser1.test.js +248 -0
- package/lib/dataflow/sources/install/busboy.test.js +152 -0
- package/lib/dataflow/sources/install/cookie-parser1.test.js +143 -0
- package/lib/dataflow/sources/install/express/params.test.js +105 -0
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +65 -0
- package/lib/dataflow/sources/install/fastify/fastify.test.js +210 -0
- package/lib/dataflow/sources/install/fastify/index.test.js +33 -0
- package/lib/dataflow/sources/install/formidable1.test.js +119 -0
- package/lib/dataflow/sources/install/hapi/hapi.test.js +172 -0
- package/lib/dataflow/sources/install/hapi/index.test.js +33 -0
- package/lib/dataflow/sources/install/http.test.js +155 -0
- package/lib/dataflow/sources/install/koa/index.test.js +40 -0
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +161 -0
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +197 -0
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +146 -0
- package/lib/dataflow/sources/install/koa/koa2.test.js +145 -0
- package/lib/dataflow/sources/install/multer1.test.js +145 -0
- package/lib/dataflow/sources/install/qs6.test.js +131 -0
- package/lib/dataflow/sources/install/querystring.test.js +82 -0
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +88 -0
- package/lib/dataflow/sources/install/restify/index.test.js +38 -0
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +144 -0
- package/lib/dataflow/sources/install/restify/router.test.js +83 -0
- package/lib/dataflow/tag-utils-complete.test.js +27 -0
- package/lib/dataflow/tag-utils.test.js +192 -0
- package/lib/dataflow/tracker.js +7 -2
- package/lib/dataflow/tracker.test.js +216 -0
- package/lib/dataflow/utils/is-safe-content-type.test.js +16 -0
- package/lib/dataflow/utils/is-vulnerable.test.js +115 -0
- package/lib/event-factory.test.js +321 -0
- package/lib/get-policy.test.js +194 -0
- package/lib/get-source-context.js +10 -1
- package/lib/get-source-context.test.js +108 -0
- package/lib/index.test.js +41 -0
- package/lib/make-source-context.test.js +50 -0
- package/lib/response-scanning/handlers/index.test.js +425 -0
- package/lib/response-scanning/handlers/utils.test.js +391 -0
- package/lib/response-scanning/index.test.js +41 -0
- package/lib/response-scanning/install/http.test.js +175 -0
- package/lib/rule-scopes.test.js +27 -0
- package/lib/session-configuration/handlers.test.js +84 -0
- package/lib/session-configuration/index.test.js +36 -0
- package/lib/session-configuration/install/express-session.test.js +220 -0
- package/lib/session-configuration/install/fastify-cookie.test.js +65 -0
- package/lib/session-configuration/install/hapi.test.js +269 -0
- package/lib/session-configuration/install/koa.test.js +92 -0
- package/package.json +2 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { Event } = require('@contrast/common');
|
|
5
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
+
const {
|
|
7
|
+
InstrumentationType: { SOURCE, PROPAGATOR, RULE }
|
|
8
|
+
} = require('./constants');
|
|
9
|
+
|
|
10
|
+
describe('assess getSourceContext', function () {
|
|
11
|
+
let core, simulateRequestScope;
|
|
12
|
+
|
|
13
|
+
beforeEach(function () {
|
|
14
|
+
({ core, simulateRequestScope } = initAssessFixture());
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
function execStoreAssertions(assessStore) {
|
|
18
|
+
expect(assessStore).to.be.an('object').and.deep.include({
|
|
19
|
+
reqData: {
|
|
20
|
+
ip: '127.0.0.1',
|
|
21
|
+
httpVersion: '1.1',
|
|
22
|
+
method: 'get',
|
|
23
|
+
headers: {
|
|
24
|
+
'content-type': 'text/html',
|
|
25
|
+
language: 'en',
|
|
26
|
+
referer: 'http://fake.url.foo',
|
|
27
|
+
},
|
|
28
|
+
uriPath: '/index',
|
|
29
|
+
queries: '_id=123',
|
|
30
|
+
contentType: 'text/html'
|
|
31
|
+
},
|
|
32
|
+
responseData: {},
|
|
33
|
+
sourceEventsCount: 0,
|
|
34
|
+
propagationEventsCount: 0,
|
|
35
|
+
});
|
|
36
|
+
expect(assessStore.policy.enabledRules).to.have.length.greaterThan(5);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
it('returns `null` when not in request scope', function() {
|
|
40
|
+
expect(core.assess.getSourceContext()).to.be.null;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('getSourceContext()', function() {
|
|
44
|
+
it('returns assess store when in request scope', function() {
|
|
45
|
+
simulateRequestScope(() => {
|
|
46
|
+
execStoreAssertions(core.assess.getSourceContext());
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('.getSourceContext(SOURCE?)', function() {
|
|
52
|
+
it('returns assess store when max source event threshold is not met', function() {
|
|
53
|
+
simulateRequestScope(() => {
|
|
54
|
+
execStoreAssertions(core.assess.getSourceContext(SOURCE));
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('returns `null` when max source event threshold is exceeded', function() {
|
|
59
|
+
simulateRequestScope(() => {
|
|
60
|
+
core.config.setValue('assess.max_context_source_events', 10);
|
|
61
|
+
core.scopes.sources.getStore().assess.sourceEventsCount = 11;
|
|
62
|
+
expect(core.assess.getSourceContext(SOURCE)).to.be.null;
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('.getSourceContext(PROPAGATOR?)', function() {
|
|
68
|
+
it('returns assess store when max propagation event threshold is not met', function() {
|
|
69
|
+
simulateRequestScope(() => {
|
|
70
|
+
execStoreAssertions(core.assess.getSourceContext(SOURCE));
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('returns `null` when max propagation event threshold is exceeded', function() {
|
|
75
|
+
simulateRequestScope(() => {
|
|
76
|
+
core.config.setValue('assess.max_propagation_events', 10);
|
|
77
|
+
core.scopes.sources.getStore().assess.propagationEventsCount = 11;
|
|
78
|
+
expect(core.assess.getSourceContext(PROPAGATOR)).to.be.null;
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('.getSourceContext(SINK?, ruleId?)', function() {
|
|
84
|
+
it('returns assess store when ruleId is not passed', function() {
|
|
85
|
+
simulateRequestScope(() => {
|
|
86
|
+
execStoreAssertions(core.assess.getSourceContext(RULE));
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('returns assess store when ruleId provided is enabled in the policy', function() {
|
|
91
|
+
simulateRequestScope(() => {
|
|
92
|
+
execStoreAssertions(core.assess.getSourceContext(RULE, 'reflected-xss'));
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('returns `null` when ruleId provided is not enabled in the policy', function() {
|
|
97
|
+
core.messages.emit(Event.SERVER_SETTINGS_UPDATE, {
|
|
98
|
+
assess: {
|
|
99
|
+
['reflected-xss']: { enable: false },
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
simulateRequestScope(() => {
|
|
104
|
+
expect(core.assess.getSourceContext(RULE, 'reflected-xss')).to.be.null;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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[moduleName] = mock[moduleName];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe('assess', function () {
|
|
12
|
+
let core, assessMock, assessModule, modulesWithInstall;
|
|
13
|
+
|
|
14
|
+
beforeEach(function () {
|
|
15
|
+
assessMock = mocks.assess();
|
|
16
|
+
core = mocks.core();
|
|
17
|
+
core.config = mocks.config();
|
|
18
|
+
core.logger = mocks.logger();
|
|
19
|
+
core.rewriter = mocks.rewriter();
|
|
20
|
+
core.scopes = mocks.scopes();
|
|
21
|
+
core.config.assess.enable = true;
|
|
22
|
+
|
|
23
|
+
assessModule = proxyquire('.', {
|
|
24
|
+
'./session-configuration': moduleMock('sessionConfiguration', assessMock),
|
|
25
|
+
'./dataflow': moduleMock('dataflow', assessMock),
|
|
26
|
+
'./response-scanning': moduleMock('responseScanning', assessMock),
|
|
27
|
+
'./crypto-analysis': moduleMock('cryptoAnalysis', assessMock),
|
|
28
|
+
});
|
|
29
|
+
modulesWithInstall = ['sessionConfiguration', 'dataflow', 'responseScanning', 'cryptoAnalysis'];
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('installs the components', function () {
|
|
33
|
+
core.config.getEffectiveValue.withArgs('assess.enable').returns(true);
|
|
34
|
+
|
|
35
|
+
assessModule(core).install();
|
|
36
|
+
modulesWithInstall.forEach((module) => {
|
|
37
|
+
expect(assessMock[module].install).to.have.been.calledOnce;
|
|
38
|
+
});
|
|
39
|
+
expect(core.rewriter.install).to.have.been.calledWith('assess');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
|
|
9
|
+
describe('assess makeSourceContext', function () {
|
|
10
|
+
let core;
|
|
11
|
+
|
|
12
|
+
beforeEach(function () {
|
|
13
|
+
({ core } = initAssessFixture());
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('will return `null` and log error when passed insufficient parameters', function() {
|
|
17
|
+
const assessCtx = core.assess.makeSourceContext({}, {});
|
|
18
|
+
expect(assessCtx).to.be.null;
|
|
19
|
+
expect(core.logger.error).to.have.been.calledWithMatch({
|
|
20
|
+
err: sinon.match.has('message'),
|
|
21
|
+
}, 'unable to construct assess store. assess will be disabled for request.');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('construct the store correctly given req and res', function() {
|
|
25
|
+
const req = mocks.incomingMessage();
|
|
26
|
+
const res = {};
|
|
27
|
+
|
|
28
|
+
const assessCtx = core.assess.makeSourceContext(req, res);
|
|
29
|
+
|
|
30
|
+
expect(assessCtx).to.deep.include({
|
|
31
|
+
propagationEventsCount: 0,
|
|
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
|
+
});
|
|
@@ -0,0 +1,425 @@
|
|
|
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: '<form>',
|
|
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: '<form>'
|
|
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
|
+
baseUriSecure: false,
|
|
255
|
+
baseUriValue: '',
|
|
256
|
+
childSrcSecure: true,
|
|
257
|
+
childSrcValue: '',
|
|
258
|
+
connectSrcSecure: true,
|
|
259
|
+
connectSrcValue: '',
|
|
260
|
+
frameSrcSecure: true,
|
|
261
|
+
frameSrcValue: '',
|
|
262
|
+
mediaSrcSecure: true,
|
|
263
|
+
mediaSrcValue: '',
|
|
264
|
+
objectSrcSecure: true,
|
|
265
|
+
objectSrcValue: '',
|
|
266
|
+
scriptSrcSecure: true,
|
|
267
|
+
scriptSrcValue: '',
|
|
268
|
+
styleSrcSecure: true,
|
|
269
|
+
styleSrcValue: '',
|
|
270
|
+
formActionSecure: true,
|
|
271
|
+
formActionValue: '"foobar"',
|
|
272
|
+
frameAncestorsSecure: true,
|
|
273
|
+
frameAncestorsValue: '"foobar"',
|
|
274
|
+
pluginTypesSecure: true,
|
|
275
|
+
pluginTypesValue: '"foobar"',
|
|
276
|
+
reflectedXssSecure: true,
|
|
277
|
+
reflectedXssValue: '',
|
|
278
|
+
refererSecure: true,
|
|
279
|
+
refererValue: ''
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('handleHstsHeaderMissing', function () {
|
|
288
|
+
it('does not report when the max age is set properly on the hsts header', function () {
|
|
289
|
+
const sc = core.assess.getSourceContext();
|
|
290
|
+
handleHstsHeaderMissing(sc, {
|
|
291
|
+
'strict-transport-security': 'max-age=1'
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
expect(reportFindings).to.not.have.been.called;
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('reports when the max age is not set properly on the hsts header', function () {
|
|
298
|
+
simulateRequestScope(() => {
|
|
299
|
+
const sc = core.assess.getSourceContext();
|
|
300
|
+
handleHstsHeaderMissing(sc, {
|
|
301
|
+
'strict-transport-security': 'max-age=0;'
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
expect(reportFindings).to.have.been.calledOnceWith(sc, {
|
|
305
|
+
ruleId: 'hsts-header-missing',
|
|
306
|
+
vulnerabilityMetadata: { data: '0' }
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
it('reports when the hsts headers is not set at all', function () {
|
|
313
|
+
simulateRequestScope(() => {
|
|
314
|
+
const sc = core.assess.getSourceContext();
|
|
315
|
+
handleHstsHeaderMissing(sc, {});
|
|
316
|
+
|
|
317
|
+
expect(reportFindings).to.have.been.calledOnceWith(sc, {
|
|
318
|
+
ruleId: 'hsts-header-missing',
|
|
319
|
+
vulnerabilityMetadata: { data: '' }
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
describe('handleXPoweredByHeader', function () {
|
|
326
|
+
it('does not report if the x-powered-by header is not set', function () {
|
|
327
|
+
simulateRequestScope(() => {
|
|
328
|
+
handleXPoweredByHeader(core.assess.getSourceContext(), {});
|
|
329
|
+
|
|
330
|
+
expect(reportFindings).to.not.have.been.called;
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it('reports when the x-powered-by header is set', function () {
|
|
335
|
+
simulateRequestScope(() => {
|
|
336
|
+
const sc = core.assess.getSourceContext();
|
|
337
|
+
handleXPoweredByHeader(sc, {
|
|
338
|
+
'x-powered-by': 'nginx'
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
expect(reportFindings).to.have.been.calledOnceWith(sc, {
|
|
342
|
+
ruleId: 'x-powered-by-header',
|
|
343
|
+
vulnerabilityMetadata: { platform: 'nginx' }
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
describe('handleXContentTypeHeaderMissing', function () {
|
|
349
|
+
it('does not report if the x-content-type-options header is set to "nosniff"', function () {
|
|
350
|
+
simulateRequestScope(() => {
|
|
351
|
+
handleXContentTypeHeaderMissing(core.assess.getSourceContext(), {
|
|
352
|
+
'x-content-type-options': 'nosniff'
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
expect(reportFindings).to.not.have.been.called;
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('reports if the x-content-type-options header is set to an unsafe value', function () {
|
|
360
|
+
simulateRequestScope(() => {
|
|
361
|
+
const sc = core.assess.getSourceContext();
|
|
362
|
+
handleXContentTypeHeaderMissing(sc, {
|
|
363
|
+
'x-content-type-options': 'unsafe'
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
expect(reportFindings).to.have.been.calledOnceWith(sc, {
|
|
367
|
+
ruleId: 'xcontenttype-header-missing',
|
|
368
|
+
vulnerabilityMetadata: { data: 'unsafe' }
|
|
369
|
+
});
|
|
370
|
+
});
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
it('reports when the x-content-type-options header is not set', function () {
|
|
374
|
+
simulateRequestScope(() => {
|
|
375
|
+
const sc = core.assess.getSourceContext();
|
|
376
|
+
handleXContentTypeHeaderMissing(sc, {
|
|
377
|
+
responseHeaders: {}
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
expect(reportFindings).to.have.been.calledOnceWith(sc, {
|
|
381
|
+
ruleId: 'xcontenttype-header-missing',
|
|
382
|
+
vulnerabilityMetadata: { data: '' }
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
describe('handleXxsProtectionHeaderDisabled', function () {
|
|
389
|
+
it('does not report if the x-xss-protection header value starts with 1', function () {
|
|
390
|
+
simulateRequestScope(() => {
|
|
391
|
+
handleXxsProtectionHeaderDisabled(core.assess.getSourceContext(), {
|
|
392
|
+
responseHeaders: {
|
|
393
|
+
'x-xss-protection': '1'
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
expect(reportFindings).to.not.have.been.called;
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('reports if the x-xss-protection header is set to an unsafe value', function () {
|
|
402
|
+
simulateRequestScope(() => {
|
|
403
|
+
const sc = core.assess.getSourceContext();
|
|
404
|
+
handleXxsProtectionHeaderDisabled(sc, {
|
|
405
|
+
'x-xss-protection': '0'
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
expect(reportFindings).to.have.been.calledOnceWith(sc, {
|
|
409
|
+
ruleId: 'xxssprotection-header-disabled',
|
|
410
|
+
vulnerabilityMetadata: { data: '0' }
|
|
411
|
+
});
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
it('reports when the x-xss-protection header is not set', function () {
|
|
416
|
+
simulateRequestScope(() => {
|
|
417
|
+
const sc = core.assess.getSourceContext();
|
|
418
|
+
handleXxsProtectionHeaderDisabled(sc, {});
|
|
419
|
+
|
|
420
|
+
expect(reportFindings).not.to.have.been.called;
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
});
|