@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,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const sinon = require('sinon');
|
|
5
|
+
const {
|
|
6
|
+
DataflowTag: { UNTRUSTED, WEAK_URL_ENCODED }
|
|
7
|
+
} = require('@contrast/common');
|
|
8
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
9
|
+
|
|
10
|
+
describe('assess dataflow propagation pugRuntime.escape', function () {
|
|
11
|
+
let core, trackString, simulateRequestScope, tracker, mockPugRuntime;
|
|
12
|
+
|
|
13
|
+
beforeEach(function () {
|
|
14
|
+
({
|
|
15
|
+
core,
|
|
16
|
+
simulateRequestScope,
|
|
17
|
+
trackString
|
|
18
|
+
} = initAssessFixture());
|
|
19
|
+
|
|
20
|
+
mockPugRuntime = {
|
|
21
|
+
escape: (str) => `mock-escape_${str}_mock-escape`
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
tracker = core.assess.dataflow.tracker;
|
|
25
|
+
core.assess.dataflow.propagation.pugRuntimeEscape.install();
|
|
26
|
+
core.depHooks.resolve.yield(mockPugRuntime);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(function () {
|
|
30
|
+
sinon.resetHistory();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('propagates correctly', function () {
|
|
34
|
+
simulateRequestScope(function () {
|
|
35
|
+
const notTrackedValue = 'foo';
|
|
36
|
+
const trackedValue = trackString('foo');
|
|
37
|
+
|
|
38
|
+
const notTrackedResult = mockPugRuntime.escape(notTrackedValue);
|
|
39
|
+
const notTrackedStrInfo = tracker.getData(notTrackedResult);
|
|
40
|
+
|
|
41
|
+
const trackedResult = mockPugRuntime.escape(trackedValue);
|
|
42
|
+
const trackedStrInfo = tracker.getData(trackedResult);
|
|
43
|
+
|
|
44
|
+
expect(notTrackedStrInfo).to.be.null;
|
|
45
|
+
expect(trackedStrInfo?.tags).to.deep.equal({
|
|
46
|
+
[UNTRUSTED]: [0, trackedStrInfo.value.length - 1],
|
|
47
|
+
[WEAK_URL_ENCODED]: [0, trackedStrInfo.value.length - 1]
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('will not propagate if there is no assess context', function () {
|
|
53
|
+
simulateRequestScope(function () {
|
|
54
|
+
const value = trackString('foo');
|
|
55
|
+
const result = mockPugRuntime.escape(value);
|
|
56
|
+
expect(tracker.getData(result)).to.be.null;
|
|
57
|
+
}, {});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('will not propagate if there instrumentation is locked', function () {
|
|
61
|
+
simulateRequestScope(function () {
|
|
62
|
+
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
63
|
+
const value = trackString('foo');
|
|
64
|
+
const result = mockPugRuntime.escape(value);
|
|
65
|
+
expect(tracker.getData(result)).to.be.null;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { DataflowTag: { URL_ENCODED, UNTRUSTED } } = require('@contrast/common');
|
|
5
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
+
|
|
7
|
+
describe('assess dataflow propagation querystring escape', function () {
|
|
8
|
+
let core, simulateRequestScope, tracker, trackString, querystring;
|
|
9
|
+
|
|
10
|
+
const baseEvent = {
|
|
11
|
+
moduleName: 'querystring',
|
|
12
|
+
methodName: 'escape',
|
|
13
|
+
object: { tracked: false, value: 'querystring' },
|
|
14
|
+
source: 'P',
|
|
15
|
+
target: 'R',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
before(function () {
|
|
19
|
+
({ core, trackString, simulateRequestScope } = initAssessFixture());
|
|
20
|
+
tracker = core.assess.dataflow.tracker;
|
|
21
|
+
|
|
22
|
+
querystring = require('querystring');
|
|
23
|
+
core.depHooks.resolve.withArgs({ name: 'querystring' }).yields(querystring);
|
|
24
|
+
|
|
25
|
+
core.assess.dataflow.propagation.querystringInstrumentation.escape.install();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
after(function () {
|
|
29
|
+
core.assess.dataflow.propagation.querystringInstrumentation.escape.uninstall();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('propagates to entire result when value is escaped and modified', function () {
|
|
33
|
+
simulateRequestScope(() => {
|
|
34
|
+
const str = trackString('😺');
|
|
35
|
+
const result = querystring.escape(str);
|
|
36
|
+
const strInfo = tracker.getData(result);
|
|
37
|
+
|
|
38
|
+
expect(strInfo).to.deep.include({
|
|
39
|
+
...baseEvent,
|
|
40
|
+
tags: {
|
|
41
|
+
[UNTRUSTED]: [0, 11],
|
|
42
|
+
[URL_ENCODED]: [0, 11]
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('propagates exactly to result when value is escaped and not modified and adds URL_ENCODED tag', function () {
|
|
49
|
+
simulateRequestScope(() => {
|
|
50
|
+
const str = trackString('foo', { tags: { UNTRUSTED: [0, 1] } });
|
|
51
|
+
const result = querystring.escape(str);
|
|
52
|
+
const strInfo = tracker.getData(result);
|
|
53
|
+
|
|
54
|
+
expect(strInfo).to.deep.include({
|
|
55
|
+
...baseEvent,
|
|
56
|
+
tags: {
|
|
57
|
+
[UNTRUSTED]: [0, 1],
|
|
58
|
+
[URL_ENCODED]: [0, 2]
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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 querystring', function () {
|
|
8
|
+
let core, instr;
|
|
9
|
+
|
|
10
|
+
beforeEach(function () {
|
|
11
|
+
({ core } = initAssessFixture());
|
|
12
|
+
instr = core.assess.dataflow.propagation.querystringInstrumentation;
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const propagatorList = [
|
|
16
|
+
'parse'
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
it('composes different installers', function () {
|
|
20
|
+
propagatorList.forEach((name) => {
|
|
21
|
+
expect(instr[name]).to.have.property('install').and.be.a('function');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('dispatches installation to sub-components', function () {
|
|
26
|
+
const installs = [];
|
|
27
|
+
propagatorList.forEach((name) => {
|
|
28
|
+
const instr = core.assess.dataflow.propagation.querystringInstrumentation;
|
|
29
|
+
installs.push(sinon.stub(instr[name], 'install'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
instr.install();
|
|
33
|
+
|
|
34
|
+
expect(installs).to.have.lengthOf(1);
|
|
35
|
+
installs.forEach((installer) => {
|
|
36
|
+
expect(installer).to.have.been.called;
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const sinon = require('sinon');
|
|
4
|
+
const { expect } = require('chai');
|
|
5
|
+
const {
|
|
6
|
+
DataflowTag: { URL_ENCODED }
|
|
7
|
+
} = require('@contrast/common');
|
|
8
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
9
|
+
|
|
10
|
+
describe('assess dataflow propagation querystring parse', function () {
|
|
11
|
+
let core, trackString, simulateRequestScope, tracker, querystring;
|
|
12
|
+
|
|
13
|
+
beforeEach(function () {
|
|
14
|
+
({
|
|
15
|
+
core,
|
|
16
|
+
simulateRequestScope,
|
|
17
|
+
trackString
|
|
18
|
+
} = initAssessFixture());
|
|
19
|
+
|
|
20
|
+
tracker = core.assess.dataflow.tracker;
|
|
21
|
+
querystring = require('querystring');
|
|
22
|
+
core.assess.dataflow.propagation.querystringInstrumentation.parse.install();
|
|
23
|
+
core.assess.dataflow.propagation.stringInstrumentation.concat.install();
|
|
24
|
+
core.depHooks.resolve.withArgs({ name: 'querystring' }).yield(querystring);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(function () {
|
|
28
|
+
sinon.resetHistory();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
['parse', 'decode'].forEach((method) => {
|
|
32
|
+
it('should do nothing on empty input', function () {
|
|
33
|
+
simulateRequestScope(() => {
|
|
34
|
+
const ret = querystring[method]('');
|
|
35
|
+
expect(ret).to.deep.equal({});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should do nothing if input isn\'t tracked', function () {
|
|
40
|
+
simulateRequestScope(() => {
|
|
41
|
+
const ret = querystring[method]('x=abcd&y=bcde&z=&w=cdef');
|
|
42
|
+
expect(ret).to.deep.equal({
|
|
43
|
+
x: 'abcd', y: 'bcde', z: '', w: 'cdef'
|
|
44
|
+
});
|
|
45
|
+
Object.values(ret).forEach((val) => {
|
|
46
|
+
expect(tracker.getData(val)).to.be.null;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should not track tracked input that is parsed out', function () {
|
|
52
|
+
simulateRequestScope(() => {
|
|
53
|
+
const extern = trackString('x=abcd&y=bcde', {
|
|
54
|
+
tags: {
|
|
55
|
+
x: [0, 1],
|
|
56
|
+
ampersand: [6, 6],
|
|
57
|
+
y: [7, 8]
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const ret = querystring[method](extern);
|
|
61
|
+
expect(ret).to.deep.equal({
|
|
62
|
+
x: 'abcd', y: 'bcde'
|
|
63
|
+
});
|
|
64
|
+
expect(tracker.getData(ret.x)).to.be.null;
|
|
65
|
+
expect(tracker.getData(ret.y)).to.be.null;
|
|
66
|
+
Object.keys(ret).forEach((key) => {
|
|
67
|
+
expect(tracker.getData(key)).to.be.null;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should propagate tags to object values', function () {
|
|
73
|
+
simulateRequestScope(() => {
|
|
74
|
+
const extern = trackString('x=abcd&y=abcd&z=&w=cdef', {
|
|
75
|
+
tags: {
|
|
76
|
+
foo: [2, 5],
|
|
77
|
+
bar: [9, 12]
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const ret = querystring[method](extern);
|
|
81
|
+
expect(ret).to.deep.equal({
|
|
82
|
+
x: 'abcd', y: 'abcd', z: '', w: 'cdef'
|
|
83
|
+
});
|
|
84
|
+
expect(tracker.getData(ret.x).tags).to.deep.equal({
|
|
85
|
+
foo: [0, 3]
|
|
86
|
+
});
|
|
87
|
+
expect(tracker.getData(ret.y).tags).to.deep.equal({
|
|
88
|
+
bar: [0, 3]
|
|
89
|
+
});
|
|
90
|
+
expect(tracker.getData(ret.z)).to.be.null;
|
|
91
|
+
expect(tracker.getData(ret.w)).to.be.null;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should adjust tags to account for percent decoding', function () {
|
|
96
|
+
simulateRequestScope(() => {
|
|
97
|
+
const extern = trackString('x=%E2%9C%93%F0%9F%98%90%F0%9F%99%89&y=%2F%3F%23&z=&w=cdef', {
|
|
98
|
+
tags: {
|
|
99
|
+
foo: [2, 34],
|
|
100
|
+
bar: [38, 46]
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
const ret = querystring[method](extern);
|
|
104
|
+
expect(ret).to.deep.equal({
|
|
105
|
+
x: '✓😐🙉', y: '/?#', z: '', w: 'cdef'
|
|
106
|
+
});
|
|
107
|
+
expect(tracker.getData(ret.x).tags).to.deep.equal({
|
|
108
|
+
foo: [0, 4]
|
|
109
|
+
});
|
|
110
|
+
expect(tracker.getData(ret.y).tags).to.deep.equal({
|
|
111
|
+
bar: [0, 2]
|
|
112
|
+
});
|
|
113
|
+
expect(tracker.getData(ret.z)).to.be.null;
|
|
114
|
+
expect(tracker.getData(ret.w)).to.be.null;
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should strip url-encoded tags', function () {
|
|
119
|
+
simulateRequestScope(() => {
|
|
120
|
+
const extern = trackString('x=abcd&y=bcde&z=&w=cdef', {
|
|
121
|
+
tags: {
|
|
122
|
+
[URL_ENCODED]: [2, 5],
|
|
123
|
+
foo: [2, 5]
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
const ret = querystring[method](extern);
|
|
127
|
+
expect(ret).to.deep.equal({
|
|
128
|
+
x: 'abcd', y: 'bcde', z: '', w: 'cdef'
|
|
129
|
+
});
|
|
130
|
+
expect(tracker.getData(ret.x).tags).to.deep.equal({
|
|
131
|
+
foo: [0, 3]
|
|
132
|
+
});
|
|
133
|
+
expect(tracker.getData(ret.x).removedTags).to.deep.equal([URL_ENCODED]);
|
|
134
|
+
expect(tracker.getData(ret.y)).to.be.null;
|
|
135
|
+
expect(tracker.getData(ret.z)).to.be.null;
|
|
136
|
+
expect(tracker.getData(ret.w)).to.be.null;
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should track if custom decode function is passed (querystring.unescape)', function () {
|
|
141
|
+
simulateRequestScope(() => {
|
|
142
|
+
const extern = trackString('x=abcd&y=bcde&z=&w=cdef', {
|
|
143
|
+
tags: {
|
|
144
|
+
foo: [2, 5],
|
|
145
|
+
bar: [9, 12]
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
const ret = querystring[method](extern, null, null, { decodeURIComponent: querystring.unescape });
|
|
149
|
+
expect(ret).to.deep.equal({
|
|
150
|
+
x: 'abcd', y: 'bcde', z: '', w: 'cdef'
|
|
151
|
+
});
|
|
152
|
+
expect(tracker.getData(ret.x).tags).to.deep.equal({
|
|
153
|
+
foo: [0, 3]
|
|
154
|
+
});
|
|
155
|
+
expect(tracker.getData(ret.y).tags).to.deep.equal({
|
|
156
|
+
bar: [0, 3]
|
|
157
|
+
});
|
|
158
|
+
expect(tracker.getData(ret.z)).to.be.null;
|
|
159
|
+
expect(tracker.getData(ret.w)).to.be.null;
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('should track if custom decode function is passed (custom)', function () {
|
|
164
|
+
simulateRequestScope(() => {
|
|
165
|
+
const extern = trackString('x=abcd&y=bcde&z=&w=cdef', {
|
|
166
|
+
tags: {
|
|
167
|
+
foo: [2, 5],
|
|
168
|
+
bar: [9, 12]
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
const ret = querystring[method](extern, null, null, {
|
|
172
|
+
decodeURIComponent(part) {
|
|
173
|
+
return part.concat('_');
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
expect(ret).to.deep.equal({
|
|
177
|
+
x_: 'abcd_', y_: 'bcde_', z_: '', w_: 'cdef_'
|
|
178
|
+
});
|
|
179
|
+
expect(tracker.getData(ret.x_).tags).to.deep.equal({
|
|
180
|
+
foo: [0, 3]
|
|
181
|
+
});
|
|
182
|
+
expect(tracker.getData(ret.y_).tags).to.deep.equal({
|
|
183
|
+
bar: [0, 3]
|
|
184
|
+
});
|
|
185
|
+
expect(tracker.getData(ret.z_)).to.be.null;
|
|
186
|
+
expect(tracker.getData(ret.w_)).to.be.null;
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should track if custom decode function is passed (tracked string in decode)', function () {
|
|
191
|
+
simulateRequestScope(() => {
|
|
192
|
+
const extern = trackString('x=abcd&y=bcde&z=&w=cdef', {
|
|
193
|
+
tags: {
|
|
194
|
+
foo: [2, 5],
|
|
195
|
+
bar: [9, 12]
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
const concatStr = trackString('__', {
|
|
199
|
+
tags: {
|
|
200
|
+
concat: [1, 1]
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
const ret = querystring[method](extern, null, null, {
|
|
204
|
+
decodeURIComponent(part) {
|
|
205
|
+
return part.concat(concatStr);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
expect(ret).to.deep.equal({
|
|
209
|
+
x__: 'abcd__', y__: 'bcde__', z__: '', w__: 'cdef__'
|
|
210
|
+
});
|
|
211
|
+
expect(tracker.getData(ret.x__).tags).to.deep.equal({
|
|
212
|
+
foo: [0, 3],
|
|
213
|
+
concat: [5, 5]
|
|
214
|
+
});
|
|
215
|
+
expect(tracker.getData(ret.y__).tags).to.deep.equal({
|
|
216
|
+
bar: [0, 3],
|
|
217
|
+
concat: [5, 5]
|
|
218
|
+
});
|
|
219
|
+
expect(tracker.getData(ret.z__)).to.be.null;
|
|
220
|
+
expect(tracker.getData(ret.w__).tags).to.deep.equal({
|
|
221
|
+
concat: [5, 5]
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('should properly handle custom separators', function () {
|
|
227
|
+
simulateRequestScope(() => {
|
|
228
|
+
const extern = trackString('x=abcd...y=bcde...z=...w=cdef', {
|
|
229
|
+
tags: {
|
|
230
|
+
foo: [2, 5],
|
|
231
|
+
bar: [11, 14]
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
const ret = querystring[method](extern, '...');
|
|
235
|
+
expect(ret).to.deep.equal({
|
|
236
|
+
x: 'abcd', y: 'bcde', z: '', w: 'cdef'
|
|
237
|
+
});
|
|
238
|
+
expect(tracker.getData(ret.x).tags).to.deep.equal({
|
|
239
|
+
foo: [0, 3]
|
|
240
|
+
});
|
|
241
|
+
expect(tracker.getData(ret.y).tags).to.deep.equal({
|
|
242
|
+
bar: [0, 3]
|
|
243
|
+
});
|
|
244
|
+
expect(tracker.getData(ret.z)).to.be.null;
|
|
245
|
+
expect(tracker.getData(ret.w)).to.be.null;
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('should handle arrays', function () {
|
|
250
|
+
simulateRequestScope(() => {
|
|
251
|
+
const extern = trackString('x=123&x=4567&z=foo', {
|
|
252
|
+
tags: {
|
|
253
|
+
untrusted: [0, 24],
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
const ret = querystring[method](extern);
|
|
257
|
+
expect(ret).to.deep.equal({
|
|
258
|
+
x: ['123', '4567'], z: 'foo'
|
|
259
|
+
});
|
|
260
|
+
expect(tracker.getData(ret.x[0]).tags).to.deep.equal({
|
|
261
|
+
untrusted: [0, 2]
|
|
262
|
+
});
|
|
263
|
+
expect(tracker.getData(ret.x[1]).tags).to.deep.equal({
|
|
264
|
+
untrusted: [0, 3]
|
|
265
|
+
});
|
|
266
|
+
expect(tracker.getData(ret.z).tags).to.deep.equal({
|
|
267
|
+
untrusted: [0, 2]
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
});
|