@contrast/assess 1.46.1 → 1.46.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +14 -11
- package/lib/crypto-analysis/install/crypto.test.js +0 -146
- package/lib/crypto-analysis/install/math.test.js +0 -65
- package/lib/dataflow/index.test.js +0 -36
- package/lib/dataflow/propagation/index.test.js +0 -103
- package/lib/dataflow/propagation/install/JSON/index.test.js +0 -50
- package/lib/dataflow/propagation/install/JSON/parse-fn.test.js +0 -232
- package/lib/dataflow/propagation/install/JSON/parse.test.js +0 -968
- package/lib/dataflow/propagation/install/JSON/stringify.test.js +0 -265
- package/lib/dataflow/propagation/install/array-prototype-join.test.js +0 -106
- package/lib/dataflow/propagation/install/buffer.test.js +0 -112
- package/lib/dataflow/propagation/install/contrast-methods/add.test.js +0 -94
- package/lib/dataflow/propagation/install/contrast-methods/index.test.js +0 -49
- package/lib/dataflow/propagation/install/contrast-methods/number.test.js +0 -50
- package/lib/dataflow/propagation/install/contrast-methods/string.test.js +0 -148
- package/lib/dataflow/propagation/install/contrast-methods/tag.test.js +0 -145
- package/lib/dataflow/propagation/install/decode-uri-component.test.js +0 -78
- package/lib/dataflow/propagation/install/ejs/escape-xml.test.js +0 -69
- package/lib/dataflow/propagation/install/ejs/template.test.js +0 -62
- package/lib/dataflow/propagation/install/encode-uri.test.js +0 -83
- package/lib/dataflow/propagation/install/escape-html.test.js +0 -71
- package/lib/dataflow/propagation/install/escape.test.js +0 -73
- package/lib/dataflow/propagation/install/fastify-send.test.js +0 -42
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.test.js +0 -71
- package/lib/dataflow/propagation/install/isnumeric-0.test.js +0 -58
- package/lib/dataflow/propagation/install/joi/any.test.js +0 -270
- package/lib/dataflow/propagation/install/joi/array.test.js +0 -912
- package/lib/dataflow/propagation/install/joi/boolean.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/expression.test.js +0 -76
- package/lib/dataflow/propagation/install/joi/index.test.js +0 -39
- package/lib/dataflow/propagation/install/joi/number.test.js +0 -103
- package/lib/dataflow/propagation/install/joi/object.test.js +0 -119
- package/lib/dataflow/propagation/install/joi/ref.test.js +0 -607
- package/lib/dataflow/propagation/install/joi/string-schema.test.js +0 -513
- package/lib/dataflow/propagation/install/mongoose/index.test.js +0 -42
- package/lib/dataflow/propagation/install/mongoose/schema-map.test.js +0 -348
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.test.js +0 -511
- package/lib/dataflow/propagation/install/mongoose/schema-string.test.js +0 -199
- package/lib/dataflow/propagation/install/mustache-escape.test.js +0 -62
- package/lib/dataflow/propagation/install/mysql-connection-escape.test.js +0 -74
- package/lib/dataflow/propagation/install/parse-int.test.js +0 -48
- package/lib/dataflow/propagation/install/path/basename.test.js +0 -143
- package/lib/dataflow/propagation/install/path/dirname.test.js +0 -167
- package/lib/dataflow/propagation/install/path/extname.test.js +0 -141
- package/lib/dataflow/propagation/install/path/format.test.js +0 -250
- package/lib/dataflow/propagation/install/path/index.test.js +0 -45
- package/lib/dataflow/propagation/install/path/join-and-resolve.test.js +0 -485
- package/lib/dataflow/propagation/install/path/normalize.test.js +0 -176
- package/lib/dataflow/propagation/install/path/parse.test.js +0 -238
- package/lib/dataflow/propagation/install/path/relative.test.js +0 -239
- package/lib/dataflow/propagation/install/path/toNamespacedPath.test.js +0 -158
- package/lib/dataflow/propagation/install/pug/index.test.js +0 -55
- package/lib/dataflow/propagation/install/pug-runtime-escape.test.js +0 -69
- package/lib/dataflow/propagation/install/querystring/escape.test.js +0 -63
- package/lib/dataflow/propagation/install/querystring/index.test.js +0 -40
- package/lib/dataflow/propagation/install/querystring/parse.test.js +0 -272
- package/lib/dataflow/propagation/install/querystring/stringify.test.js +0 -301
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.test.js +0 -283
- package/lib/dataflow/propagation/install/send.test.js +0 -63
- package/lib/dataflow/propagation/install/sequelize/query-generator.test.js +0 -74
- package/lib/dataflow/propagation/install/sequelize/sql-string.test.js +0 -119
- package/lib/dataflow/propagation/install/sql-template-strings.test.js +0 -100
- package/lib/dataflow/propagation/install/string/concat.test.js +0 -145
- package/lib/dataflow/propagation/install/string/format-methods.test.js +0 -74
- package/lib/dataflow/propagation/install/string/html-methods.test.js +0 -177
- package/lib/dataflow/propagation/install/string/index.test.js +0 -103
- package/lib/dataflow/propagation/install/string/match-all.test.js +0 -412
- package/lib/dataflow/propagation/install/string/match.test.js +0 -374
- package/lib/dataflow/propagation/install/string/replace.test.js +0 -601
- package/lib/dataflow/propagation/install/string/slice.test.js +0 -278
- package/lib/dataflow/propagation/install/string/split.test.js +0 -513
- package/lib/dataflow/propagation/install/string/substring.test.js +0 -251
- package/lib/dataflow/propagation/install/string/trim.test.js +0 -135
- package/lib/dataflow/propagation/install/unescape.test.js +0 -78
- package/lib/dataflow/propagation/install/url/domain-parsers.test.js +0 -63
- package/lib/dataflow/propagation/install/url/parse.test.js +0 -391
- package/lib/dataflow/propagation/install/url/searchParams.test.js +0 -538
- package/lib/dataflow/propagation/install/url/url.test.js +0 -466
- package/lib/dataflow/propagation/install/util-format.test.js +0 -336
- package/lib/dataflow/propagation/install/validator/hooks.test.js +0 -211
- package/lib/dataflow/sinks/index.test.js +0 -78
- package/lib/dataflow/sinks/install/child-process.test.js +0 -338
- package/lib/dataflow/sinks/install/eval.test.js +0 -95
- package/lib/dataflow/sinks/install/express/index.test.js +0 -33
- package/lib/dataflow/sinks/install/express/reflected-xss.test.js +0 -109
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.test.js +0 -144
- package/lib/dataflow/sinks/install/fastify/index.test.js +0 -32
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/fs.test.js +0 -138
- package/lib/dataflow/sinks/install/function.test.js +0 -103
- package/lib/dataflow/sinks/install/hapi/index.test.js +0 -32
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.test.js +0 -130
- package/lib/dataflow/sinks/install/http/index.test.js +0 -33
- package/lib/dataflow/sinks/install/http/request.test.js +0 -184
- package/lib/dataflow/sinks/install/http/server-response.test.js +0 -160
- package/lib/dataflow/sinks/install/koa/index.test.js +0 -32
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.test.js +0 -200
- package/lib/dataflow/sinks/install/libxmljs.test.js +0 -158
- package/lib/dataflow/sinks/install/marsdb.test.js +0 -166
- package/lib/dataflow/sinks/install/mongodb.test.js +0 -617
- package/lib/dataflow/sinks/install/mssql.test.js +0 -134
- package/lib/dataflow/sinks/install/mysql.test.js +0 -224
- package/lib/dataflow/sinks/install/node-serialize.test.js +0 -83
- package/lib/dataflow/sinks/install/postgres.test.js +0 -152
- package/lib/dataflow/sinks/install/restify.test.js +0 -140
- package/lib/dataflow/sinks/install/sequelize.test.js +0 -100
- package/lib/dataflow/sinks/install/sqlite3.test.js +0 -118
- package/lib/dataflow/sinks/install/vm.test.js +0 -326
- package/lib/dataflow/sources/handler.test.js +0 -501
- package/lib/dataflow/sources/index.test.js +0 -60
- package/lib/dataflow/sources/install/body-parser1.test.js +0 -244
- package/lib/dataflow/sources/install/busboy.test.js +0 -152
- package/lib/dataflow/sources/install/cookie-parser1.test.js +0 -141
- package/lib/dataflow/sources/install/express/params.test.js +0 -110
- package/lib/dataflow/sources/install/express/parsedUrl.test.js +0 -107
- package/lib/dataflow/sources/install/fastify/fastify.test.js +0 -207
- package/lib/dataflow/sources/install/fastify/index.test.js +0 -33
- package/lib/dataflow/sources/install/formidable1.test.js +0 -119
- package/lib/dataflow/sources/install/graphql-http.test.js +0 -133
- package/lib/dataflow/sources/install/hapi/hapi.test.js +0 -171
- package/lib/dataflow/sources/install/hapi/index.test.js +0 -33
- package/lib/dataflow/sources/install/http.test.js +0 -149
- package/lib/dataflow/sources/install/koa/index.test.js +0 -40
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.test.js +0 -160
- package/lib/dataflow/sources/install/koa/koa-multer.test.js +0 -197
- package/lib/dataflow/sources/install/koa/koa-routers.test.js +0 -146
- package/lib/dataflow/sources/install/koa/koa2.test.js +0 -145
- package/lib/dataflow/sources/install/multer1.test.js +0 -143
- package/lib/dataflow/sources/install/qs6.test.js +0 -131
- package/lib/dataflow/sources/install/querystring.test.js +0 -82
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.test.js +0 -86
- package/lib/dataflow/sources/install/restify/index.test.js +0 -38
- package/lib/dataflow/sources/install/restify/jsonBodyParser.test.js +0 -140
- package/lib/dataflow/sources/install/restify/router.test.js +0 -81
- package/lib/dataflow/tag-utils-complete.test.js +0 -27
- package/lib/dataflow/tag-utils.test.js +0 -192
- package/lib/dataflow/tracker.test.js +0 -216
- package/lib/dataflow/utils/is-safe-content-type.test.js +0 -16
- package/lib/dataflow/utils/is-vulnerable.test.js +0 -115
- package/lib/event-factory.test.js +0 -326
- package/lib/get-policy.test.js +0 -194
- package/lib/get-source-context.test.js +0 -161
- package/lib/index.test.js +0 -45
- package/lib/make-source-context.test.js +0 -50
- package/lib/response-scanning/handlers/index.test.js +0 -419
- package/lib/response-scanning/handlers/utils.test.js +0 -380
- package/lib/response-scanning/index.test.js +0 -41
- package/lib/response-scanning/install/http.test.js +0 -175
- package/lib/rule-scopes.test.js +0 -27
- package/lib/sampler/common.test.js +0 -101
- package/lib/sampler/index.test.js +0 -313
- package/lib/session-configuration/handlers.test.js +0 -84
- package/lib/session-configuration/index.test.js +0 -36
- package/lib/session-configuration/install/express-session.test.js +0 -218
- package/lib/session-configuration/install/fastify-cookie.test.js +0 -63
- package/lib/session-configuration/install/hapi.test.js +0 -269
- package/lib/session-configuration/install/koa.test.js +0 -92
|
@@ -1,103 +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 { DataflowTag } = require('@contrast/common');
|
|
7
|
-
|
|
8
|
-
describe('assess dataflow propagation joi boolean', function() {
|
|
9
|
-
let core, joi, schema, tracker, createPropagationEvent, trackString, simulateRequestScope;
|
|
10
|
-
|
|
11
|
-
beforeEach(function() {
|
|
12
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
13
|
-
tracker = core.assess.dataflow.tracker;
|
|
14
|
-
createPropagationEvent = sinon.spy(
|
|
15
|
-
core.assess.eventFactory,
|
|
16
|
-
'createPropagationEvent'
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
core.depHooks.resolve
|
|
20
|
-
.withArgs({
|
|
21
|
-
name: 'joi',
|
|
22
|
-
file: 'lib/types/boolean.js',
|
|
23
|
-
version: '>=17 <18',
|
|
24
|
-
})
|
|
25
|
-
.yields(require('joi-17/lib/types/boolean'));
|
|
26
|
-
|
|
27
|
-
require('./index')(core).install();
|
|
28
|
-
|
|
29
|
-
joi = require('joi-17');
|
|
30
|
-
schema = joi.boolean();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(function() {
|
|
34
|
-
Object.keys(require.cache).forEach((key) => {
|
|
35
|
-
if (key.includes('joi')) {
|
|
36
|
-
delete require.cache[key];
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
createPropagationEvent.restore();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should add alphanum-space-hyphen tag if value is a string and it was coerced', function() {
|
|
43
|
-
simulateRequestScope(() => {
|
|
44
|
-
const value = trackString('true');
|
|
45
|
-
|
|
46
|
-
schema.validate(value);
|
|
47
|
-
const trackData = tracker.getData(value);
|
|
48
|
-
|
|
49
|
-
expect(trackData.tags).to.deep.equal({
|
|
50
|
-
[DataflowTag.UNTRUSTED]: [0, 3],
|
|
51
|
-
[DataflowTag.ALPHANUM_SPACE_HYPHEN]: [0, 3],
|
|
52
|
-
});
|
|
53
|
-
expect(trackData).to.deep.include({
|
|
54
|
-
moduleName: 'joi',
|
|
55
|
-
methodName: 'boolean.coerce',
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should not propagate anything if the argument is not tracked', function() {
|
|
61
|
-
simulateRequestScope(() => {
|
|
62
|
-
const value = 'true';
|
|
63
|
-
|
|
64
|
-
schema.validate(value);
|
|
65
|
-
const trackData = tracker.getData(value);
|
|
66
|
-
|
|
67
|
-
expect(trackData).to.be.null;
|
|
68
|
-
expect(createPropagationEvent).to.not.have.been.called;
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should not add alphanum-space-hyphen tag if value was already tagged', function() {
|
|
73
|
-
simulateRequestScope(() => {
|
|
74
|
-
const value = trackString('true');
|
|
75
|
-
|
|
76
|
-
schema.validate(value);
|
|
77
|
-
schema.validate(value);
|
|
78
|
-
const trackData = tracker.getData(value);
|
|
79
|
-
|
|
80
|
-
expect(trackData.tags).to.deep.equal({
|
|
81
|
-
[DataflowTag.UNTRUSTED]: [0, 3],
|
|
82
|
-
[DataflowTag.ALPHANUM_SPACE_HYPHEN]: [0, 3],
|
|
83
|
-
});
|
|
84
|
-
expect(trackData).to.deep.include({
|
|
85
|
-
moduleName: 'joi',
|
|
86
|
-
methodName: 'boolean.coerce',
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should not add alphanum-space-hyphen tag if value is a string and it was not coerced', function() {
|
|
92
|
-
simulateRequestScope(() => {
|
|
93
|
-
const value = trackString('foobar');
|
|
94
|
-
|
|
95
|
-
schema.validate(value);
|
|
96
|
-
const trackData = tracker.getData(value);
|
|
97
|
-
|
|
98
|
-
expect(trackData.tags).to.deep.equal({
|
|
99
|
-
[DataflowTag.UNTRUSTED]: [0, 5],
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
5
|
-
const { DataflowTag } = require('@contrast/common');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow propagation joi expression', function() {
|
|
8
|
-
let core, joi, tracker, trackString, simulateRequestScope;
|
|
9
|
-
|
|
10
|
-
beforeEach(function() {
|
|
11
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
12
|
-
tracker = core.assess.dataflow.tracker;
|
|
13
|
-
core.config.assess.trust_custom_validators = true;
|
|
14
|
-
|
|
15
|
-
core.depHooks.resolve.withArgs({ name: 'joi', file: 'lib/index.js', version: '>=17 <18' }).yields(require('joi-17/lib/index'));
|
|
16
|
-
|
|
17
|
-
require('./index')(core).install();
|
|
18
|
-
joi = require('joi-17');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(function() {
|
|
22
|
-
Object.keys(require.cache).forEach((key) => {
|
|
23
|
-
if (key.includes('joi')) {
|
|
24
|
-
delete require.cache[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should add html-encoded tag if value is a template string using the template syntax (joi.expression)', function() {
|
|
30
|
-
simulateRequestScope(() => {
|
|
31
|
-
const value = trackString('{{foobar}}');
|
|
32
|
-
const expr = joi.expression(value);
|
|
33
|
-
const { tags } = tracker.getData(expr.rendered);
|
|
34
|
-
expect(tags).to.deep.equal({
|
|
35
|
-
[DataflowTag.UNTRUSTED]: [0, 9],
|
|
36
|
-
[DataflowTag.HTML_ENCODED]: [0, 9]
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('should add html-encoded tag if value is a template string using the template syntax (joi.x)', function() {
|
|
42
|
-
simulateRequestScope(() => {
|
|
43
|
-
const value = trackString('{{foobar}}');
|
|
44
|
-
const expr = joi.x(value);
|
|
45
|
-
const { tags } = tracker.getData(expr.rendered);
|
|
46
|
-
expect(tags).to.deep.equal({
|
|
47
|
-
[DataflowTag.UNTRUSTED]: [0, 9],
|
|
48
|
-
[DataflowTag.HTML_ENCODED]: [0, 9]
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('should not add html-encoded tag if value is not a template string (joi.expression)', function() {
|
|
54
|
-
simulateRequestScope(() => {
|
|
55
|
-
const value = trackString('foobar');
|
|
56
|
-
const expr = joi.expression(value);
|
|
57
|
-
const { tags } = tracker.getData(expr.rendered);
|
|
58
|
-
expect(tags).to.deep.equal({
|
|
59
|
-
[DataflowTag.UNTRUSTED]: [0, 5],
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('should not add html-encoded tag if value is not a template string (joi.x)', function() {
|
|
65
|
-
simulateRequestScope(() => {
|
|
66
|
-
const value = trackString('foobar');
|
|
67
|
-
const expr = joi.x(value);
|
|
68
|
-
const { tags } = tracker.getData(expr.rendered);
|
|
69
|
-
expect(tags).to.deep.equal({
|
|
70
|
-
[DataflowTag.UNTRUSTED]: [0, 5],
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow propagation joi', function() {
|
|
8
|
-
let core, instr;
|
|
9
|
-
|
|
10
|
-
beforeEach(function() {
|
|
11
|
-
({ core } = initAssessFixture());
|
|
12
|
-
instr = core.assess.dataflow.propagation.joiInstrumentation;
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const instrumentationList = ['any', 'booleanCoerce', 'expression', 'keys', 'numberCoerce', 'object', 'stringSchema', 'values'];
|
|
16
|
-
|
|
17
|
-
it('composes different installers', function() {
|
|
18
|
-
instrumentationList.forEach((name) => {
|
|
19
|
-
expect(instr[name]).to.have.property('install').and.be.a('function');
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('dispatches installation to sub-components', function() {
|
|
24
|
-
const installs = [];
|
|
25
|
-
// stub these to prevent side effects
|
|
26
|
-
instrumentationList.forEach((name) => {
|
|
27
|
-
const instr = core.assess.dataflow.propagation.joiInstrumentation;
|
|
28
|
-
installs.push(sinon.stub(instr[name], 'install'));
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
instr.install();
|
|
32
|
-
|
|
33
|
-
expect(installs).to.have.lengthOf(8);
|
|
34
|
-
|
|
35
|
-
installs.forEach((installer) => {
|
|
36
|
-
expect(installer).to.have.been.called;
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,103 +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 { DataflowTag } = require('@contrast/common');
|
|
7
|
-
|
|
8
|
-
describe('assess dataflow propagation joi number', function() {
|
|
9
|
-
let core, joi, schema, tracker, createPropagationEvent, trackString, simulateRequestScope;
|
|
10
|
-
|
|
11
|
-
beforeEach(function() {
|
|
12
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
13
|
-
tracker = core.assess.dataflow.tracker;
|
|
14
|
-
createPropagationEvent = sinon.spy(
|
|
15
|
-
core.assess.eventFactory,
|
|
16
|
-
'createPropagationEvent'
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
core.depHooks.resolve
|
|
20
|
-
.withArgs({
|
|
21
|
-
name: 'joi',
|
|
22
|
-
file: 'lib/types/number.js',
|
|
23
|
-
version: '>=17 <18',
|
|
24
|
-
})
|
|
25
|
-
.yields(require('joi-17/lib/types/number'));
|
|
26
|
-
|
|
27
|
-
require('./index')(core).install();
|
|
28
|
-
|
|
29
|
-
joi = require('joi-17');
|
|
30
|
-
schema = joi.number();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(function() {
|
|
34
|
-
Object.keys(require.cache).forEach((key) => {
|
|
35
|
-
if (key.includes('joi')) {
|
|
36
|
-
delete require.cache[key];
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
createPropagationEvent.restore();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should add limited-chars tag if value is a string and it was coerced', function() {
|
|
43
|
-
simulateRequestScope(() => {
|
|
44
|
-
const value = trackString('1234');
|
|
45
|
-
|
|
46
|
-
schema.validate(value);
|
|
47
|
-
const trackData = tracker.getData(value);
|
|
48
|
-
|
|
49
|
-
expect(trackData.tags).to.deep.equal({
|
|
50
|
-
[DataflowTag.UNTRUSTED]: [0, 3],
|
|
51
|
-
[DataflowTag.LIMITED_CHARS]: [0, 3],
|
|
52
|
-
});
|
|
53
|
-
expect(trackData).to.deep.include({
|
|
54
|
-
moduleName: 'joi',
|
|
55
|
-
methodName: 'number.coerce',
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('should not propagate anything if the argument is not tracked', function() {
|
|
61
|
-
simulateRequestScope(() => {
|
|
62
|
-
const value = '1234';
|
|
63
|
-
|
|
64
|
-
schema.validate(value);
|
|
65
|
-
const trackData = tracker.getData(value);
|
|
66
|
-
|
|
67
|
-
expect(trackData).to.be.null;
|
|
68
|
-
expect(createPropagationEvent).to.not.have.been.called;
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should not add limited-chars tag if value was already tagged', function() {
|
|
73
|
-
simulateRequestScope(() => {
|
|
74
|
-
const value = trackString('1234');
|
|
75
|
-
|
|
76
|
-
schema.validate(value);
|
|
77
|
-
schema.validate(value);
|
|
78
|
-
const trackData = tracker.getData(value);
|
|
79
|
-
|
|
80
|
-
expect(trackData.tags).to.deep.equal({
|
|
81
|
-
[DataflowTag.UNTRUSTED]: [0, 3],
|
|
82
|
-
[DataflowTag.LIMITED_CHARS]: [0, 3],
|
|
83
|
-
});
|
|
84
|
-
expect(trackData).to.deep.include({
|
|
85
|
-
moduleName: 'joi',
|
|
86
|
-
methodName: 'number.coerce',
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should not add limited-chars tag if value is a string and it was coerced', function() {
|
|
92
|
-
simulateRequestScope(() => {
|
|
93
|
-
const value = trackString('foobar');
|
|
94
|
-
|
|
95
|
-
schema.validate(value);
|
|
96
|
-
const trackData = tracker.getData(value);
|
|
97
|
-
|
|
98
|
-
expect(trackData.tags).to.deep.equal({
|
|
99
|
-
[DataflowTag.UNTRUSTED]: [0, 5],
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
5
|
-
const { DataflowTag } = require('@contrast/common');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow propagation joi object validator with custom or external fn', function() {
|
|
8
|
-
let core, joi, tracker, trackString, simulateRequestScope;
|
|
9
|
-
|
|
10
|
-
beforeEach(function() {
|
|
11
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
12
|
-
tracker = core.assess.dataflow.tracker;
|
|
13
|
-
core.config.assess.trust_custom_validators = true;
|
|
14
|
-
|
|
15
|
-
core.depHooks.resolve.withArgs({ name: 'joi', file: 'lib/types/object', version: '>=17 <18' }).yields(require('joi-17/lib/types/object'));
|
|
16
|
-
|
|
17
|
-
require('./index')(core).install();
|
|
18
|
-
joi = require('joi-17');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
afterEach(function() {
|
|
22
|
-
Object.keys(require.cache).forEach((key) => {
|
|
23
|
-
if (key.includes('joi')) {
|
|
24
|
-
delete require.cache[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
['custom', 'external'].forEach((method) => {
|
|
30
|
-
it(`objects with tracked values passing validation with ${method} validator will be tagged with ${DataflowTag.CUSTOM_VALIDATED}`, function(done) {
|
|
31
|
-
simulateRequestScope(() => {
|
|
32
|
-
const tracked = trackString('test');
|
|
33
|
-
const schema = joi.object()[method]((value, helper) => {
|
|
34
|
-
if (value.a === 'test' && value.b === 'test') {
|
|
35
|
-
return value;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return helper.message('Invalid value');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
schema.validateAsync({
|
|
42
|
-
a: tracked,
|
|
43
|
-
b: tracked
|
|
44
|
-
})
|
|
45
|
-
.then((validated) => {
|
|
46
|
-
|
|
47
|
-
Object.values(validated).forEach((v) => {
|
|
48
|
-
const data = tracker.getData(v);
|
|
49
|
-
|
|
50
|
-
expect(data.tags).to.deep.equal({
|
|
51
|
-
[DataflowTag.UNTRUSTED]: [0, 3],
|
|
52
|
-
[DataflowTag.CUSTOM_VALIDATED]: [0, 3],
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
expect(data.moduleName).to.equal('joi');
|
|
56
|
-
expect(data.methodName).to.include(`object.${method}`);
|
|
57
|
-
});
|
|
58
|
-
done();
|
|
59
|
-
})
|
|
60
|
-
.catch(err => done(err));
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('tracked values not passing validation with an external validator won\'t be tagged', function(done) {
|
|
65
|
-
simulateRequestScope(() => {
|
|
66
|
-
const tracked = trackString('value');
|
|
67
|
-
const schema = joi.object({
|
|
68
|
-
v1: joi.object()[method]((value, helper) => {
|
|
69
|
-
if (value === 'test') {
|
|
70
|
-
return value;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return helper.message('Invalid value');
|
|
74
|
-
}),
|
|
75
|
-
v2: joi.object()[method]((value) => {
|
|
76
|
-
if (value === 'test') {
|
|
77
|
-
return value;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
throw new Error('Invalid value');
|
|
81
|
-
}),
|
|
82
|
-
v3: joi.object()[method]((value) => {
|
|
83
|
-
if (value === 'test') {
|
|
84
|
-
return value;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return 'Invalid value';
|
|
88
|
-
}),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const obj = {
|
|
92
|
-
v1: tracked,
|
|
93
|
-
v2: tracked,
|
|
94
|
-
v3: tracked,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
schema.validateAsync(obj, { abortEarly: false })
|
|
98
|
-
.then(() => {
|
|
99
|
-
done('The validation should not pass');
|
|
100
|
-
})
|
|
101
|
-
.catch(() => {
|
|
102
|
-
Object.values(obj).forEach((v) => {
|
|
103
|
-
const data = tracker.getData(v);
|
|
104
|
-
|
|
105
|
-
expect(data.tags).to.deep.equal({
|
|
106
|
-
[DataflowTag.UNTRUSTED]: [0, 4],
|
|
107
|
-
});
|
|
108
|
-
expect(data.name).to.equal('assess-dataflow-fixture');
|
|
109
|
-
});
|
|
110
|
-
done();
|
|
111
|
-
})
|
|
112
|
-
.catch(err => done(err));
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
|