@contrast/assess 1.30.0 → 1.32.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.js +1 -1
- 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.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.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.js +50 -44
- package/lib/session-configuration/install/koa.test.js +92 -0
- package/package.json +2 -2
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { DataflowTag } = require('@contrast/common');
|
|
5
|
+
const sinon = require('sinon');
|
|
6
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
7
|
+
|
|
8
|
+
describe('assess dataflow propagation String', function () {
|
|
9
|
+
let core, trackString, simulateRequestScope, tracker;
|
|
10
|
+
|
|
11
|
+
beforeEach(function () {
|
|
12
|
+
({
|
|
13
|
+
core,
|
|
14
|
+
simulateRequestScope,
|
|
15
|
+
trackString
|
|
16
|
+
} = initAssessFixture());
|
|
17
|
+
|
|
18
|
+
core.contrastMethods.install();
|
|
19
|
+
tracker = core.assess.dataflow.tracker;
|
|
20
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation.string.install();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(function () {
|
|
24
|
+
sinon.resetHistory();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('base cases', function () {
|
|
28
|
+
|
|
29
|
+
it('null', function () {
|
|
30
|
+
expect(global.ContrastMethods.String(null)).to.equal('null');
|
|
31
|
+
expect(global.ContrastMethods.String(undefined)).to.equal('undefined');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('number', function () {
|
|
35
|
+
expect(global.ContrastMethods.String(42)).to.equal('42');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('boolean', function () {
|
|
39
|
+
expect(global.ContrastMethods.String(false)).to.equal('false');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('Object.create(null) with no toString throws an error', function () {
|
|
43
|
+
const obj = Object.create(null);
|
|
44
|
+
expect(() => {
|
|
45
|
+
global.ContrastMethods.String(obj);
|
|
46
|
+
}).to.throw(TypeError);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('propagation', function () {
|
|
52
|
+
it('non-string does not propagate', function () {
|
|
53
|
+
simulateRequestScope(function () {
|
|
54
|
+
const extern = trackString({});
|
|
55
|
+
|
|
56
|
+
const result = global.ContrastMethods.String(extern);
|
|
57
|
+
expect(tracker.getData(result)).to.be.null;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('untracked string does not propagate', function () {
|
|
62
|
+
simulateRequestScope(function () {
|
|
63
|
+
const result = global.ContrastMethods.String('foo');
|
|
64
|
+
expect(result).to.equal('foo');
|
|
65
|
+
expect(tracker.getData(result)).to.be.null;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('tracked string propagates', function () {
|
|
70
|
+
simulateRequestScope(function () {
|
|
71
|
+
const extern = trackString('foo');
|
|
72
|
+
|
|
73
|
+
const result = global.ContrastMethods.String(extern);
|
|
74
|
+
expect(result).to.equal('foo');
|
|
75
|
+
expect(tracker.getData(result).tags).to.deep.equal({
|
|
76
|
+
[DataflowTag.UNTRUSTED]: [0, 2],
|
|
77
|
+
[DataflowTag.STRING_TYPE_CHECKED]: [0, 2]
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('toString propagates', function () {
|
|
83
|
+
simulateRequestScope(function () {
|
|
84
|
+
const extern = trackString('foo');
|
|
85
|
+
|
|
86
|
+
const result = global.ContrastMethods.String(extern).toString();
|
|
87
|
+
expect(result).to.equal('foo');
|
|
88
|
+
expect(tracker.getData(result).tags).to.deep.equal({
|
|
89
|
+
[DataflowTag.UNTRUSTED]: [0, 2],
|
|
90
|
+
[DataflowTag.STRING_TYPE_CHECKED]: [0, 2]
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('tracked string propagates copy', function () {
|
|
96
|
+
simulateRequestScope(function () {
|
|
97
|
+
const extern = trackString('foo');
|
|
98
|
+
|
|
99
|
+
const result = new global.ContrastMethods.String(extern.substring(0, extern.length)).toString();
|
|
100
|
+
expect(result).to.equal('foo');
|
|
101
|
+
expect(tracker.getData(result).tags).to.deep.equal({
|
|
102
|
+
[DataflowTag.UNTRUSTED]: [0, 2],
|
|
103
|
+
[DataflowTag.STRING_TYPE_CHECKED]: [0, 2]
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('object with a custom toString propagates', function () {
|
|
109
|
+
simulateRequestScope(function () {
|
|
110
|
+
const extern = trackString('foo');
|
|
111
|
+
const string = new String({
|
|
112
|
+
toString() {
|
|
113
|
+
return extern;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const result = global.ContrastMethods.String(string);
|
|
118
|
+
expect(result).to.equal('foo');
|
|
119
|
+
expect(tracker.getData(result).tags).to.deep.equal({
|
|
120
|
+
[DataflowTag.UNTRUSTED]: [0, 2],
|
|
121
|
+
[DataflowTag.STRING_TYPE_CHECKED]: [0, 2]
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('class with a custom toString propagates', function () {
|
|
127
|
+
simulateRequestScope(function () {
|
|
128
|
+
const extern = trackString('foo');
|
|
129
|
+
class Test {
|
|
130
|
+
constructor() {
|
|
131
|
+
this.tracked = extern;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
toString() {
|
|
135
|
+
return this.tracked;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const test = new Test();
|
|
139
|
+
const result = global.ContrastMethods.String(test);
|
|
140
|
+
expect(result).to.equal('foo');
|
|
141
|
+
expect(tracker.getData(result).tags).to.deep.equal({
|
|
142
|
+
[DataflowTag.UNTRUSTED]: [0, 2],
|
|
143
|
+
[DataflowTag.STRING_TYPE_CHECKED]: [0, 2]
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const {
|
|
5
|
+
DataflowTag: {
|
|
6
|
+
UNTRUSTED,
|
|
7
|
+
}
|
|
8
|
+
} = require('@contrast/common');
|
|
9
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
+
|
|
11
|
+
describe('assess dataflow propagation contrast-methods tag', function () {
|
|
12
|
+
let core, simulateRequestScope, trackString, tracker;
|
|
13
|
+
|
|
14
|
+
beforeEach(function () {
|
|
15
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
16
|
+
tracker = core.assess.dataflow.tracker;
|
|
17
|
+
|
|
18
|
+
// We're effectively testing that `ContrastMethods.tag` delegates
|
|
19
|
+
// propagation to `String.prototype.concat` correctly.
|
|
20
|
+
core.contrastMethods.install();
|
|
21
|
+
core.assess.dataflow.propagation.stringInstrumentation.concat.install();
|
|
22
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation.tag.install();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(function () {
|
|
26
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation.tag.uninstall();
|
|
27
|
+
core.assess.dataflow.propagation.stringInstrumentation.concat.uninstall();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const bar = () => trackString('bar');
|
|
31
|
+
const baz = () => 'baz';
|
|
32
|
+
|
|
33
|
+
[
|
|
34
|
+
{
|
|
35
|
+
name: '`foo${bar}`',
|
|
36
|
+
context: '`foo${expr0}`',
|
|
37
|
+
strings: ['foo', ''],
|
|
38
|
+
args: [bar],
|
|
39
|
+
expected: {
|
|
40
|
+
[UNTRUSTED]: [3, 5],
|
|
41
|
+
},
|
|
42
|
+
history: 1,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: '`foo${bar}boo`',
|
|
46
|
+
context: '`foo${expr0}boo`',
|
|
47
|
+
strings: ['foo', 'boo'],
|
|
48
|
+
args: [bar],
|
|
49
|
+
expected: {
|
|
50
|
+
[UNTRUSTED]: [3, 5],
|
|
51
|
+
},
|
|
52
|
+
history: 1,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: '`foo${baz}boo${bar}`',
|
|
56
|
+
context: '`foo${expr0}boo${expr1}`',
|
|
57
|
+
strings: ['foo', 'boo', ''],
|
|
58
|
+
args: [baz, bar],
|
|
59
|
+
expected: {
|
|
60
|
+
[UNTRUSTED]: [9, 11],
|
|
61
|
+
},
|
|
62
|
+
history: 1,
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: '`foo${bar}boo${bar}.`',
|
|
66
|
+
context: '`foo${expr0}boo${expr1}.`',
|
|
67
|
+
strings: ['foo', 'boo', '.'],
|
|
68
|
+
args: [bar, bar],
|
|
69
|
+
expected: {
|
|
70
|
+
[UNTRUSTED]: [3, 5, 9, 11],
|
|
71
|
+
},
|
|
72
|
+
history: 2,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: '`foo${concat}`',
|
|
76
|
+
context: '`foo${expr0}`',
|
|
77
|
+
strings: ['foo', ''],
|
|
78
|
+
args: [() => trackString('con').concat(trackString('cat'))],
|
|
79
|
+
expected: {
|
|
80
|
+
[UNTRUSTED]: [3, 8],
|
|
81
|
+
},
|
|
82
|
+
history: 1,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: '`foo${bar}boo${bar}baz{$bar}.`',
|
|
86
|
+
context: '`foo${expr0}boo${expr1}baz${expr2}.`',
|
|
87
|
+
strings: ['foo', 'boo', 'baz', '.'],
|
|
88
|
+
args: [bar, bar, bar],
|
|
89
|
+
expected: {
|
|
90
|
+
[UNTRUSTED]: [3, 5, 9, 11, 15, 17],
|
|
91
|
+
},
|
|
92
|
+
history: 3,
|
|
93
|
+
},
|
|
94
|
+
].forEach(({ name, context, strings, args, expected, history }) => {
|
|
95
|
+
it(`propagates ${name} correctly`, function () {
|
|
96
|
+
simulateRequestScope(() => {
|
|
97
|
+
const result = global.ContrastMethods.tag(
|
|
98
|
+
strings,
|
|
99
|
+
...args.map(Reflect.apply),
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const data = tracker.getData(result);
|
|
103
|
+
expect(data).to.have.property('tags').that.deep.equals(expected);
|
|
104
|
+
expect(data).to.have.property('name', 'ContrastMethods.tag');
|
|
105
|
+
expect(data).to.have.property('history').with.length(history);
|
|
106
|
+
expect(data).to.have.property('context').that.equals(context);
|
|
107
|
+
expect(data).to.have.property('moduleName').that.equals('global');
|
|
108
|
+
expect(data).to.have.property('methodName').that.equals('ContrastMethods.tag');
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
* name: '`${bar}`',
|
|
115
|
+
* strings: ['', ''],
|
|
116
|
+
* args: [bar],
|
|
117
|
+
*/
|
|
118
|
+
it('handles the `${bar}` edge case appropriately', function () {
|
|
119
|
+
simulateRequestScope(() => {
|
|
120
|
+
const result = global.ContrastMethods.tag(['', ''], trackString('bar'));
|
|
121
|
+
const data = tracker.getData(result);
|
|
122
|
+
expect(data)
|
|
123
|
+
.to.have.property('tags')
|
|
124
|
+
.that.deep.equals({ [UNTRUSTED]: [0, 2] });
|
|
125
|
+
expect(data).to.have.property('name', 'assess-dataflow-fixture');
|
|
126
|
+
expect(data).not.to.have.property('history');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('does not propagate if args are untracked', function () {
|
|
131
|
+
simulateRequestScope(() => {
|
|
132
|
+
const result = global.ContrastMethods.tag(['', ''], 'bar');
|
|
133
|
+
const data = tracker.getData(result);
|
|
134
|
+
expect(data).to.be.null;
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('does not propagate if not in proper scope', function () {
|
|
139
|
+
simulateRequestScope(() => {
|
|
140
|
+
const result = global.ContrastMethods.tag(['', ''], trackString('bar'));
|
|
141
|
+
const data = tracker.getData(result);
|
|
142
|
+
expect(data).to.be.null;
|
|
143
|
+
}, null);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
DataflowTag: { UNTRUSTED, URL_ENCODED }
|
|
6
|
+
} = require('@contrast/common');
|
|
7
|
+
const { expect } = require('chai');
|
|
8
|
+
const sinon = require('sinon');
|
|
9
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
+
|
|
11
|
+
describe('assess dataflow propagation decodeURIComponent', 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.decodeURIComponent.install();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(function () {
|
|
26
|
+
core.assess.dataflow.propagation.decodeURIComponent.uninstall();
|
|
27
|
+
sinon.resetHistory();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
str: '%3Ftest%3Dstr',
|
|
33
|
+
tags: {
|
|
34
|
+
[UNTRUSTED]: [0, 12],
|
|
35
|
+
[URL_ENCODED]: [0, 12]
|
|
36
|
+
},
|
|
37
|
+
expected: { [UNTRUSTED]: [0, 8] }
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
str: '?test=str',
|
|
41
|
+
tags: {
|
|
42
|
+
[UNTRUSTED]: [0, 8]
|
|
43
|
+
},
|
|
44
|
+
expected: { [UNTRUSTED]: [0, 8] }
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
str: 'not-tracked',
|
|
48
|
+
}
|
|
49
|
+
].forEach(({ str, tags, expected }) => {
|
|
50
|
+
it('propagates correctly', function () {
|
|
51
|
+
simulateRequestScope(function () {
|
|
52
|
+
const value = tags ? trackString(str, { tags }) : str;
|
|
53
|
+
|
|
54
|
+
const result = decodeURIComponent(value);
|
|
55
|
+
const strInfo = tracker.getData(result);
|
|
56
|
+
expect(strInfo?.tags).to.deep.equal(expected);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('will not propagate if there is no assess context', function () {
|
|
62
|
+
simulateRequestScope(function () {
|
|
63
|
+
const value = trackString('%3Ftest%3Dstr');
|
|
64
|
+
const result = decodeURIComponent(value);
|
|
65
|
+
expect(tracker.getData(result)).to.be.null;
|
|
66
|
+
}, {});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('will not propagate if there instrumentation is locked', function () {
|
|
70
|
+
simulateRequestScope(function () {
|
|
71
|
+
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
72
|
+
const value = trackString('%3Ftest%3Dstr');
|
|
73
|
+
const result = decodeURIComponent(value);
|
|
74
|
+
expect(tracker.getData(result)).to.be.null;
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -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 ejs.utils.escapeXML', function () {
|
|
11
|
+
let core, trackString, simulateRequestScope, tracker, mockEjsUtils;
|
|
12
|
+
|
|
13
|
+
beforeEach(function () {
|
|
14
|
+
({
|
|
15
|
+
core,
|
|
16
|
+
simulateRequestScope,
|
|
17
|
+
trackString
|
|
18
|
+
} = initAssessFixture());
|
|
19
|
+
|
|
20
|
+
mockEjsUtils = {
|
|
21
|
+
escapeXML: (str) => `mock-escapeXML_${str}_mock-escapeXML`
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
tracker = core.assess.dataflow.tracker;
|
|
25
|
+
core.assess.dataflow.propagation.ejsInstrumentation.escapeXML.install();
|
|
26
|
+
core.depHooks.resolve.yield(mockEjsUtils);
|
|
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 = mockEjsUtils.escapeXML(notTrackedValue);
|
|
39
|
+
const notTrackedStrInfo = tracker.getData(notTrackedResult);
|
|
40
|
+
|
|
41
|
+
const trackedResult = mockEjsUtils.escapeXML(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 = mockEjsUtils.escapeXML(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 = mockEjsUtils.escapeXML(value);
|
|
65
|
+
expect(tracker.getData(result)).to.be.null;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const sinon = require('sinon');
|
|
5
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
6
|
+
|
|
7
|
+
describe('assess dataflow propagation ejs.Template', function () {
|
|
8
|
+
let core, trackString, simulateRequestScope, MockEjsTemplate;
|
|
9
|
+
|
|
10
|
+
beforeEach(function () {
|
|
11
|
+
({
|
|
12
|
+
core,
|
|
13
|
+
simulateRequestScope,
|
|
14
|
+
trackString
|
|
15
|
+
} = initAssessFixture());
|
|
16
|
+
|
|
17
|
+
MockEjsTemplate = function (source) {
|
|
18
|
+
this.source = source;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
MockEjsTemplate.prototype.generateSource = function() {
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
core.depHooks.resolve.withArgs({ name: 'ejs', version: '>=2.6.2' }).yields({ Template: MockEjsTemplate });
|
|
25
|
+
core.assess.dataflow.propagation.ejsInstrumentation.template.install();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(function () {
|
|
29
|
+
sinon.resetHistory();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('template.generateSource() will generate rewritten \'.source\' code value', function () {
|
|
33
|
+
simulateRequestScope(function () {
|
|
34
|
+
const t = new MockEjsTemplate(trackString('a + b'));
|
|
35
|
+
t.generateSource();
|
|
36
|
+
|
|
37
|
+
[
|
|
38
|
+
'function __append(s) {',
|
|
39
|
+
'if (ContrastMethods.notEqEq(s, undefined) && ContrastMethods.notEqEq(s, null)) __output = ContrastMethods.addAssign(__output, s);',
|
|
40
|
+
'}',
|
|
41
|
+
'ContrastMethods.add(a, b);',
|
|
42
|
+
'return __output',
|
|
43
|
+
].forEach((l) => expect(t.source).to.include(l));
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('will not rewrite content if not in source scope', function () {
|
|
48
|
+
const t = new MockEjsTemplate(trackString('a + b'));
|
|
49
|
+
t.generateSource();
|
|
50
|
+
expect(t.source).to.not.include('ContrastMethods');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('will not propagate if there instrumentation is locked', function () {
|
|
54
|
+
simulateRequestScope(function () {
|
|
55
|
+
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
56
|
+
const t = new MockEjsTemplate(trackString('a + b'));
|
|
57
|
+
t.generateSource();
|
|
58
|
+
expect(t.source).to.not.include('ContrastMethods');
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const { expect } = require('chai');
|
|
5
|
+
const sinon = require('sinon');
|
|
6
|
+
const {
|
|
7
|
+
DataflowTag: { UNTRUSTED, URL_ENCODED, WEAK_URL_ENCODED }
|
|
8
|
+
} = require('@contrast/common');
|
|
9
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
10
|
+
|
|
11
|
+
describe('assess dataflow propagation encodeURI, encodeURIComponent', 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.encodeURI.install();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(function () {
|
|
26
|
+
core.assess.dataflow.propagation.encodeURI.uninstall();
|
|
27
|
+
sinon.resetHistory();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('will not propagate if there is no assess context', function () {
|
|
31
|
+
simulateRequestScope(function () {
|
|
32
|
+
const value = trackString('?test=str');
|
|
33
|
+
const result = encodeURIComponent(value);
|
|
34
|
+
expect(tracker.getData(result)).to.be.null;
|
|
35
|
+
}, {});
|
|
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('?test=str');
|
|
42
|
+
const result = encodeURIComponent(value);
|
|
43
|
+
expect(tracker.getData(result)).to.be.null;
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('does not propagate untracked string', function () {
|
|
49
|
+
simulateRequestScope(function () {
|
|
50
|
+
const value = '?test=str';
|
|
51
|
+
const result = encodeURIComponent(value);
|
|
52
|
+
expect(tracker.getData(result)).to.be.null;
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('encodeURIComponent propagates correctly', function () {
|
|
57
|
+
simulateRequestScope(function () {
|
|
58
|
+
const value = trackString('?test=str');
|
|
59
|
+
|
|
60
|
+
const result = encodeURIComponent(value);
|
|
61
|
+
expect(result).to.be.equal('%3Ftest%3Dstr');
|
|
62
|
+
const strInfo = tracker.getData(result);
|
|
63
|
+
expect(strInfo?.tags).to.deep.equal({
|
|
64
|
+
[UNTRUSTED]: [3, 6, 10, 12],
|
|
65
|
+
[URL_ENCODED]: [0, 12]
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('encodeURI propagates correctly', function () {
|
|
71
|
+
simulateRequestScope(function () {
|
|
72
|
+
const value = trackString('http://foo.org/?tëst=str');
|
|
73
|
+
|
|
74
|
+
const result = encodeURI(value);
|
|
75
|
+
expect(result).to.be.equal('http://foo.org/?t%C3%ABst=str');
|
|
76
|
+
const strInfo = tracker.getData(result);
|
|
77
|
+
expect(strInfo?.tags).to.deep.equal({
|
|
78
|
+
[UNTRUSTED]: [0, 16, 23, 28],
|
|
79
|
+
[WEAK_URL_ENCODED]: [0, 28]
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
DataflowTag: { UNTRUSTED, HTML_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 escape-html', function () {
|
|
11
|
+
let core, trackString, simulateRequestScope, tracker, mockEscapeHtml, patchedEscapeHtml;
|
|
12
|
+
|
|
13
|
+
beforeEach(function () {
|
|
14
|
+
({
|
|
15
|
+
core,
|
|
16
|
+
simulateRequestScope,
|
|
17
|
+
trackString
|
|
18
|
+
} = initAssessFixture());
|
|
19
|
+
|
|
20
|
+
mockEscapeHtml = (str) => `mock-escape_${str}_mock-escape`;
|
|
21
|
+
|
|
22
|
+
tracker = core.assess.dataflow.tracker;
|
|
23
|
+
core.assess.dataflow.propagation.escapeHtml.install();
|
|
24
|
+
patchedEscapeHtml = core.depHooks.resolve.yield(mockEscapeHtml)[0];
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
afterEach(function () {
|
|
28
|
+
sinon.resetHistory();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('will not propagate if there is no assess context', function () {
|
|
32
|
+
simulateRequestScope(function () {
|
|
33
|
+
const value = trackString('<script>alert("hello");</script>');
|
|
34
|
+
const result = patchedEscapeHtml(value);
|
|
35
|
+
expect(tracker.getData(result)).to.be.null;
|
|
36
|
+
}, {});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('will not propagate if there instrumentation is locked', function () {
|
|
40
|
+
simulateRequestScope(function () {
|
|
41
|
+
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
42
|
+
const value = trackString('<script>alert("hello");</script>');
|
|
43
|
+
const result = patchedEscapeHtml(value);
|
|
44
|
+
expect(tracker.getData(result)).to.be.null;
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('will not propagate if string is not tracked', function () {
|
|
50
|
+
simulateRequestScope(function () {
|
|
51
|
+
const value = '<script>alert("hello");</script>';
|
|
52
|
+
const result = patchedEscapeHtml(value);
|
|
53
|
+
expect(tracker.getData(result)).to.be.null;
|
|
54
|
+
}, {});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
it('patchedEscapeHtml propagates correctly', function () {
|
|
59
|
+
simulateRequestScope(function () {
|
|
60
|
+
const value = trackString('<script>alert("hello");</script>');
|
|
61
|
+
const result = patchedEscapeHtml(value);
|
|
62
|
+
const strInfo = tracker.getData(result);
|
|
63
|
+
|
|
64
|
+
expect(result).to.be.equal('mock-escape_<script>alert("hello");</script>_mock-escape');
|
|
65
|
+
expect(strInfo?.tags).to.deep.equal({
|
|
66
|
+
[UNTRUSTED]: [12, 43],
|
|
67
|
+
[HTML_ENCODED]: [0, 55]
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|