@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,62 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
DataflowTag: { UNTRUSTED, HTML_ENCODED }
|
|
5
|
-
} = require('@contrast/common');
|
|
6
|
-
const sinon = require('sinon');
|
|
7
|
-
const { expect } = require('chai');
|
|
8
|
-
const mustache = require('mustache');
|
|
9
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
-
|
|
11
|
-
describe('assess dataflow propagation mustache.escape', function () {
|
|
12
|
-
let core, trackString, simulateRequestScope, tracker;
|
|
13
|
-
|
|
14
|
-
beforeEach(function () {
|
|
15
|
-
({
|
|
16
|
-
core,
|
|
17
|
-
simulateRequestScope,
|
|
18
|
-
trackString
|
|
19
|
-
} = initAssessFixture());
|
|
20
|
-
|
|
21
|
-
tracker = core.assess.dataflow.tracker;
|
|
22
|
-
core.assess.dataflow.propagation.mustacheEscape.install();
|
|
23
|
-
core.depHooks.resolve.yield(mustache);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(function () {
|
|
27
|
-
sinon.resetHistory();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('will not propagate if there is no assess policy in request context', function () {
|
|
31
|
-
simulateRequestScope(function () {
|
|
32
|
-
const value = trackString('<script>alert("hello");</script>');
|
|
33
|
-
const result = mustache.escape(value);
|
|
34
|
-
expect(tracker.getData(result)).to.be.null;
|
|
35
|
-
}, { assess: { policy: null } });
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('will not propagate if there instrumentation is locked', function () {
|
|
39
|
-
simulateRequestScope(function () {
|
|
40
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
41
|
-
const value = trackString('<script>alert("hello");</script>');
|
|
42
|
-
const result = mustache.escape(value);
|
|
43
|
-
expect(tracker.getData(result)).to.be.null;
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('propagates correctly', function () {
|
|
49
|
-
simulateRequestScope(function () {
|
|
50
|
-
const value = trackString('<script>alert("hello");</script>');
|
|
51
|
-
const result = mustache.escape(value);
|
|
52
|
-
|
|
53
|
-
const strInfo = tracker.getData(result);
|
|
54
|
-
expect(result).to.be.equal('<script>alert("hello");</script>');
|
|
55
|
-
|
|
56
|
-
expect(strInfo?.tags).to.deep.equal({
|
|
57
|
-
[UNTRUSTED]: [4, 9, 14, 19, 26, 30, 37, 38, 49, 54],
|
|
58
|
-
[HTML_ENCODED]: [0, 58]
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const {
|
|
5
|
-
DataflowTag: {
|
|
6
|
-
UNTRUSTED,
|
|
7
|
-
SQL_ENCODED,
|
|
8
|
-
}
|
|
9
|
-
} = require('@contrast/common');
|
|
10
|
-
const sinon = require('sinon');
|
|
11
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
12
|
-
|
|
13
|
-
describe('assess dataflow propagation mysql.connection.escape', function () {
|
|
14
|
-
let core, trackString, simulateRequestScope, tracker, mockConnection;
|
|
15
|
-
|
|
16
|
-
beforeEach(function () {
|
|
17
|
-
({
|
|
18
|
-
core,
|
|
19
|
-
simulateRequestScope,
|
|
20
|
-
trackString
|
|
21
|
-
} = initAssessFixture());
|
|
22
|
-
|
|
23
|
-
mockConnection = function () { };
|
|
24
|
-
|
|
25
|
-
mockConnection.prototype.escape = (str) => `mock-escape_${str}_mock-escape`;
|
|
26
|
-
tracker = core.assess.dataflow.tracker;
|
|
27
|
-
core.assess.dataflow.propagation.mysqlEscape.install();
|
|
28
|
-
core.depHooks.resolve.withArgs(sinon.match({ name: 'mysql', file: 'lib/Connection.js' })).yield(mockConnection);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
afterEach(function () {
|
|
32
|
-
sinon.resetHistory();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('propagates correctly', function () {
|
|
36
|
-
simulateRequestScope(function () {
|
|
37
|
-
const notTrackedValue = 'foo';
|
|
38
|
-
const trackedValue = trackString('foo', { tags: { [UNTRUSTED]: [0, 2] } });
|
|
39
|
-
const connection = new mockConnection();
|
|
40
|
-
|
|
41
|
-
const notTrackedResult = connection.escape(notTrackedValue);
|
|
42
|
-
const notTrackedStrInfo = tracker.getData(notTrackedResult);
|
|
43
|
-
|
|
44
|
-
const trackedResult = connection.escape(trackedValue);
|
|
45
|
-
const trackedStrInfo = tracker.getData(trackedResult);
|
|
46
|
-
|
|
47
|
-
expect(notTrackedStrInfo).to.be.null;
|
|
48
|
-
expect(trackedStrInfo?.tags).to.deep.equal({
|
|
49
|
-
[UNTRUSTED]: [0, trackedStrInfo?.value.length - 1],
|
|
50
|
-
[SQL_ENCODED]: [0, trackedStrInfo?.value.length - 1]
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('will not propagate if there is no assess policy in request context', function () {
|
|
56
|
-
simulateRequestScope(function () {
|
|
57
|
-
const value = trackString('foo');
|
|
58
|
-
const connection = new mockConnection();
|
|
59
|
-
const result = connection.escape(value);
|
|
60
|
-
expect(tracker.getData(result)).to.be.null;
|
|
61
|
-
}, { assess: { policy: null } });
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('will not propagate if there instrumentation is locked', function () {
|
|
65
|
-
simulateRequestScope(function () {
|
|
66
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
67
|
-
const value = trackString('foo');
|
|
68
|
-
const connection = new mockConnection();
|
|
69
|
-
const result = connection.escape(value);
|
|
70
|
-
expect(tracker.getData(result)).to.be.null;
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
5
|
-
|
|
6
|
-
describe('assess dataflow propagation parseInt', function () {
|
|
7
|
-
let core, simulateRequestScope, trackString, tracker;
|
|
8
|
-
|
|
9
|
-
beforeEach(function () {
|
|
10
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
11
|
-
tracker = core.assess.dataflow.tracker;
|
|
12
|
-
core.assess.dataflow.propagation.parseIntInstrumentation.install();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
afterEach(function () {
|
|
16
|
-
core.assess.dataflow.propagation.parseIntInstrumentation.uninstall();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('will not sanitize if Number coercion fails', function () {
|
|
20
|
-
simulateRequestScope(() => {
|
|
21
|
-
const str = trackString('foo');
|
|
22
|
-
global.parseInt(str);
|
|
23
|
-
expect(tracker.getData(str)).to.deep.include({
|
|
24
|
-
context: 'UNKNOWN.val',
|
|
25
|
-
name: 'assess-dataflow-fixture',
|
|
26
|
-
fieldName: 'val',
|
|
27
|
-
pathName: 'val',
|
|
28
|
-
stack: [],
|
|
29
|
-
inputType: 'UNKNOWN',
|
|
30
|
-
tags: { UNTRUSTED: [0, 2] },
|
|
31
|
-
result: { tracked: true, value: 'foo' },
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('will untrack if Number coercion succeeds', function () {
|
|
37
|
-
simulateRequestScope(() => {
|
|
38
|
-
const str = trackString('30000');
|
|
39
|
-
global.parseInt(str);
|
|
40
|
-
expect(tracker.getData(str)).to.be.null;
|
|
41
|
-
expect(core.logger.trace).to.have.been.calledWithMatch({
|
|
42
|
-
funcKey: 'assess-dataflow-propagator:global.parseInt',
|
|
43
|
-
sanitizer: 'global.parseInt',
|
|
44
|
-
value: '30000',
|
|
45
|
-
}, 'untracked a string value');
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
DataflowTag: { UNTRUSTED, STRING_TYPE_CHECKED, CUSTOM_ENCODED },
|
|
5
|
-
} = require('@contrast/common');
|
|
6
|
-
const { expect } = require('chai');
|
|
7
|
-
const sinon = require('sinon');
|
|
8
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
9
|
-
|
|
10
|
-
describe('assess dataflow propagation path basename', function () {
|
|
11
|
-
let core, tracker, createPropagationEvent, trackString, simulateRequestScope;
|
|
12
|
-
|
|
13
|
-
beforeEach(function () {
|
|
14
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
15
|
-
tracker = core.assess.dataflow.tracker;
|
|
16
|
-
createPropagationEvent = sinon.spy(
|
|
17
|
-
core.assess.eventFactory,
|
|
18
|
-
'createPropagationEvent'
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
['posix', 'win32'].forEach((os) => {
|
|
23
|
-
describe(os, function () {
|
|
24
|
-
let path;
|
|
25
|
-
|
|
26
|
-
beforeEach(function () {
|
|
27
|
-
path = require('path')[os];
|
|
28
|
-
|
|
29
|
-
core.depHooks.resolve.yields(path);
|
|
30
|
-
const basenameInstr = require('./basename')(core);
|
|
31
|
-
basenameInstr.install();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should ignore empty or non-string values', function () {
|
|
35
|
-
simulateRequestScope(function () {
|
|
36
|
-
const myPath = trackString('');
|
|
37
|
-
|
|
38
|
-
const file = path.basename(myPath);
|
|
39
|
-
const strInfo = tracker.getData(file);
|
|
40
|
-
|
|
41
|
-
expect(strInfo).to.be.null;
|
|
42
|
-
expect(() => path.basename(1)).to.throw();
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('will not propagate if there is no assess policy in request context', function () {
|
|
48
|
-
simulateRequestScope(function () {
|
|
49
|
-
const myPath = trackString('/script.sh');
|
|
50
|
-
const result = path.basename(myPath);
|
|
51
|
-
|
|
52
|
-
expect(tracker.getData(result)).to.be.null;
|
|
53
|
-
}, { assess: { policy: null } });
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('will not propagate if there instrumentation is locked', function () {
|
|
57
|
-
simulateRequestScope(function () {
|
|
58
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
59
|
-
const myPath = trackString('/script.sh');
|
|
60
|
-
const result = path.basename(myPath);
|
|
61
|
-
|
|
62
|
-
expect(tracker.getData(result)).to.be.null;
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('will not propagate if the argument is not tracked', function () {
|
|
68
|
-
simulateRequestScope(function () {
|
|
69
|
-
const myPath = '/script.sh';
|
|
70
|
-
const trackedExtension = trackString('.sh');
|
|
71
|
-
|
|
72
|
-
path.basename(myPath);
|
|
73
|
-
path.basename(myPath, trackedExtension);
|
|
74
|
-
|
|
75
|
-
expect(createPropagationEvent).to.not.have.been.called;
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('will not propagate if there no event created', function () {
|
|
80
|
-
simulateRequestScope(function () {
|
|
81
|
-
core.config.assess.max_propagation_events = 0;
|
|
82
|
-
|
|
83
|
-
const myPath = trackString('/script.sh');
|
|
84
|
-
const result = path.basename(myPath);
|
|
85
|
-
|
|
86
|
-
expect(tracker.getData(result)).to.be.null;
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should track entire path if entire string was tracked before normalizing', function () {
|
|
91
|
-
simulateRequestScope(function () {
|
|
92
|
-
const myPath = trackString('/some/other/file.exe/../../path/file.txt');
|
|
93
|
-
|
|
94
|
-
const basename = path.basename(myPath, '.exe');
|
|
95
|
-
const strInfo = tracker.getData(basename);
|
|
96
|
-
expect(strInfo.tags).to.deep.equal({
|
|
97
|
-
[UNTRUSTED]: [0, 3, 5, 7],
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should account for the extension properly', function () {
|
|
103
|
-
simulateRequestScope(function () {
|
|
104
|
-
const myPath = trackString('/some/path/file.txt', {
|
|
105
|
-
tags: {
|
|
106
|
-
[UNTRUSTED]: [0, 18],
|
|
107
|
-
[CUSTOM_ENCODED]: [13, 17],
|
|
108
|
-
[STRING_TYPE_CHECKED]: [5, 10],
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const basename = path.basename(myPath, '.txt');
|
|
113
|
-
const strInfo = tracker.getData(basename);
|
|
114
|
-
|
|
115
|
-
expect(strInfo.tags).to.deep.equal({
|
|
116
|
-
[UNTRUSTED]: [0, 3],
|
|
117
|
-
[CUSTOM_ENCODED]: [2, 3],
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should account for the extension properly when it is repeated in the path', function () {
|
|
123
|
-
simulateRequestScope(function () {
|
|
124
|
-
const myPath = trackString('/some/path/file.txt/../../other/txt/file/../../path/to/file.txt.txt', {
|
|
125
|
-
tags: {
|
|
126
|
-
[UNTRUSTED]: [0, 66],
|
|
127
|
-
[CUSTOM_ENCODED]: [57, 62],
|
|
128
|
-
[STRING_TYPE_CHECKED]: [5, 45],
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
const basename = path.basename(myPath, '.txt');
|
|
133
|
-
const strInfo = tracker.getData(basename);
|
|
134
|
-
|
|
135
|
-
expect(strInfo.tags).to.deep.equal({
|
|
136
|
-
[UNTRUSTED]: [0, 3, 5, 7],
|
|
137
|
-
[CUSTOM_ENCODED]: [2, 3, 5, 7],
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const sinon = require('sinon');
|
|
4
|
-
const { expect } = require('chai');
|
|
5
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
-
const { DataflowTag: { UNTRUSTED } } = require('@contrast/common');
|
|
7
|
-
|
|
8
|
-
describe('assess dataflow propagation path dirname', function () {
|
|
9
|
-
let core, 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
|
-
core.assess.dataflow.propagation.stringInstrumentation.concat.install();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
['posix', 'win32'].forEach((os) => {
|
|
22
|
-
describe(os, function () {
|
|
23
|
-
let path;
|
|
24
|
-
|
|
25
|
-
beforeEach(function () {
|
|
26
|
-
path = require('path')[os];
|
|
27
|
-
|
|
28
|
-
core.depHooks.resolve.yields(path);
|
|
29
|
-
const dirnameInstr = require('./dirname')(core);
|
|
30
|
-
dirnameInstr.install();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should ignore empty string', function () {
|
|
34
|
-
simulateRequestScope(function () {
|
|
35
|
-
const myPath = trackString('');
|
|
36
|
-
|
|
37
|
-
const result = path.dirname(myPath);
|
|
38
|
-
const strInfo = tracker.getData(result);
|
|
39
|
-
|
|
40
|
-
expect(strInfo).to.be.null;
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('will not propagate if there is no assess policy in request context', function () {
|
|
45
|
-
simulateRequestScope(function () {
|
|
46
|
-
const myPath = trackString('/path');
|
|
47
|
-
|
|
48
|
-
const result = path.dirname(myPath);
|
|
49
|
-
|
|
50
|
-
expect(tracker.getData(result)).to.be.null;
|
|
51
|
-
}, { assess: { policy: null } });
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('will not propagate if there instrumentation is locked', function () {
|
|
55
|
-
simulateRequestScope(function () {
|
|
56
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
57
|
-
const myPath = trackString('/path');
|
|
58
|
-
|
|
59
|
-
const result = path.dirname(myPath);
|
|
60
|
-
|
|
61
|
-
expect(tracker.getData(result)).to.be.null;
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('will not propagate if the argument is not tracked', function () {
|
|
67
|
-
simulateRequestScope(function () {
|
|
68
|
-
const myPath = '/path';
|
|
69
|
-
|
|
70
|
-
path.dirname(myPath);
|
|
71
|
-
|
|
72
|
-
expect(createPropagationEvent).to.not.have.been.called;
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('will not propagate if there no event created', function () {
|
|
77
|
-
simulateRequestScope(function () {
|
|
78
|
-
core.config.assess.max_propagation_events = 0;
|
|
79
|
-
const myPath = trackString('/path');
|
|
80
|
-
|
|
81
|
-
const result = path.dirname(myPath);
|
|
82
|
-
|
|
83
|
-
expect(tracker.getData(result)).to.be.null;
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should not propagate if tracked string is not in result', function() {
|
|
88
|
-
simulateRequestScope(function () {
|
|
89
|
-
const myPath = trackString('/file');
|
|
90
|
-
const result = path.dirname('/dir/path/to'.concat(myPath));
|
|
91
|
-
expect(result).to.be.equal('/dir/path/to');
|
|
92
|
-
expect(tracker.getData(result)).to.be.null;
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should propagate if entire path is tracked ', function () {
|
|
97
|
-
simulateRequestScope(function () {
|
|
98
|
-
const myPath = trackString('/dir/path/to/file');
|
|
99
|
-
|
|
100
|
-
const result = path.dirname(myPath);
|
|
101
|
-
const strInfo = tracker.getData(result);
|
|
102
|
-
|
|
103
|
-
expect(result).to.be.equal('/dir/path/to');
|
|
104
|
-
if (os === 'win32') {
|
|
105
|
-
expect(strInfo.tags).to.deep.equal({
|
|
106
|
-
[UNTRUSTED]: [1, 3, 5, 8, 10, 11],
|
|
107
|
-
});
|
|
108
|
-
} else {
|
|
109
|
-
expect(strInfo.tags).to.deep.equal({
|
|
110
|
-
[UNTRUSTED]: [0, 11],
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should propagate if partial path is tracked ', function () {
|
|
117
|
-
simulateRequestScope(function () {
|
|
118
|
-
const myPath = trackString('/path/to/file');
|
|
119
|
-
|
|
120
|
-
const result = path.dirname('/dir'.concat(myPath));
|
|
121
|
-
const strInfo = tracker.getData(result);
|
|
122
|
-
|
|
123
|
-
expect(result).to.be.equal('/dir/path/to');
|
|
124
|
-
if (os === 'win32') {
|
|
125
|
-
expect(strInfo.tags).to.deep.equal({
|
|
126
|
-
[UNTRUSTED]: [5, 8, 10, 11],
|
|
127
|
-
});
|
|
128
|
-
} else {
|
|
129
|
-
expect(strInfo.tags).to.deep.equal({
|
|
130
|
-
[UNTRUSTED]: [4, 11],
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it('should propagate multiple tag ranges ', function () {
|
|
137
|
-
simulateRequestScope(function () {
|
|
138
|
-
const myPath = trackString('/dir/path/to/file', {
|
|
139
|
-
tags: {
|
|
140
|
-
UNTRUSTED: [0, 16],
|
|
141
|
-
'FOO': [5, 8],
|
|
142
|
-
'BAR': [10, 16]
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
const result = path.dirname(myPath);
|
|
147
|
-
const strInfo = tracker.getData(result);
|
|
148
|
-
|
|
149
|
-
expect(result).to.be.equal('/dir/path/to');
|
|
150
|
-
if (os === 'win32') {
|
|
151
|
-
expect(strInfo.tags).to.deep.equal({
|
|
152
|
-
[UNTRUSTED]: [1, 3, 5, 8, 10, 11],
|
|
153
|
-
['FOO']: [5, 8],
|
|
154
|
-
['BAR']: [10, 11]
|
|
155
|
-
});
|
|
156
|
-
} else {
|
|
157
|
-
expect(strInfo.tags).to.deep.equal({
|
|
158
|
-
[UNTRUSTED]: [0, 11],
|
|
159
|
-
['FOO']: [5, 8],
|
|
160
|
-
['BAR']: [10, 11]
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
});
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { expect } = require('chai');
|
|
4
|
-
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
5
|
-
const { DataflowTag: { UNTRUSTED } } = require('@contrast/common');
|
|
6
|
-
|
|
7
|
-
describe('assess dataflow propagation path extname', function () {
|
|
8
|
-
let core, tracker, trackString, simulateRequestScope;
|
|
9
|
-
|
|
10
|
-
beforeEach(function () {
|
|
11
|
-
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
12
|
-
tracker = core.assess.dataflow.tracker;
|
|
13
|
-
core.assess.dataflow.propagation.stringInstrumentation.concat.install();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
['posix', 'win32'].forEach((os) => {
|
|
17
|
-
describe(os, function () {
|
|
18
|
-
let path;
|
|
19
|
-
|
|
20
|
-
beforeEach(function () {
|
|
21
|
-
path = require('path')[os];
|
|
22
|
-
|
|
23
|
-
core.depHooks.resolve.yields(path);
|
|
24
|
-
const extnameInstr = require('./extname')(core);
|
|
25
|
-
extnameInstr.install();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should ignore empty string', function () {
|
|
29
|
-
simulateRequestScope(function () {
|
|
30
|
-
const myPath = trackString('');
|
|
31
|
-
|
|
32
|
-
const result = path.extname(myPath);
|
|
33
|
-
const strInfo = tracker.getData(result);
|
|
34
|
-
|
|
35
|
-
expect(strInfo).to.be.null;
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('will not propagate if there is no assess policy in request context', function () {
|
|
40
|
-
simulateRequestScope(function () {
|
|
41
|
-
const myPath = trackString('/path/to/file.txt');
|
|
42
|
-
|
|
43
|
-
const result = path.extname(myPath);
|
|
44
|
-
|
|
45
|
-
expect(tracker.getData(result)).to.be.null;
|
|
46
|
-
}, { assess: { policy: null } });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('will not propagate if there instrumentation is locked', function () {
|
|
50
|
-
simulateRequestScope(function () {
|
|
51
|
-
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
52
|
-
const myPath = trackString('/path/to/file.txt');
|
|
53
|
-
|
|
54
|
-
const result = path.extname(myPath);
|
|
55
|
-
|
|
56
|
-
expect(tracker.getData(result)).to.be.null;
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('will not propagate if the argument is not tracked', function () {
|
|
62
|
-
simulateRequestScope(function () {
|
|
63
|
-
const myPath = '/path/to/file.txt';
|
|
64
|
-
|
|
65
|
-
const result = path.extname(myPath);
|
|
66
|
-
|
|
67
|
-
expect(tracker.getData(result)).to.be.null;
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('will not propagate if there no event created', function () {
|
|
72
|
-
simulateRequestScope(function () {
|
|
73
|
-
core.config.assess.max_propagation_events = 0;
|
|
74
|
-
const myPath = trackString('/path/to/file.txt');
|
|
75
|
-
|
|
76
|
-
const result = path.extname(myPath);
|
|
77
|
-
|
|
78
|
-
expect(tracker.getData(result)).to.be.null;
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should not propagate if tracked string is not in result', function() {
|
|
83
|
-
simulateRequestScope(function () {
|
|
84
|
-
const myPath = trackString('/path/to/file');
|
|
85
|
-
const result = path.extname(myPath.concat('.txt'));
|
|
86
|
-
expect(result).to.be.equal('.txt');
|
|
87
|
-
expect(tracker.getData(result)).to.be.null;
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('should propagate if entire path is tracked', function () {
|
|
92
|
-
simulateRequestScope(function () {
|
|
93
|
-
const myPath = trackString('/path/to/file.txt');
|
|
94
|
-
|
|
95
|
-
const result = path.extname(myPath);
|
|
96
|
-
const strInfo = tracker.getData(result);
|
|
97
|
-
|
|
98
|
-
expect(result).to.be.equal('.txt');
|
|
99
|
-
expect(strInfo.tags).to.deep.equal({
|
|
100
|
-
[UNTRUSTED]: [1, 3]
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should propagate if partial path is tracked ', function () {
|
|
106
|
-
simulateRequestScope(function () {
|
|
107
|
-
const myPath = trackString('file.txt');
|
|
108
|
-
|
|
109
|
-
const result = path.extname('/path/to/'.concat(myPath));
|
|
110
|
-
const strInfo = tracker.getData(result);
|
|
111
|
-
|
|
112
|
-
expect(result).to.be.equal('.txt');
|
|
113
|
-
expect(strInfo.tags).to.deep.equal({
|
|
114
|
-
[UNTRUSTED]: [1, 3],
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('should propagate multiple tag ranges ', function () {
|
|
120
|
-
simulateRequestScope(function () {
|
|
121
|
-
const myPath = trackString('/path/to/file.txt', {
|
|
122
|
-
tags: {
|
|
123
|
-
UNTRUSTED: [0, 16],
|
|
124
|
-
'FOO': [9, 12],
|
|
125
|
-
'BAR': [14, 16]
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const result = path.extname(myPath);
|
|
130
|
-
const strInfo = tracker.getData(result);
|
|
131
|
-
|
|
132
|
-
expect(result).to.be.equal('.txt');
|
|
133
|
-
expect(strInfo.tags).to.deep.equal({
|
|
134
|
-
[UNTRUSTED]: [1, 3],
|
|
135
|
-
['BAR']: [1, 3]
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|