@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,265 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
5
|
+
const {
|
|
6
|
+
UtilInspect,
|
|
7
|
+
DataflowTag: { UNTRUSTED },
|
|
8
|
+
} = require('@contrast/common');
|
|
9
|
+
const origStringify = JSON.stringify;
|
|
10
|
+
|
|
11
|
+
describe('assess dataflow propagation JSON stringify', function () {
|
|
12
|
+
let core,
|
|
13
|
+
simulateRequestScope,
|
|
14
|
+
trackString,
|
|
15
|
+
tracker,
|
|
16
|
+
objWithoutTrackedStr,
|
|
17
|
+
objWithTrackedStr,
|
|
18
|
+
standardEvent;
|
|
19
|
+
|
|
20
|
+
beforeEach(function () {
|
|
21
|
+
({ core, trackString, simulateRequestScope } = initAssessFixture());
|
|
22
|
+
|
|
23
|
+
tracker = core.assess.dataflow.tracker;
|
|
24
|
+
|
|
25
|
+
core.assess.dataflow.propagation.jsonInstrumentation.stringify.install();
|
|
26
|
+
core.assess.dataflow.propagation.stringInstrumentation.concat.install();
|
|
27
|
+
|
|
28
|
+
objWithoutTrackedStr = {
|
|
29
|
+
prop1: 'test',
|
|
30
|
+
prop2: 'test2',
|
|
31
|
+
arr: [1, 2, 'test3'],
|
|
32
|
+
nested: {
|
|
33
|
+
obj: 'prop',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
simulateRequestScope(() => {
|
|
38
|
+
objWithTrackedStr = {
|
|
39
|
+
prop1: trackString('test'),
|
|
40
|
+
prop2: trackString('test2'),
|
|
41
|
+
arr: [1, 2, trackString('test3')],
|
|
42
|
+
nested: {
|
|
43
|
+
obj: trackString('prop'),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
standardEvent = {
|
|
49
|
+
object: {
|
|
50
|
+
tracked: false,
|
|
51
|
+
value: 'JSON',
|
|
52
|
+
},
|
|
53
|
+
args: [{ tracked: false, value: 'Object' }],
|
|
54
|
+
context: `JSON.stringify(${origStringify(objWithTrackedStr)})`,
|
|
55
|
+
name: 'JSON.stringify',
|
|
56
|
+
moduleName: 'JSON',
|
|
57
|
+
methodName: 'stringify',
|
|
58
|
+
source: 'P0',
|
|
59
|
+
target: 'R',
|
|
60
|
+
result: {
|
|
61
|
+
tracked: true,
|
|
62
|
+
value: origStringify(objWithTrackedStr),
|
|
63
|
+
},
|
|
64
|
+
value: origStringify(objWithTrackedStr),
|
|
65
|
+
tags: {
|
|
66
|
+
[UNTRUSTED]: [10, 13, 25, 29, 44, 48, 69, 72],
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
afterEach(function () {
|
|
72
|
+
core.assess.dataflow.propagation.jsonInstrumentation.stringify.uninstall();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('results in an untracked string when the object is with all strings untracked ', function () {
|
|
76
|
+
simulateRequestScope(() => {
|
|
77
|
+
const ret = JSON.stringify(objWithoutTrackedStr);
|
|
78
|
+
expect(ret).to.equal(origStringify(objWithoutTrackedStr));
|
|
79
|
+
expect(tracker.getData(ret)).to.be.null;
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('results in an untracked string when there is no Assess scope', function () {
|
|
84
|
+
simulateRequestScope(() => {
|
|
85
|
+
const ret = JSON.stringify(objWithTrackedStr);
|
|
86
|
+
expect(ret).to.equal(origStringify(objWithTrackedStr));
|
|
87
|
+
expect(tracker.getData(ret)).to.be.null;
|
|
88
|
+
}, {});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('results in an untracked string when instrumentation is locked', function () {
|
|
92
|
+
simulateRequestScope(() => {
|
|
93
|
+
core.scopes.instrumentation.run({ lock: true }, () => {
|
|
94
|
+
const ret = JSON.stringify(objWithTrackedStr);
|
|
95
|
+
expect(ret).to.equal(origStringify(objWithTrackedStr));
|
|
96
|
+
expect(tracker.getData(ret)).to.be.null;
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('propagates correctly all kinds of string properties in a generic JSON.stringify call', function () {
|
|
102
|
+
simulateRequestScope(() => {
|
|
103
|
+
const ret = JSON.stringify(objWithTrackedStr);
|
|
104
|
+
expect(ret).to.equal(standardEvent.value);
|
|
105
|
+
expect(tracker.getData(ret)).to.be.like(standardEvent);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('propagates correctly all kinds of string properties in a JSON.stringify call with predefined spaces', function () {
|
|
110
|
+
simulateRequestScope(() => {
|
|
111
|
+
const stringifyArgs = [objWithTrackedStr, (_k, v) => v, 's'];
|
|
112
|
+
const ret = JSON.stringify(...stringifyArgs);
|
|
113
|
+
expect(ret).to.equal(origStringify(...stringifyArgs));
|
|
114
|
+
expect(tracker.getData(ret)).to.be.like({
|
|
115
|
+
...standardEvent,
|
|
116
|
+
context: `JSON.stringify(${origStringify(...stringifyArgs)})`,
|
|
117
|
+
args: [
|
|
118
|
+
{
|
|
119
|
+
tracked: false,
|
|
120
|
+
value: 'Object'
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
tracked: false,
|
|
124
|
+
value: 'Function',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
tracked: false,
|
|
128
|
+
value: 'String',
|
|
129
|
+
}
|
|
130
|
+
],
|
|
131
|
+
value: origStringify(...stringifyArgs),
|
|
132
|
+
result: {
|
|
133
|
+
tracked: true,
|
|
134
|
+
value: origStringify(...stringifyArgs),
|
|
135
|
+
},
|
|
136
|
+
tags: {
|
|
137
|
+
[UNTRUSTED]: [13, 16, 31, 35, 62, 66, 96, 99],
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('propagates correctly a JSON.stringify call with untrusted specified spaces', function () {
|
|
144
|
+
simulateRequestScope(() => {
|
|
145
|
+
const stringifyArgs = [
|
|
146
|
+
objWithoutTrackedStr,
|
|
147
|
+
(_k, v) => v,
|
|
148
|
+
trackString('user'),
|
|
149
|
+
];
|
|
150
|
+
const ret = JSON.stringify(...stringifyArgs);
|
|
151
|
+
|
|
152
|
+
expect(ret).to.equal(origStringify(...stringifyArgs));
|
|
153
|
+
expect(tracker.getData(ret)).to.be.like({
|
|
154
|
+
...standardEvent,
|
|
155
|
+
context: `JSON.stringify(${origStringify(...stringifyArgs)})`,
|
|
156
|
+
args: [
|
|
157
|
+
{
|
|
158
|
+
tracked: false,
|
|
159
|
+
value: 'Object',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
tracked: false,
|
|
163
|
+
value: 'Function',
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
tracked: true,
|
|
167
|
+
value: UtilInspect(stringifyArgs[2]),
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
value: origStringify(...stringifyArgs),
|
|
171
|
+
source: 'P2',
|
|
172
|
+
result: {
|
|
173
|
+
tracked: true,
|
|
174
|
+
value: origStringify(...stringifyArgs),
|
|
175
|
+
},
|
|
176
|
+
tags: {
|
|
177
|
+
[UNTRUSTED]: [
|
|
178
|
+
2, 5, 23, 26, 45, 48, 58, 65, 69, 76, 80, 87, 96, 99, 103, 106, 119,
|
|
179
|
+
126, 141, 144,
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('propagates correctly all kind of string properties in a JSON.stringify call with untrusted specified spaces', function () {
|
|
187
|
+
simulateRequestScope(() => {
|
|
188
|
+
const stringifyArgs = [
|
|
189
|
+
objWithTrackedStr,
|
|
190
|
+
(_k, v) => v,
|
|
191
|
+
trackString('user'),
|
|
192
|
+
];
|
|
193
|
+
const ret = JSON.stringify(...stringifyArgs);
|
|
194
|
+
expect(ret).to.equal(origStringify(...stringifyArgs));
|
|
195
|
+
expect(tracker.getData(ret)).to.be.like({
|
|
196
|
+
...standardEvent,
|
|
197
|
+
context: `JSON.stringify(${origStringify(...stringifyArgs)})`,
|
|
198
|
+
args: [
|
|
199
|
+
{
|
|
200
|
+
tracked: false,
|
|
201
|
+
value: 'Object',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
tracked: false,
|
|
205
|
+
value: 'Function',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
tracked: true,
|
|
209
|
+
value: UtilInspect(stringifyArgs[2]),
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
value: origStringify(...stringifyArgs),
|
|
213
|
+
source: 'P',
|
|
214
|
+
result: {
|
|
215
|
+
tracked: true,
|
|
216
|
+
value: origStringify(...stringifyArgs),
|
|
217
|
+
},
|
|
218
|
+
tags: {
|
|
219
|
+
[UNTRUSTED]: [
|
|
220
|
+
2, 5, 16, 19, 23, 26, 37, 41, 45, 48, 58, 65, 69, 76, 80, 87, 89,
|
|
221
|
+
93, 96, 99, 103, 106, 119, 126, 135, 138, 141, 144,
|
|
222
|
+
],
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('some edge cases', function () {
|
|
229
|
+
it('handles cases when the second argument is an array', function () {
|
|
230
|
+
simulateRequestScope(() => {
|
|
231
|
+
const stringifyArgs = [objWithTrackedStr, ['arr', 'nested', 'obj']];
|
|
232
|
+
const ret = JSON.stringify(...stringifyArgs);
|
|
233
|
+
expect(ret).to.equal(origStringify(...stringifyArgs));
|
|
234
|
+
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
235
|
+
[UNTRUSTED]: [13, 17, 38, 41],
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it('handles cases when the third argument is not entirely tagged', function () {
|
|
241
|
+
simulateRequestScope(() => {
|
|
242
|
+
const concatSpaces = 'd'.concat(
|
|
243
|
+
trackString('us'),
|
|
244
|
+
'd',
|
|
245
|
+
trackString('us')
|
|
246
|
+
);
|
|
247
|
+
const stringifyArgs = [
|
|
248
|
+
objWithoutTrackedStr,
|
|
249
|
+
(_k, v) => v,
|
|
250
|
+
concatSpaces,
|
|
251
|
+
];
|
|
252
|
+
const ret = JSON.stringify(...stringifyArgs);
|
|
253
|
+
expect(ret).to.equal(origStringify(...stringifyArgs));
|
|
254
|
+
expect(tracker.getData(ret).tags).to.deep.equal({
|
|
255
|
+
[UNTRUSTED]: [
|
|
256
|
+
3, 4, 6, 7, 26, 27, 29, 30, 50, 51, 53, 54, 65, 66, 68, 69, 71, 72,
|
|
257
|
+
74, 75, 80, 81, 83, 84, 86, 87, 89, 90, 95, 96, 98, 99, 101, 102,
|
|
258
|
+
104, 105, 115, 116, 118, 119, 124, 125, 127, 128, 142, 143, 145,
|
|
259
|
+
146, 148, 149, 151, 152, 168, 169, 171, 172,
|
|
260
|
+
],
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
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 array join', function () {
|
|
8
|
+
let core, trackString, simulateRequestScope, tracker;
|
|
9
|
+
|
|
10
|
+
beforeEach(function () {
|
|
11
|
+
({
|
|
12
|
+
core,
|
|
13
|
+
simulateRequestScope,
|
|
14
|
+
trackString
|
|
15
|
+
} = initAssessFixture());
|
|
16
|
+
|
|
17
|
+
tracker = core.assess.dataflow.tracker;
|
|
18
|
+
core.assess.dataflow.propagation.arrayJoin.install();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(function () {
|
|
22
|
+
core.assess.dataflow.propagation.arrayJoin.uninstall();
|
|
23
|
+
sinon.resetHistory();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
[
|
|
27
|
+
{
|
|
28
|
+
expected: { untrusted: [12, 18, 38, 51] }
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
separator: 'not-tracked',
|
|
32
|
+
expected: { untrusted: [22, 28, 68, 81] }
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
separator: 'tracked-sep',
|
|
36
|
+
tags: {
|
|
37
|
+
untrusted: [0, 10]
|
|
38
|
+
},
|
|
39
|
+
expected: { untrusted: [11, 39, 57, 81] }
|
|
40
|
+
}
|
|
41
|
+
].forEach(({ separator, tags, expected }) => {
|
|
42
|
+
it('propagates correctly', function () {
|
|
43
|
+
simulateRequestScope(function () {
|
|
44
|
+
const arr = [
|
|
45
|
+
'not-tracked',
|
|
46
|
+
trackString('tracked', { tags: { untrusted: [0, 6] } }),
|
|
47
|
+
'another-untracked',
|
|
48
|
+
trackString('another-tracked', { tags: { untrusted: [0, 13] } })
|
|
49
|
+
];
|
|
50
|
+
let source = 'O';
|
|
51
|
+
|
|
52
|
+
if (tags) {
|
|
53
|
+
separator = trackString(separator, { tags });
|
|
54
|
+
source = 'A';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const result = arr.join(separator);
|
|
58
|
+
const strInfo = tracker.getData(result);
|
|
59
|
+
expect(strInfo?.tags).to.deep.equal(expected);
|
|
60
|
+
expect(strInfo?.source).to.equal(source);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('propagates correclty nested arrays', function () {
|
|
66
|
+
simulateRequestScope(function () {
|
|
67
|
+
const str = trackString('tracked', { tags: { untrusted: [0, 6] } });
|
|
68
|
+
const arr = [
|
|
69
|
+
'not-tracked',
|
|
70
|
+
[
|
|
71
|
+
'not-tracked',
|
|
72
|
+
str
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
'not-tracked',
|
|
76
|
+
[
|
|
77
|
+
'not-tracked',
|
|
78
|
+
str
|
|
79
|
+
]
|
|
80
|
+
]
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
const result = arr.join();
|
|
84
|
+
const resultInfo = tracker.getData(result);
|
|
85
|
+
expect(resultInfo?.tags).to.deep.equal({ untrusted: [24, 30, 56, 62] });
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('will not propagate if there is no assess context', function () {
|
|
90
|
+
simulateRequestScope(function () {
|
|
91
|
+
const value = trackString('foo');
|
|
92
|
+
const result = ['not-tracked', value].join();
|
|
93
|
+
expect(tracker.getData(result)).to.be.null;
|
|
94
|
+
}, {});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('will not propagate if there instrumentation is locked', function () {
|
|
98
|
+
simulateRequestScope(function () {
|
|
99
|
+
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
100
|
+
const value = trackString('foo');
|
|
101
|
+
const result = ['not-tracked', value].join();
|
|
102
|
+
expect(tracker.getData(result)).to.be.null;
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
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 Buffer', function () {
|
|
8
|
+
let core, simulateRequestScope, tracker, trackString, createSourceEvent;
|
|
9
|
+
|
|
10
|
+
beforeEach(function () {
|
|
11
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
12
|
+
|
|
13
|
+
tracker = core.assess.dataflow.tracker;
|
|
14
|
+
createSourceEvent = core.assess.eventFactory.createSourceEvent;
|
|
15
|
+
core.assess.dataflow.propagation.bufferInstrumentation.install();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(function () {
|
|
19
|
+
core.assess.dataflow.propagation.arrayJoin.uninstall();
|
|
20
|
+
sinon.resetHistory();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('Buffer.prototype.toString', function () {
|
|
24
|
+
[
|
|
25
|
+
'utf8',
|
|
26
|
+
'latin1',
|
|
27
|
+
'ascii',
|
|
28
|
+
// todo
|
|
29
|
+
].forEach((encoding) => {
|
|
30
|
+
const value = 'foo';
|
|
31
|
+
|
|
32
|
+
it(`value when buffer is tracked (${encoding})`, function () {
|
|
33
|
+
simulateRequestScope(() => {
|
|
34
|
+
const b = Buffer.from(value, encoding);
|
|
35
|
+
const event = createSourceEvent({
|
|
36
|
+
name: 'body-parser-mock',
|
|
37
|
+
result: { tracked: true, value: b },
|
|
38
|
+
inputType: 'BODY',
|
|
39
|
+
tags: {
|
|
40
|
+
UNTRUSTED: [0, 2],
|
|
41
|
+
},
|
|
42
|
+
stack: [],
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
tracker.track(b, event);
|
|
46
|
+
expect(tracker.getData(b.toString(encoding))).to.deep.include({
|
|
47
|
+
addedTags: [],
|
|
48
|
+
args: [{ tracked: false, value: encoding }],
|
|
49
|
+
moduleName: 'Buffer',
|
|
50
|
+
methodName: 'prototype.toString',
|
|
51
|
+
context: 'buffer.toString()',
|
|
52
|
+
name: 'global.Buffer.prototype.toString',
|
|
53
|
+
object: { tracked: true, value: 'Buffer' },
|
|
54
|
+
removedTags: [],
|
|
55
|
+
result: { tracked: true, value },
|
|
56
|
+
source: 'O',
|
|
57
|
+
stack: [],
|
|
58
|
+
tags: {
|
|
59
|
+
UNTRUSTED: [0, 2]
|
|
60
|
+
},
|
|
61
|
+
target: 'R',
|
|
62
|
+
value,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('Buffer.from', function () {
|
|
70
|
+
// todo: implementation for other types. see https://nodejs.org/api/buffer.html
|
|
71
|
+
|
|
72
|
+
const trkInfoCommon = {
|
|
73
|
+
object: { tracked: true, value: 'Buffer' },
|
|
74
|
+
source: 'P0',
|
|
75
|
+
target: 'R',
|
|
76
|
+
tags: { UNTRUSTED: [0, 7] },
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
[
|
|
80
|
+
{
|
|
81
|
+
getArgs: () => trackString('a string'),
|
|
82
|
+
argType: 'string',
|
|
83
|
+
expected: {
|
|
84
|
+
...trkInfoCommon,
|
|
85
|
+
context: 'Buffer.from(a string)',
|
|
86
|
+
args: [{ tracked: true, value: 'a string' }],
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
getArgs: () => Buffer.from(trackString('a buffer')),
|
|
91
|
+
argType: 'buffer',
|
|
92
|
+
expected: {
|
|
93
|
+
...trkInfoCommon,
|
|
94
|
+
context: 'Buffer.from(a buffer)',
|
|
95
|
+
args: [{ tracked: true, value: 'a buffer' }],
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
].forEach(({ argType, getArgs, expected }) => {
|
|
100
|
+
it(`tracks result when argument is tracked (arg type ${argType})`, function () {
|
|
101
|
+
simulateRequestScope(() => {
|
|
102
|
+
const b = Buffer.from(getArgs());
|
|
103
|
+
const trkInfo = tracker.getData(b);
|
|
104
|
+
expect(trkInfo).to.deep.include(expected);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
DataflowTag: {
|
|
5
|
+
UNTRUSTED,
|
|
6
|
+
}
|
|
7
|
+
} = require('@contrast/common');
|
|
8
|
+
const { expect } = require('chai');
|
|
9
|
+
const sinon = require('sinon');
|
|
10
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
11
|
+
|
|
12
|
+
describe('assess dataflow propagation contrast-methods add', function () {
|
|
13
|
+
let core, simulateRequestScope, trackString, tracker;
|
|
14
|
+
|
|
15
|
+
beforeEach(function () {
|
|
16
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
17
|
+
tracker = core.assess.dataflow.tracker;
|
|
18
|
+
|
|
19
|
+
core.contrastMethods.install();
|
|
20
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation.add.install();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
afterEach(function () {
|
|
24
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation.add.uninstall();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const foo = () => trackString('foo');
|
|
28
|
+
const bar = () => 'bar';
|
|
29
|
+
|
|
30
|
+
[
|
|
31
|
+
{
|
|
32
|
+
name: 'tracked A, untracked B',
|
|
33
|
+
args: [foo, bar],
|
|
34
|
+
expected: {
|
|
35
|
+
[UNTRUSTED]: [0, 2],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'tracked A, tracked B',
|
|
40
|
+
args: [foo, foo],
|
|
41
|
+
expected: {
|
|
42
|
+
[UNTRUSTED]: [0, 5],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'untracked A, tracked B',
|
|
47
|
+
args: [bar, foo],
|
|
48
|
+
expected: {
|
|
49
|
+
[UNTRUSTED]: [3, 5],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'empty A, tracked B',
|
|
54
|
+
args: [() => '', foo],
|
|
55
|
+
expected: {
|
|
56
|
+
[UNTRUSTED]: [0, 2],
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
].forEach(({ name, args, expected }) => {
|
|
60
|
+
it(`propagates ${name} correctly`, function () {
|
|
61
|
+
simulateRequestScope(function () {
|
|
62
|
+
const result = global.ContrastMethods.add(...args.map(Reflect.apply));
|
|
63
|
+
|
|
64
|
+
expect(tracker.getData(result))
|
|
65
|
+
.to.have.property('tags')
|
|
66
|
+
.that.deep.equals(expected);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('will not propagate if there is no result or not in proper source scope', function () {
|
|
72
|
+
const { extern } = tracker.track('foo', { tags: { UNTRUSTED: [0, 2] } });
|
|
73
|
+
|
|
74
|
+
sinon.spy(tracker, 'track');
|
|
75
|
+
sinon.spy(tracker, 'getData');
|
|
76
|
+
|
|
77
|
+
core.scopes.sources.run({}, function () {
|
|
78
|
+
global.ContrastMethods.add('', '');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
core.scopes.sources.run(null, function () {
|
|
82
|
+
global.ContrastMethods.add(extern, 'bar');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
core.scopes.instrumentation.run({ lock: true }, function () {
|
|
86
|
+
core.scopes.sources.run({}, function () {
|
|
87
|
+
global.ContrastMethods.add(extern, 'bar');
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(tracker.track).not.to.have.been.called;
|
|
92
|
+
expect(tracker.getData).not.to.have.been.called;
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
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 contrast-methods', function () {
|
|
8
|
+
let core, instr;
|
|
9
|
+
|
|
10
|
+
const propagators = ['add', 'tag', 'number'];
|
|
11
|
+
|
|
12
|
+
beforeEach(function () {
|
|
13
|
+
({ core } = initAssessFixture());
|
|
14
|
+
instr = core.assess.dataflow.propagation.contrastMethodsInstrumentation;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('composes different installers', function () {
|
|
18
|
+
propagators.forEach((name) => {
|
|
19
|
+
expect(instr[name]).to.have.property('install').and.be.a('function');
|
|
20
|
+
expect(instr[name]).to.have.property('uninstall').and.be.a('function');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('dispatches installation to sub-components', function () {
|
|
25
|
+
const installs = [];
|
|
26
|
+
const uninstalls = [];
|
|
27
|
+
// stub these to prevent side effects
|
|
28
|
+
propagators.forEach((name) => {
|
|
29
|
+
const instr =
|
|
30
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation;
|
|
31
|
+
installs.push(sinon.stub(instr[name], 'install'));
|
|
32
|
+
uninstalls.push(sinon.stub(instr[name], 'uninstall'));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
instr.install();
|
|
36
|
+
|
|
37
|
+
expect(installs).to.have.lengthOf(propagators.length);
|
|
38
|
+
installs.forEach((installer) => {
|
|
39
|
+
expect(installer).to.have.been.called;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
instr.uninstall();
|
|
43
|
+
|
|
44
|
+
expect(uninstalls).to.have.lengthOf(propagators.length);
|
|
45
|
+
uninstalls.forEach((installer) => {
|
|
46
|
+
expect(installer).to.have.been.called;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { expect } = require('chai');
|
|
4
|
+
const { initAssessFixture } = require('@contrast/test/fixtures');
|
|
5
|
+
|
|
6
|
+
describe('assess dataflow propagation contrast-methods number', function () {
|
|
7
|
+
let core, simulateRequestScope, trackString, tracker;
|
|
8
|
+
|
|
9
|
+
beforeEach(function () {
|
|
10
|
+
({ core, simulateRequestScope, trackString } = initAssessFixture());
|
|
11
|
+
tracker = core.assess.dataflow.tracker;
|
|
12
|
+
core.contrastMethods.install();
|
|
13
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation.number.install();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(function () {
|
|
17
|
+
core.assess.dataflow.propagation.contrastMethodsInstrumentation.number.uninstall();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('will not sanitize if Number coercion fails', function () {
|
|
21
|
+
simulateRequestScope(() => {
|
|
22
|
+
const str = trackString('foo');
|
|
23
|
+
global.ContrastMethods.Number(str);
|
|
24
|
+
expect(tracker.getData(str)).to.deep.include({
|
|
25
|
+
context: 'UNKNOWN.val',
|
|
26
|
+
name: 'assess-dataflow-fixture',
|
|
27
|
+
fieldName: 'val',
|
|
28
|
+
pathName: 'val',
|
|
29
|
+
stack: [],
|
|
30
|
+
inputType: 'UNKNOWN',
|
|
31
|
+
tags: { UNTRUSTED: [0, 2] },
|
|
32
|
+
result: { tracked: true, value: 'foo' },
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('will untrack if Number coercion succeeds', function () {
|
|
38
|
+
simulateRequestScope(() => {
|
|
39
|
+
const str = trackString('30000');
|
|
40
|
+
global.ContrastMethods.Number(str);
|
|
41
|
+
expect(tracker.getData(str)).to.be.null;
|
|
42
|
+
expect(core.logger.trace).to.have.been.calledWithMatch({
|
|
43
|
+
funcKey: 'assess-dataflow-propagator:ContrastMethods.Number',
|
|
44
|
+
sanitizer: 'ContrastMethods.Number',
|
|
45
|
+
value: '30000',
|
|
46
|
+
}, 'untracked a string value');
|
|
47
|
+
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
});
|