@contrast/assess 1.46.0 → 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,192 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const utils = require('./tag-utils');
|
|
5
|
-
|
|
6
|
-
describe('assess dataflow tag-utils', function() {
|
|
7
|
-
describe('createSubsetTags', function() {
|
|
8
|
-
it('creates subset tags for multiple tags', function() {
|
|
9
|
-
const ret = utils.createSubsetTags({
|
|
10
|
-
lowSpan: [0, 3],
|
|
11
|
-
span: [0, 7],
|
|
12
|
-
highSpan: [3, 7],
|
|
13
|
-
below: [0, 1],
|
|
14
|
-
above: [7, 10],
|
|
15
|
-
}, 2, 4);
|
|
16
|
-
|
|
17
|
-
expect(ret).to.deep.equal({
|
|
18
|
-
lowSpan: [0, 1],
|
|
19
|
-
span: [0, 3],
|
|
20
|
-
highSpan: [1, 3],
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('creates subset tags for multiple tag ranges', function() {
|
|
25
|
-
const ret = utils.createSubsetTags({
|
|
26
|
-
multiples: [1, 2, 4, 4],
|
|
27
|
-
}, 2, 10);
|
|
28
|
-
|
|
29
|
-
expect(ret).to.deep.equal({
|
|
30
|
-
multiples: [0, 0, 2, 2]
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('will not merge results since input ranges are expected to be merged', function() {
|
|
35
|
-
const ret = utils.createSubsetTags({
|
|
36
|
-
// correctly merged these would be [1, 3]
|
|
37
|
-
multiples: [1, 2, 3, 3],
|
|
38
|
-
}, 2, 10);
|
|
39
|
-
|
|
40
|
-
expect(ret).to.deep.equal({
|
|
41
|
-
multiples: [0, 0, 1, 1]
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('createAppendTags', function() {
|
|
47
|
-
it('creates appended ranges from 2 tags #1', function() {
|
|
48
|
-
const ret = utils.createAppendTags(
|
|
49
|
-
{ untrusted: [0, 3] },
|
|
50
|
-
{ untrusted: [0, 3] },
|
|
51
|
-
3
|
|
52
|
-
);
|
|
53
|
-
expect(ret).to.deep.equal({
|
|
54
|
-
untrusted: [0, 6]
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
it('creates appended ranges from 2 tags #2', function() {
|
|
58
|
-
const ret = utils.createAppendTags(
|
|
59
|
-
{ untrusted: [0, 3] },
|
|
60
|
-
{ untrusted: [3, 6] },
|
|
61
|
-
3
|
|
62
|
-
);
|
|
63
|
-
expect(ret).to.deep.equal({
|
|
64
|
-
untrusted: [0, 3, 6, 9]
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('createFullLengthCopyTags', function() {
|
|
70
|
-
it('creates tags with the full length of the result', function() {
|
|
71
|
-
const ret = utils.createFullLengthCopyTags(
|
|
72
|
-
{
|
|
73
|
-
untrusted: [0, 10],
|
|
74
|
-
'sql-encoded': [0, 20],
|
|
75
|
-
'custom-encoded': [0, 12]
|
|
76
|
-
},
|
|
77
|
-
13
|
|
78
|
-
);
|
|
79
|
-
expect(ret).to.deep.equal({
|
|
80
|
-
untrusted: [0, 12],
|
|
81
|
-
'sql-encoded': [0, 12],
|
|
82
|
-
'custom-encoded': [0, 12]
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('returns null in case of bad arguments', function() {
|
|
87
|
-
expect(utils.createFullLengthCopyTags({}, 1)).to.be.null;
|
|
88
|
-
expect(utils.createFullLengthCopyTags({ untrusted: [0, 2] }, 0)).to.be.null;
|
|
89
|
-
expect(utils.createFullLengthCopyTags({ untrusted: [0, 2] }, null)).to.be.null;
|
|
90
|
-
expect(utils.createFullLengthCopyTags({ untrusted: [0, 2] })).to.be.null;
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe('createMergedTags', function() {
|
|
95
|
-
it('creates merged ranges from 2 tags #1', function() {
|
|
96
|
-
const ret = utils.createMergedTags(
|
|
97
|
-
{ untrusted: [0, 3] },
|
|
98
|
-
{ untrusted: [3, 6] },
|
|
99
|
-
);
|
|
100
|
-
expect(ret).to.deep.equal({
|
|
101
|
-
untrusted: [0, 6]
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('creates merged ranges from 2 tags #2', function() {
|
|
106
|
-
const ret = utils.createMergedTags(
|
|
107
|
-
{ untrusted: [0, 3] },
|
|
108
|
-
{ untrusted: [5, 8] },
|
|
109
|
-
);
|
|
110
|
-
expect(ret).to.deep.equal({
|
|
111
|
-
untrusted: [0, 3, 5, 8]
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('creates merged ranges from 2 tags #3', function() {
|
|
116
|
-
const ret = utils.createMergedTags(
|
|
117
|
-
{ untrusted: [0, 3, 9, 12, 21, 23] },
|
|
118
|
-
{ untrusted: [5, 8, 14, 18] },
|
|
119
|
-
);
|
|
120
|
-
expect(ret).to.deep.equal({
|
|
121
|
-
untrusted: [0, 3, 5, 12, 14, 18, 21, 23]
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('returns null when trying to merge empty tag ranges', function() {
|
|
126
|
-
const ret = utils.createMergedTags(
|
|
127
|
-
{ untrusted: [] },
|
|
128
|
-
{ untrusted: [] },
|
|
129
|
-
);
|
|
130
|
-
expect(ret).to.equal(null);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe('createOverlappingTags', function() {
|
|
136
|
-
it('should return overlapping tags', function() {
|
|
137
|
-
const result = utils.createOverlappingTags({
|
|
138
|
-
untrusted: [0, 20],
|
|
139
|
-
tag2: [2, 5],
|
|
140
|
-
tag3: [4, 9],
|
|
141
|
-
tag4: [6, 6]
|
|
142
|
-
}, 1, 5);
|
|
143
|
-
|
|
144
|
-
expect(result).to.eql({
|
|
145
|
-
untrusted: [[0, 20]],
|
|
146
|
-
tag2: [[2, 5]],
|
|
147
|
-
tag3: [[4, 9]],
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
describe('createEscapeTagRanges', function() {
|
|
153
|
-
it('should return empty object when no overlap exists', function() {
|
|
154
|
-
const result = utils.createEscapeTagRanges('foo', 'bar', { untrusted: [0, 2] });
|
|
155
|
-
expect(result).to.be.deep.equal({});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should carry over tag ranges when overlap exists', function() {
|
|
159
|
-
const result = utils.createEscapeTagRanges('<foo>', '<foo>', { untrusted: [1, 3] });
|
|
160
|
-
expect(result).to.be.deep.equal({ untrusted: [4, 6] });
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('should handle duplicate strings', function() {
|
|
164
|
-
const result = utils.createEscapeTagRanges('<foo><foo>', '<foo><foo>', { untrusted: [1, 3, 6, 8] });
|
|
165
|
-
expect(result).to.be.deep.equal({ untrusted: [4, 6, 15, 17] });
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('createTagsWithExclusion', function() {
|
|
170
|
-
const tests = [
|
|
171
|
-
{ args: [{ untrusted: [0, 0] }, [0, 0]], expected: null },
|
|
172
|
-
{ args: [{ untrusted: [0, 1] }, [0, 0]], expected: { untrusted: [1, 1] } },
|
|
173
|
-
{ args: [{ untrusted: [0, 1] }, [1, 1]], expected: { untrusted: [0, 0] } },
|
|
174
|
-
{ args: [{ untrusted: [0, 1] }, [0, 1]], expected: null },
|
|
175
|
-
{ args: [{ untrusted: [0, 2] }, [0, 0]], expected: { untrusted: [1, 2] } },
|
|
176
|
-
{ args: [{ untrusted: [0, 2] }, [1, 1]], expected: { untrusted: [0, 0, 2, 2] } },
|
|
177
|
-
{ args: [{ untrusted: [0, 2] }, [2, 2]], expected: { untrusted: [0, 1] } },
|
|
178
|
-
|
|
179
|
-
];
|
|
180
|
-
|
|
181
|
-
for (const test of tests) {
|
|
182
|
-
const { args, expected } = test;
|
|
183
|
-
const [tags, exclusion] = args;
|
|
184
|
-
const tagRange = tags.untrusted;
|
|
185
|
-
|
|
186
|
-
it(`should return ${expected} for ${tagRange} and ${exclusion}`, function() {
|
|
187
|
-
const result = utils.createTagsWithExclusion(tags, exclusion);
|
|
188
|
-
expect(result).to.deep.equal(expected);
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
});
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const sinon = require('sinon');
|
|
5
|
-
const { inspect } = require('util');
|
|
6
|
-
const mocks = require('@contrast/test/mocks');
|
|
7
|
-
const patcher = require('@contrast/patcher');
|
|
8
|
-
const distringuish = require('@contrast/distringuish');
|
|
9
|
-
|
|
10
|
-
describe('assess dataflow tracker', function () {
|
|
11
|
-
let core, tracker;
|
|
12
|
-
|
|
13
|
-
beforeEach(function () {
|
|
14
|
-
core = mocks.core();
|
|
15
|
-
core.logger = mocks.logger();
|
|
16
|
-
core.depHooks = mocks.depHooks();
|
|
17
|
-
core.patcher = patcher;
|
|
18
|
-
core.assess = mocks.assess();
|
|
19
|
-
tracker = require('./tracker')(core);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('tracks strings', function () {
|
|
23
|
-
const str = 'foo';
|
|
24
|
-
const meta = {
|
|
25
|
-
source: 'query',
|
|
26
|
-
tags: {
|
|
27
|
-
userControlled: [0, 0, 2, 2],
|
|
28
|
-
urlEncoded: [[0, 2]],
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
tracker.track(str, meta);
|
|
33
|
-
|
|
34
|
-
const str2 = 'bar';
|
|
35
|
-
|
|
36
|
-
const strInfo = tracker.track(str2, {
|
|
37
|
-
parents: [meta],
|
|
38
|
-
tags: {
|
|
39
|
-
userControlled: [0, 2]
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
expect(tracker.getData(strInfo.extern)).to.deep.equal({
|
|
44
|
-
parents: [{
|
|
45
|
-
source: 'query',
|
|
46
|
-
tags: {
|
|
47
|
-
userControlled: [0, 0, 2, 2],
|
|
48
|
-
urlEncoded: [[0, 2]],
|
|
49
|
-
},
|
|
50
|
-
value: 'foo',
|
|
51
|
-
}],
|
|
52
|
-
tags: {
|
|
53
|
-
userControlled: [0, 2]
|
|
54
|
-
},
|
|
55
|
-
value: 'bar',
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('logs an error when the first argument is falsey', function () {
|
|
60
|
-
const result = tracker.track(null, { test: 'meta' });
|
|
61
|
-
|
|
62
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value: null }, 'tracker.track called with invalid argument: value is falsy');
|
|
63
|
-
expect(result).to.deep.equal({ extern: null });
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('logs an error when the second argument is falsey', function () {
|
|
67
|
-
const result = tracker.track('testString', null);
|
|
68
|
-
|
|
69
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, metadata: null }, 'tracker.track called with invalid argument: metadata is falsy');
|
|
70
|
-
expect(result).to.deep.equal({ extern: null });
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('logs an error when the metadata is not validated through the factory function for it', function () {
|
|
74
|
-
core.assess.eventFactory.createdEvents.has = sinon.stub().returns(false);
|
|
75
|
-
const meta = { test: 'meta' };
|
|
76
|
-
const result = tracker.track('testString', meta);
|
|
77
|
-
|
|
78
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, metadata: meta }, 'tracker.track called without validated metadata');
|
|
79
|
-
expect(result).to.deep.equal({ extern: null });
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('logs an error when the string is already tracked', function () {
|
|
83
|
-
const str = 'test';
|
|
84
|
-
const meta = { test: 'meta' };
|
|
85
|
-
const newMeta = { test: 'new meta' };
|
|
86
|
-
|
|
87
|
-
const trackedStr = tracker.track(str, meta).extern;
|
|
88
|
-
const result = tracker.track(trackedStr, newMeta);
|
|
89
|
-
|
|
90
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value: str }, 'tracker.track called with a string value that is already tracked');
|
|
91
|
-
expect(result).to.deep.equal({ extern: null });
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
[
|
|
95
|
-
{ prop: 'val' },
|
|
96
|
-
[1, 'two']
|
|
97
|
-
].forEach((obj) => {
|
|
98
|
-
it(`tracks objects ${inspect(obj)}`, function () {
|
|
99
|
-
const metadata = { foo: 'bar' };
|
|
100
|
-
tracker.track(obj, metadata);
|
|
101
|
-
expect(tracker.getData(obj)).to.deep.equal(metadata);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('returns null for getData() if the object is not tracked', function () {
|
|
106
|
-
const obj = new String('foo');
|
|
107
|
-
|
|
108
|
-
const result = tracker.getData(obj);
|
|
109
|
-
|
|
110
|
-
expect(result).to.equal(null);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('returns the metadata of on object that already have been tracked', function () {
|
|
114
|
-
const metadata = { foo: 'bar' };
|
|
115
|
-
const obj = new String('foo');
|
|
116
|
-
|
|
117
|
-
const returnedMetadata = tracker.track(obj, metadata);
|
|
118
|
-
|
|
119
|
-
expect(tracker.track(obj, metadata)).to.equal(returnedMetadata);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('logs an error when the value is not trackable', function () {
|
|
123
|
-
const metadata = { foo: 'bar' };
|
|
124
|
-
const value = 123;
|
|
125
|
-
|
|
126
|
-
const result = tracker.track(value, metadata);
|
|
127
|
-
|
|
128
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value }, 'tracker.track called with a value type that is not trackable');
|
|
129
|
-
expect(result).to.be.null;
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('untracks strings', function () {
|
|
133
|
-
const str = 'foo';
|
|
134
|
-
const meta = {
|
|
135
|
-
source: 'query',
|
|
136
|
-
tags: {
|
|
137
|
-
userControlled: [0, 2],
|
|
138
|
-
urlEncoded: [[0, 2]],
|
|
139
|
-
},
|
|
140
|
-
history: [{ some: 'history' }],
|
|
141
|
-
resultTracked: true,
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const trackedStr = tracker.track(str, meta).extern;
|
|
145
|
-
tracker.untrack(trackedStr);
|
|
146
|
-
|
|
147
|
-
expect(tracker.getData(trackedStr)).to.be.null;
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('untracks objects', function () {
|
|
151
|
-
const obj = new String('foo');
|
|
152
|
-
const meta = {
|
|
153
|
-
source: 'query',
|
|
154
|
-
tags: {
|
|
155
|
-
userControlled: [0, 2],
|
|
156
|
-
urlEncoded: [[0, 2]],
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
tracker.track(obj, meta);
|
|
161
|
-
tracker.untrack(obj);
|
|
162
|
-
|
|
163
|
-
expect(tracker.getData(obj)).to.be.null;
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('returns null if untrack() argument is not string or object)', function () {
|
|
167
|
-
expect(tracker.untrack(1)).to.be.null;
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe('error checks with mocked `externalize` method', function () {
|
|
171
|
-
const originalExternalize = distringuish.externalize;
|
|
172
|
-
|
|
173
|
-
beforeEach(function () {
|
|
174
|
-
distringuish.externalize = sinon.stub().callsFake((...a) => Number(a[0]));
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
afterEach(function () {
|
|
178
|
-
distringuish.externalize = originalExternalize;
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('error for zero-length string', function () {
|
|
182
|
-
const result = tracker.track('1', {});
|
|
183
|
-
|
|
184
|
-
expect(result).to.deep.equal({ extern: null });
|
|
185
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value: '1' }, 'tracker.track was unable to externalize because zero-length string was passed');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('error for non-two-byte-encoded string', function () {
|
|
189
|
-
const result = tracker.track('2', {});
|
|
190
|
-
|
|
191
|
-
expect(result).to.deep.equal({ extern: null });
|
|
192
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value: '2' }, 'tracker.track was unable to externalize because non-two-byte encoded string was passed');
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('error for unsucessful conversion', function () {
|
|
196
|
-
const result = tracker.track('3', {});
|
|
197
|
-
|
|
198
|
-
expect(result).to.deep.equal({ extern: null });
|
|
199
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value: '3' }, 'tracker.track was unable to externalize because distringuish was unable to convert a MaybeLocal to Local');
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('error for isExternal returning false', function () {
|
|
203
|
-
const result = tracker.track('4', {});
|
|
204
|
-
|
|
205
|
-
expect(result).to.deep.equal({ extern: null });
|
|
206
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value: '4' }, 'tracker.track was unable to externalize because distinguish\'s isExternal call returned false');
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('error for unknown', function () {
|
|
210
|
-
const result = tracker.track('5', {});
|
|
211
|
-
|
|
212
|
-
expect(result).to.deep.equal({ extern: null });
|
|
213
|
-
expect(core.logger.error).to.have.been.calledOnceWith({ err: sinon.match.any, value: '5' }, 'tracker.track was unable to externalize because unknown error while trying to externalize the string was encountered');
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { isSafeContentType, SAFE_XSS_CONTENT_TYPES } = require('./is-safe-content-type');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
|
|
6
|
-
describe('assess dataflow utils isSafeContentType', function() {
|
|
7
|
-
SAFE_XSS_CONTENT_TYPES.forEach(type => {
|
|
8
|
-
it(`should returns true for when content type is ${type}`, function() {
|
|
9
|
-
expect(isSafeContentType(type)).to.be.true;
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it('should return false when content type is not part of the safe types', function() {
|
|
14
|
-
expect(isSafeContentType('something')).to.be.false;
|
|
15
|
-
});
|
|
16
|
-
});
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { isVulnerable } = require('./is-vulnerable');
|
|
5
|
-
|
|
6
|
-
describe('assess dataflow utils isVulnerable', function() {
|
|
7
|
-
[
|
|
8
|
-
{
|
|
9
|
-
args: [
|
|
10
|
-
'untrusted',
|
|
11
|
-
['ant'],
|
|
12
|
-
{
|
|
13
|
-
untrusted: [5, 10, 100, 102],
|
|
14
|
-
ant: [4, 104],
|
|
15
|
-
},
|
|
16
|
-
],
|
|
17
|
-
desc: 'encompasses all',
|
|
18
|
-
expected: false,
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
args: [
|
|
22
|
-
'untrusted',
|
|
23
|
-
['ant', 'cat'],
|
|
24
|
-
{
|
|
25
|
-
untrusted: [5, 10, 100, 102],
|
|
26
|
-
ant: [0, 0],
|
|
27
|
-
cat: [1, 1, 2, 2, 4, 8],
|
|
28
|
-
},
|
|
29
|
-
],
|
|
30
|
-
desc: 'no overlaps',
|
|
31
|
-
expected: true,
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
args: [
|
|
35
|
-
'untrusted',
|
|
36
|
-
['ant', 'cat'],
|
|
37
|
-
{
|
|
38
|
-
untrusted: [5, 10, 100, 102],
|
|
39
|
-
ant: [0, 0],
|
|
40
|
-
cat: [1, 1, 2, 2, 3, 8],
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
desc: 'no overlaps',
|
|
44
|
-
expected: true,
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
args: [
|
|
48
|
-
'untrusted',
|
|
49
|
-
['ant', 'cat'],
|
|
50
|
-
{
|
|
51
|
-
untrusted: [5, 10, 100, 102],
|
|
52
|
-
ant: [0, 0],
|
|
53
|
-
cat: [1, 5, 3, 8],
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
desc: 'no overlaps',
|
|
57
|
-
expected: true,
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
args: [
|
|
61
|
-
'untrusted',
|
|
62
|
-
['ant'],
|
|
63
|
-
{
|
|
64
|
-
untrusted: [5, 10, 100, 102],
|
|
65
|
-
ant: [4, 5],
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
desc: 'no overlaps',
|
|
69
|
-
expected: true,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
args: [
|
|
73
|
-
'untrusted',
|
|
74
|
-
['ant', 'cat', 'dog'],
|
|
75
|
-
{
|
|
76
|
-
untrusted: [8, 14],
|
|
77
|
-
ant: [4, 5, 7, 10],
|
|
78
|
-
cat: [6, 9],
|
|
79
|
-
dog: [9, 18],
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
desc: 'encompasses all',
|
|
83
|
-
expected: false,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
args: [
|
|
87
|
-
'untrusted',
|
|
88
|
-
['ant', 'cat', 'dog'],
|
|
89
|
-
{
|
|
90
|
-
ant: [4, 5, 7, 10],
|
|
91
|
-
cat: [6, 9],
|
|
92
|
-
dog: [9, 18],
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
desc: 'when no target tags found',
|
|
96
|
-
expected: false,
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
args: [
|
|
100
|
-
'untrusted',
|
|
101
|
-
['ant'],
|
|
102
|
-
{
|
|
103
|
-
untrusted: [4, 5, 7, 10],
|
|
104
|
-
ant: [4, 5, 7, 10],
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
desc: 'when there are multiple ranges but they are all covered',
|
|
108
|
-
expected: false,
|
|
109
|
-
},
|
|
110
|
-
].forEach(({ args, desc, expected }) => {
|
|
111
|
-
it(`${desc} returns ${expected}`, function() {
|
|
112
|
-
expect(isVulnerable(...args)).to.equal(expected);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|