@contrast/assess 1.28.0 → 1.29.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.js +3 -3
- package/lib/dataflow/propagation/install/JSON/parse-fn.js +5 -5
- package/lib/dataflow/propagation/install/JSON/parse.js +3 -3
- package/lib/dataflow/propagation/install/JSON/stringify.js +24 -17
- package/lib/dataflow/propagation/install/array-prototype-join.js +3 -3
- package/lib/dataflow/propagation/install/buffer.js +60 -2
- package/lib/dataflow/propagation/install/contrast-methods/add.js +1 -3
- package/lib/dataflow/propagation/install/ejs/template.js +3 -3
- package/lib/dataflow/propagation/install/joi/boolean.js +1 -1
- package/lib/dataflow/propagation/install/joi/expression.js +1 -1
- package/lib/dataflow/propagation/install/joi/index.js +1 -1
- package/lib/dataflow/propagation/install/joi/keys.js +5 -4
- package/lib/dataflow/propagation/install/joi/number.js +1 -1
- package/lib/dataflow/propagation/install/joi/string-schema.js +3 -2
- package/lib/dataflow/propagation/install/joi/utils.js +9 -5
- package/lib/dataflow/propagation/install/joi/values.js +4 -3
- package/lib/dataflow/propagation/install/mongoose/schema-map.js +2 -2
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +2 -2
- package/lib/dataflow/propagation/install/mongoose/schema-string.js +2 -2
- package/lib/dataflow/propagation/install/path/basename.js +2 -2
- package/lib/dataflow/propagation/install/path/common.js +5 -5
- package/lib/dataflow/propagation/install/path/format.js +7 -4
- package/lib/dataflow/propagation/install/path/join-and-resolve.js +2 -2
- package/lib/dataflow/propagation/install/path/parse.js +4 -5
- package/lib/dataflow/propagation/install/querystring/escape.js +1 -1
- package/lib/dataflow/propagation/install/querystring/parse.js +8 -8
- package/lib/dataflow/propagation/install/querystring/stringify.js +1 -1
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +2 -3
- package/lib/dataflow/propagation/install/send.js +2 -2
- package/lib/dataflow/propagation/install/string/concat.js +19 -19
- package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
- package/lib/dataflow/propagation/install/string/index.js +4 -3
- package/lib/dataflow/propagation/install/string/match-all.js +3 -9
- package/lib/dataflow/propagation/install/string/match.js +6 -5
- package/lib/dataflow/propagation/install/string/replace.js +23 -17
- package/lib/dataflow/propagation/install/string/slice.js +5 -5
- package/lib/dataflow/propagation/install/string/split.js +13 -11
- package/lib/dataflow/propagation/install/string/substring.js +6 -5
- package/lib/dataflow/propagation/install/url/parse.js +1 -1
- package/lib/dataflow/propagation/install/url/searchParams.js +2 -1
- package/lib/dataflow/propagation/install/url/url.js +1 -1
- package/lib/dataflow/sinks/index.js +1 -0
- package/lib/dataflow/sinks/install/child-process.js +4 -4
- package/lib/dataflow/sinks/install/express/reflected-xss.js +7 -5
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +1 -2
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +1 -3
- package/lib/dataflow/sinks/install/fs.js +3 -3
- package/lib/dataflow/sinks/install/function.js +3 -3
- package/lib/dataflow/sinks/install/hapi/unvalidated-redirect.js +1 -2
- package/lib/dataflow/sinks/install/http/request.js +6 -5
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +2 -2
- package/lib/dataflow/sinks/install/libxmljs.js +1 -1
- package/lib/dataflow/sinks/install/marsdb.js +1 -2
- package/lib/dataflow/sinks/install/mongodb.js +1 -1
- package/lib/dataflow/sinks/install/mysql.js +1 -1
- package/lib/dataflow/sinks/install/postgres.js +1 -3
- package/lib/dataflow/sinks/install/restify.js +208 -0
- package/lib/dataflow/sinks/install/sequelize.js +1 -2
- package/lib/dataflow/sinks/install/vm.js +5 -5
- package/lib/dataflow/sources/handler.js +2 -2
- package/lib/dataflow/sources/index.js +1 -0
- package/lib/dataflow/sources/install/http.js +4 -4
- package/lib/dataflow/sources/install/restify/fieldedTextBodyParser.js +85 -0
- package/lib/dataflow/sources/install/restify/index.js +32 -0
- package/lib/dataflow/sources/install/restify/jsonBodyParser.js +109 -0
- package/lib/dataflow/sources/install/restify/router.js +77 -0
- package/lib/dataflow/tag-utils.js +20 -4
- package/lib/dataflow/tracker.js +1 -0
- package/lib/event-factory.js +3 -3
- package/lib/get-policy.js +2 -2
- package/lib/index.d.ts +18 -0
- package/lib/index.js +13 -0
- package/lib/make-source-context.js +2 -2
- package/lib/response-scanning/handlers/index.js +10 -10
- package/lib/response-scanning/handlers/utils.js +19 -12
- package/lib/response-scanning/install/http.js +9 -59
- package/lib/session-configuration/install/express-session.js +3 -5
- package/lib/session-configuration/install/fastify-cookie.js +3 -3
- package/lib/session-configuration/install/hapi.js +1 -3
- package/lib/session-configuration/install/koa.js +1 -1
- package/package.json +4 -4
|
@@ -15,11 +15,10 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const { inspect } = require('util');
|
|
19
18
|
const {
|
|
20
19
|
Rule,
|
|
21
20
|
isString,
|
|
22
|
-
|
|
21
|
+
StringPrototypeToLowerCase,
|
|
23
22
|
} = require('@contrast/common');
|
|
24
23
|
const { InstrumentationType: { RULE } } = require('../../constants');
|
|
25
24
|
const { PATCH_TYPE: patchType } = require('../common');
|
|
@@ -54,6 +53,7 @@ module.exports = function (core) {
|
|
|
54
53
|
logger,
|
|
55
54
|
patcher,
|
|
56
55
|
assess: {
|
|
56
|
+
inspect, // todo: remove
|
|
57
57
|
eventFactory,
|
|
58
58
|
cryptoAnalysis,
|
|
59
59
|
getSourceContext,
|
|
@@ -123,7 +123,7 @@ module.exports = function (core) {
|
|
|
123
123
|
const [alg] = data.args;
|
|
124
124
|
if (!isString(alg) || !getSourceContext(RULE, Rule.CRYPTO_BAD_CIPHERS)) return;
|
|
125
125
|
|
|
126
|
-
const algLower =
|
|
126
|
+
const algLower = StringPrototypeToLowerCase.call(alg);
|
|
127
127
|
for (const prefix of SAFE_CIPHER_ALGORITHM_PREFIXES) {
|
|
128
128
|
if (algLower.indexOf(prefix) === 0) return;
|
|
129
129
|
}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
-
const {
|
|
17
|
+
const { StringPrototypeTrim } = require('@contrast/common');
|
|
18
18
|
|
|
19
19
|
function isNumber(value) {
|
|
20
20
|
return !isNaN(value);
|
|
@@ -31,7 +31,7 @@ function array(input, index, accumulator) {
|
|
|
31
31
|
break;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
if (
|
|
34
|
+
if (StringPrototypeTrim.call(cv) === '' || (valueIndexes.length > 0 && cv === ',')) {
|
|
35
35
|
index += 1;
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
@@ -136,7 +136,7 @@ function object(value, index, accumulator) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
if (
|
|
139
|
-
|
|
139
|
+
StringPrototypeTrim.call(cv) === '' ||
|
|
140
140
|
(cv === ':' && keyIndexesLength > 0) ||
|
|
141
141
|
(cv === ',' && areKeysEqualToValues)
|
|
142
142
|
) {
|
|
@@ -214,10 +214,10 @@ function getStartEndIndices(input) {
|
|
|
214
214
|
let startCharIdx = 0;
|
|
215
215
|
let endCharIdx = input.length - 1;
|
|
216
216
|
|
|
217
|
-
while (!
|
|
217
|
+
while (!StringPrototypeTrim.call(input[startCharIdx])) {
|
|
218
218
|
startCharIdx++;
|
|
219
219
|
}
|
|
220
|
-
while (!
|
|
220
|
+
while (!StringPrototypeTrim.call(input[endCharIdx])) {
|
|
221
221
|
endCharIdx--;
|
|
222
222
|
}
|
|
223
223
|
return [startCharIdx, endCharIdx];
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const { isString
|
|
18
|
+
const { isString } = require('@contrast/common');
|
|
19
19
|
const { createSubsetTags } = require('../../../tag-utils');
|
|
20
20
|
const { patchType } = require('../../common');
|
|
21
21
|
const { getKeyValueIndices } = require('./parse-fn');
|
|
@@ -75,7 +75,7 @@ module.exports = function (core) {
|
|
|
75
75
|
moduleName: 'JSON',
|
|
76
76
|
methodName: 'parse',
|
|
77
77
|
object: {
|
|
78
|
-
value:
|
|
78
|
+
value: 'JSON',
|
|
79
79
|
tracked: false,
|
|
80
80
|
},
|
|
81
81
|
args: eventArgs,
|
|
@@ -97,7 +97,7 @@ module.exports = function (core) {
|
|
|
97
97
|
return core.assess.dataflow.propagation.jsonInstrumentation.parse = {
|
|
98
98
|
install() {
|
|
99
99
|
patcher.patch(JSON, 'parse', {
|
|
100
|
-
name: 'JSON.
|
|
100
|
+
name: 'JSON.parse',
|
|
101
101
|
patchType,
|
|
102
102
|
pre(data) {
|
|
103
103
|
if (!data.args[0] || !sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
@@ -16,14 +16,19 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
isString,
|
|
20
|
+
ArrayPrototypeSlice,
|
|
21
|
+
StringPrototypeReplace,
|
|
22
|
+
StringPrototypeMatch,
|
|
23
|
+
StringPrototypeMatchAll,
|
|
24
|
+
StringPrototypeSlice,
|
|
25
|
+
} = require('@contrast/common');
|
|
23
26
|
const crypto = require('crypto');
|
|
27
|
+
const { createMergedTags, getAdjustedUntrackedValue } = require('../../../tag-utils');
|
|
28
|
+
const { patchType } = require('../../common');
|
|
24
29
|
|
|
25
30
|
function makeCanary() {
|
|
26
|
-
return
|
|
31
|
+
return StringPrototypeReplace.call(
|
|
27
32
|
crypto
|
|
28
33
|
.randomBytes(12)
|
|
29
34
|
.toString('base64'),
|
|
@@ -84,12 +89,12 @@ module.exports = function(core) {
|
|
|
84
89
|
function getUntrustedSpaceProps(space) {
|
|
85
90
|
// it can't be a problem if it's not a string, if the string is all spaces, or
|
|
86
91
|
// if the string is zero length.
|
|
87
|
-
if (!isString(space) ||
|
|
92
|
+
if (!isString(space) || StringPrototypeMatch.call(space, /^\s+$/) || !space) {
|
|
88
93
|
return null;
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
|
|
92
|
-
const props = tracker.getData(
|
|
97
|
+
const props = tracker.getData(StringPrototypeSlice.call(space, 0, 10));
|
|
93
98
|
if (!props || !Object.keys(props.tags).length) {
|
|
94
99
|
return null;
|
|
95
100
|
}
|
|
@@ -100,10 +105,10 @@ module.exports = function(core) {
|
|
|
100
105
|
|
|
101
106
|
function createSpaceTagRanges(result, metadata) {
|
|
102
107
|
const tags = {};
|
|
103
|
-
const spaceValue =
|
|
108
|
+
const spaceValue = StringPrototypeSlice.call(metadata.origArgs[2], 0, 10);
|
|
104
109
|
const { spaceProps: { tags: spacePropsTags } } = metadata;
|
|
105
110
|
|
|
106
|
-
const spaces = Array.from(
|
|
111
|
+
const spaces = Array.from(StringPrototypeMatchAll.call(result, new RegExp(`(?<=\\n)(${spaceValue})+?(?=\\d|"|null|]|})`, 'g')));
|
|
107
112
|
|
|
108
113
|
for (const space of spaces) {
|
|
109
114
|
const match = space[0];
|
|
@@ -132,7 +137,7 @@ module.exports = function(core) {
|
|
|
132
137
|
let canaryReplacementDiff = 0;
|
|
133
138
|
// for each marker in the stringify's result, remove the marker and
|
|
134
139
|
// create a TagRange for the value.
|
|
135
|
-
return
|
|
140
|
+
return StringPrototypeReplace.call(result, metadata.regex, (m, id, offset) => {
|
|
136
141
|
// adjust offset by total characters removed so far
|
|
137
142
|
offset = offset - canaryReplacementDiff + 1;
|
|
138
143
|
// we don't replace the opening " in the regex - that just makes sure
|
|
@@ -157,7 +162,7 @@ module.exports = function(core) {
|
|
|
157
162
|
return core.assess.dataflow.propagation.jsonInstrumentation.stringify = {
|
|
158
163
|
install() {
|
|
159
164
|
patcher.patch(JSON, 'stringify', {
|
|
160
|
-
name: 'JSON.
|
|
165
|
+
name: 'JSON.stringify',
|
|
161
166
|
patchType,
|
|
162
167
|
pre(data) {
|
|
163
168
|
if (!sources.getStore()?.assess || instrumentation.isLocked()) return;
|
|
@@ -169,7 +174,7 @@ module.exports = function(core) {
|
|
|
169
174
|
// context used by the post hook.
|
|
170
175
|
data.metadata = {
|
|
171
176
|
history: new Set(),
|
|
172
|
-
origArgs: data.args
|
|
177
|
+
origArgs: ArrayPrototypeSlice.call(data.args),
|
|
173
178
|
strInfos: {},
|
|
174
179
|
propagate: false,
|
|
175
180
|
regex,
|
|
@@ -246,21 +251,23 @@ module.exports = function(core) {
|
|
|
246
251
|
methodName: 'stringify',
|
|
247
252
|
history: Array.from(metadata.history),
|
|
248
253
|
object: {
|
|
249
|
-
value:
|
|
254
|
+
value: 'JSON',
|
|
250
255
|
tracked: false
|
|
251
256
|
},
|
|
252
257
|
args: [
|
|
253
258
|
{
|
|
254
|
-
value:
|
|
259
|
+
value: getAdjustedUntrackedValue(metadata.origArgs[0]),
|
|
255
260
|
tracked: false
|
|
256
261
|
},
|
|
257
262
|
(metadata.origArgs[1] && {
|
|
258
|
-
value:
|
|
263
|
+
value: getAdjustedUntrackedValue(metadata.origArgs[1]),
|
|
259
264
|
tracked: false
|
|
260
265
|
}),
|
|
261
266
|
(metadata.origArgs[2] && {
|
|
262
|
-
|
|
263
|
-
|
|
267
|
+
tracked: !!metadata.spaceProps,
|
|
268
|
+
value: metadata.spaceProps ?
|
|
269
|
+
`'${metadata.origArgs[2]}'` :
|
|
270
|
+
getAdjustedUntrackedValue(metadata.origArgs[2]),
|
|
264
271
|
})
|
|
265
272
|
].filter(Boolean),
|
|
266
273
|
result: {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const { isString,
|
|
18
|
+
const { isString, ArrayPrototypeJoin, UtilInspect } = require('@contrast/common');
|
|
19
19
|
const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
|
|
20
20
|
const { createAppendTags } = require('../../tag-utils');
|
|
21
21
|
const { patchType } = require('../common');
|
|
@@ -79,7 +79,7 @@ module.exports = function(core) {
|
|
|
79
79
|
const initHistory = delimiterInfo ? new Set([delimiterInfo]) : new Set();
|
|
80
80
|
const { newTags, newHistory: history } = accumulateTags(obj, {}, 0, initHistory, delimiterLength, delimiterInfo?.tags);
|
|
81
81
|
const object = {
|
|
82
|
-
value: obj &&
|
|
82
|
+
value: obj && ArrayPrototypeJoin.call(obj),
|
|
83
83
|
tracked: false
|
|
84
84
|
};
|
|
85
85
|
|
|
@@ -93,7 +93,7 @@ module.exports = function(core) {
|
|
|
93
93
|
name,
|
|
94
94
|
moduleName: 'Array',
|
|
95
95
|
methodName: 'prototype.join',
|
|
96
|
-
context: `${object.value}.join('${
|
|
96
|
+
context: `${object.value}.join('${UtilInspect(args[0].value) || ''})`,
|
|
97
97
|
object,
|
|
98
98
|
result: {
|
|
99
99
|
value: resultInfo ? resultInfo.value : result,
|
|
@@ -14,14 +14,16 @@
|
|
|
14
14
|
*/
|
|
15
15
|
'use strict';
|
|
16
16
|
|
|
17
|
+
const { isString, ArrayPrototypeJoin, StringPrototypeSubstring } = require('@contrast/common');
|
|
17
18
|
const { InstrumentationType: { PROPAGATOR } } = require('../../../constants');
|
|
19
|
+
const { getAdjustedUntrackedValue } = require('../../tag-utils');
|
|
18
20
|
const { patchType } = require('../common');
|
|
19
21
|
|
|
20
22
|
module.exports = function(core) {
|
|
21
23
|
const {
|
|
22
24
|
assess: {
|
|
23
25
|
getSourceContext,
|
|
24
|
-
eventFactory,
|
|
26
|
+
eventFactory: { createPropagationEvent },
|
|
25
27
|
dataflow: { tracker }
|
|
26
28
|
},
|
|
27
29
|
patcher,
|
|
@@ -30,6 +32,7 @@ module.exports = function(core) {
|
|
|
30
32
|
return core.assess.dataflow.propagation.bufferInstrumentation = {
|
|
31
33
|
install() {
|
|
32
34
|
const name = 'global.Buffer.prototype.toString';
|
|
35
|
+
const bufferToString = patcher.unwrap(Buffer.prototype.toString);
|
|
33
36
|
|
|
34
37
|
patcher.patch(global.Buffer.prototype, 'toString', {
|
|
35
38
|
patchType,
|
|
@@ -44,7 +47,7 @@ module.exports = function(core) {
|
|
|
44
47
|
return;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
const event =
|
|
50
|
+
const event = createPropagationEvent({
|
|
48
51
|
args: data.args.map((a) => ({ tracked: false, value: a })),
|
|
49
52
|
moduleName: 'Buffer',
|
|
50
53
|
methodName: 'prototype.toString',
|
|
@@ -74,8 +77,63 @@ module.exports = function(core) {
|
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
});
|
|
80
|
+
|
|
81
|
+
patcher.patch(global.Buffer, 'from', {
|
|
82
|
+
patchType,
|
|
83
|
+
name,
|
|
84
|
+
post(data) {
|
|
85
|
+
const firstArg = data.args[0];
|
|
86
|
+
const argType = isString(firstArg) ? 'string' : Buffer.isBuffer(firstArg) ? 'buffer' : null;
|
|
87
|
+
// this method supports a number of type overloads. we handle when first arg matches these
|
|
88
|
+
const typeSupported = argType == 'string' || argType == 'buffer';
|
|
89
|
+
|
|
90
|
+
if (
|
|
91
|
+
!data.args[0] ||
|
|
92
|
+
!typeSupported ||
|
|
93
|
+
!getSourceContext(PROPAGATOR)
|
|
94
|
+
) return;
|
|
95
|
+
|
|
96
|
+
const trkInfo = tracker.getData(data.args[0]);
|
|
97
|
+
if (trkInfo) {
|
|
98
|
+
const args = data.args.map((arg, i) => {
|
|
99
|
+
if (i == 0) {
|
|
100
|
+
const value = argType == 'string' ? arg : bufferToString.call(arg);
|
|
101
|
+
// todo (NODE-3455): make sure tag ranges are included in substring
|
|
102
|
+
return { tracked: true, value: StringPrototypeSubstring.call(value, 0, 50) };
|
|
103
|
+
} else {
|
|
104
|
+
return { tracked: false, value: getAdjustedUntrackedValue(arg) };
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const event = createPropagationEvent({
|
|
109
|
+
args,
|
|
110
|
+
moduleName: 'Buffer',
|
|
111
|
+
methodName: 'from',
|
|
112
|
+
context: `Buffer.from(${ArrayPrototypeJoin.call(args.map((a) => a.value))})`,
|
|
113
|
+
object: { tracked: true, value: 'Buffer' },
|
|
114
|
+
history: [trkInfo],
|
|
115
|
+
name,
|
|
116
|
+
result: {
|
|
117
|
+
tracked: true,
|
|
118
|
+
value: args[0].value,
|
|
119
|
+
},
|
|
120
|
+
source: 'P0',
|
|
121
|
+
tags: trkInfo.tags,
|
|
122
|
+
stacktraceOpts: {
|
|
123
|
+
constructorOpt: data.hooked,
|
|
124
|
+
prependFrames: [data.orig]
|
|
125
|
+
},
|
|
126
|
+
target: 'R',
|
|
127
|
+
});
|
|
128
|
+
if (event) {
|
|
129
|
+
tracker.track(data.result, event);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
});
|
|
77
134
|
},
|
|
78
135
|
uninstall() {
|
|
136
|
+
global.Buffer.from = patcher.unwrap(global.Buffer.from);
|
|
79
137
|
global.Buffer.prototype.toString = patcher.unwrap(global.Buffer.prototype.toString);
|
|
80
138
|
}
|
|
81
139
|
};
|
|
@@ -15,21 +15,19 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const util = require('util');
|
|
19
18
|
const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
|
|
20
19
|
const { createAppendTags } = require('../../../tag-utils');
|
|
21
20
|
|
|
22
21
|
module.exports = function(core) {
|
|
23
22
|
const {
|
|
24
|
-
patcher,
|
|
25
23
|
assess: {
|
|
24
|
+
inspect,
|
|
26
25
|
getSourceContext,
|
|
27
26
|
eventFactory: { createPropagationEvent },
|
|
28
27
|
dataflow: { tracker }
|
|
29
28
|
}
|
|
30
29
|
} = core;
|
|
31
30
|
|
|
32
|
-
const inspect = patcher.unwrap(util.inspect);
|
|
33
31
|
const origSym = Symbol('ContrastMethods.add.orig');
|
|
34
32
|
|
|
35
33
|
return core.assess.dataflow.propagation.contrastMethodsInstrumentation.add = {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const { EOL } = require('os');
|
|
19
|
-
const {
|
|
19
|
+
const { ArrayPrototypeJoin } = require('@contrast/common');
|
|
20
20
|
const { patchType } = require('../../common');
|
|
21
21
|
const { InstrumentationType: { PROPAGATOR } } = require('../../../../constants');
|
|
22
22
|
|
|
@@ -39,11 +39,11 @@ module.exports = function (core) {
|
|
|
39
39
|
|
|
40
40
|
/** @type {import('@contrast/rewriter').RewriteOpts} */
|
|
41
41
|
const REWRITE_OPTS = { isModule: false, inject: false, wrap: false, trim: true };
|
|
42
|
-
const WRAPPER_PREFIX =
|
|
42
|
+
const WRAPPER_PREFIX = ArrayPrototypeJoin.call([
|
|
43
43
|
'function tempWrapper() {',
|
|
44
44
|
'function __append(s) { if (s !== undefined && s !== null) __output += s }'
|
|
45
45
|
], EOL);
|
|
46
|
-
const WRAPPER_SUFFIX =
|
|
46
|
+
const WRAPPER_SUFFIX = ArrayPrototypeJoin.call([
|
|
47
47
|
EOL,
|
|
48
48
|
'return __output;',
|
|
49
49
|
'}',
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
19
|
DataflowTag: { ALPHANUM_SPACE_HYPHEN },
|
|
20
|
-
inspect,
|
|
21
20
|
} = require('@contrast/common');
|
|
22
21
|
const { patchType } = require('../../common');
|
|
23
22
|
|
|
@@ -27,6 +26,7 @@ module.exports = function(core) {
|
|
|
27
26
|
scopes: { sources, instrumentation },
|
|
28
27
|
patcher,
|
|
29
28
|
assess: {
|
|
29
|
+
inspect, // todo: remove
|
|
30
30
|
eventFactory: { createPropagationEvent },
|
|
31
31
|
dataflow: { tracker },
|
|
32
32
|
},
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
19
|
DataflowTag: { HTML_ENCODED },
|
|
20
|
-
inspect,
|
|
21
20
|
} = require('@contrast/common');
|
|
22
21
|
const { patchType } = require('../../common');
|
|
23
22
|
|
|
@@ -27,6 +26,7 @@ module.exports = function(core) {
|
|
|
27
26
|
scopes: { sources, instrumentation },
|
|
28
27
|
patcher,
|
|
29
28
|
assess: {
|
|
29
|
+
inspect, // todo: remove
|
|
30
30
|
eventFactory: { createPropagationEvent },
|
|
31
31
|
dataflow: { tracker },
|
|
32
32
|
},
|
|
@@ -20,7 +20,6 @@ const {
|
|
|
20
20
|
isString,
|
|
21
21
|
isNonEmptyObject,
|
|
22
22
|
traverseValues,
|
|
23
|
-
inspect,
|
|
24
23
|
} = require('@contrast/common');
|
|
25
24
|
const { patchType } = require('../../common');
|
|
26
25
|
const { tagCustomValidatedString, handleReferences } = require('./utils');
|
|
@@ -30,6 +29,7 @@ module.exports = function(core) {
|
|
|
30
29
|
patcher,
|
|
31
30
|
scopes: { sources, instrumentation },
|
|
32
31
|
assess: {
|
|
32
|
+
inspect, // todo: remove
|
|
33
33
|
eventFactory: { createPropagationEvent },
|
|
34
34
|
dataflow: { tracker },
|
|
35
35
|
},
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
|
-
isNonEmptyObject,
|
|
19
|
+
isNonEmptyObject,
|
|
20
|
+
ArrayPrototypeJoin,
|
|
20
21
|
} = require('@contrast/common');
|
|
21
22
|
const { patchType } = require('../../common');
|
|
22
23
|
|
|
@@ -39,16 +40,16 @@ module.exports = function(core) {
|
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
let path =
|
|
43
|
+
let path = ArrayPrototypeJoin.call(refTargetPath, '.');
|
|
43
44
|
|
|
44
45
|
if (isInReference) {
|
|
45
|
-
path =
|
|
46
|
+
path = ArrayPrototypeJoin.call(refTargetPath.slice(0, -1), '.');
|
|
46
47
|
schema.__CONTRAST__.inReferenceTargets.add(path);
|
|
47
48
|
refPath = refPath.slice(0, -1);
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
const refs = schema.__CONTRAST__.refTargets[path] || [];
|
|
51
|
-
refs.push(
|
|
52
|
+
refs.push(ArrayPrototypeJoin.call(refPath, '.'));
|
|
52
53
|
schema.__CONTRAST__.refTargets[path] = refs;
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
19
|
DataflowTag: { LIMITED_CHARS },
|
|
20
|
-
inspect,
|
|
21
20
|
} = require('@contrast/common');
|
|
22
21
|
const { patchType } = require('../../common');
|
|
23
22
|
|
|
@@ -27,6 +26,7 @@ module.exports = function(core) {
|
|
|
27
26
|
scopes: { sources, instrumentation },
|
|
28
27
|
patcher,
|
|
29
28
|
assess: {
|
|
29
|
+
inspect, // todo: remove
|
|
30
30
|
eventFactory: { createPropagationEvent },
|
|
31
31
|
dataflow: { tracker },
|
|
32
32
|
},
|
|
@@ -17,11 +17,11 @@
|
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
19
|
DataflowTag: { ALPHANUM_SPACE_HYPHEN, LIMITED_CHARS, STRING_TYPE_CHECKED },
|
|
20
|
-
inspect,
|
|
21
20
|
} = require('@contrast/common');
|
|
22
|
-
const { handleReferences } = require('./utils');
|
|
23
21
|
const { createFullLengthCopyTags } = require('../../../tag-utils');
|
|
24
22
|
const { patchType } = require('../../common');
|
|
23
|
+
const { handleReferences } = require('./utils');
|
|
24
|
+
|
|
25
25
|
const VALIDATORS = {
|
|
26
26
|
base64: ALPHANUM_SPACE_HYPHEN,
|
|
27
27
|
guid: ALPHANUM_SPACE_HYPHEN,
|
|
@@ -42,6 +42,7 @@ module.exports = function(core) {
|
|
|
42
42
|
scopes: { sources, instrumentation },
|
|
43
43
|
patcher,
|
|
44
44
|
assess: {
|
|
45
|
+
inspect, // todo: remove
|
|
45
46
|
eventFactory: { createPropagationEvent },
|
|
46
47
|
dataflow: {
|
|
47
48
|
tracker, propagation: {
|
|
@@ -15,12 +15,16 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
StringPrototypeSplit,
|
|
20
|
+
ArrayPrototypeJoin,
|
|
21
|
+
DataflowTag: { CUSTOM_VALIDATED }
|
|
22
|
+
} = require('@contrast/common');
|
|
19
23
|
|
|
20
24
|
function getRefInstancesTrackingData(tracker, obj, refInstancesPaths) {
|
|
21
25
|
return refInstancesPaths
|
|
22
26
|
.map((referenceInstance) => {
|
|
23
|
-
const value =
|
|
27
|
+
const value = StringPrototypeSplit.call(referenceInstance, '.').reduce(
|
|
24
28
|
(acc, v) => acc[v] || acc,
|
|
25
29
|
obj
|
|
26
30
|
);
|
|
@@ -70,10 +74,10 @@ function tagCustomValidatedString(createPropagationEvent, strInfo, metadata) {
|
|
|
70
74
|
|
|
71
75
|
function handleReferences(tracker, schema, validationFn) {
|
|
72
76
|
const contrastData = schema?.schema?.__CONTRAST__;
|
|
73
|
-
let refTargetPath = contrastData &&
|
|
74
|
-
const inReferenceTargetPath = contrastData &&
|
|
77
|
+
let refTargetPath = contrastData && ArrayPrototypeJoin.call(schema.state.path, '.');
|
|
78
|
+
const inReferenceTargetPath = contrastData && ArrayPrototypeJoin.call(schema.state.path.slice(0, -1), '.');
|
|
75
79
|
if (contrastData?.inReferenceTargets.has(inReferenceTargetPath)) {
|
|
76
|
-
refTargetPath =
|
|
80
|
+
refTargetPath = ArrayPrototypeJoin.call(
|
|
77
81
|
schema.state.path.slice(0, -1),
|
|
78
82
|
'.'
|
|
79
83
|
);
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
const {
|
|
19
|
-
isNonEmptyObject, isString,
|
|
19
|
+
isNonEmptyObject, isString, traverseValues, ArrayPrototypeJoin
|
|
20
20
|
} = require('@contrast/common');
|
|
21
21
|
const { createMergedTags } = require('../../../tag-utils');
|
|
22
22
|
const { patchType } = require('../../common');
|
|
@@ -27,6 +27,7 @@ module.exports = function(core) {
|
|
|
27
27
|
scopes: { sources, instrumentation },
|
|
28
28
|
patcher,
|
|
29
29
|
assess: {
|
|
30
|
+
inspect, // todo: remove
|
|
30
31
|
eventFactory: { createPropagationEvent },
|
|
31
32
|
dataflow: { tracker },
|
|
32
33
|
},
|
|
@@ -57,13 +58,13 @@ module.exports = function(core) {
|
|
|
57
58
|
|
|
58
59
|
|
|
59
60
|
if (result.ref) {
|
|
60
|
-
const targetAbsolutePath =
|
|
61
|
+
const targetAbsolutePath = ArrayPrototypeJoin.call(result.ref.absolute(state), '.');
|
|
61
62
|
|
|
62
63
|
if (isString(value)) {
|
|
63
64
|
validateStringReferenceValue(value, result.value, result.ref, targetAbsolutePath, metadata);
|
|
64
65
|
} else if (isNonEmptyObject(value)) {
|
|
65
66
|
traverseValues(value, (path, _type, v) => {
|
|
66
|
-
validateStringReferenceValue(v, result.value, result.ref,
|
|
67
|
+
validateStringReferenceValue(v, result.value, result.ref, ArrayPrototypeJoin.call([...targetAbsolutePath, ...path], '.'), metadata, path);
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
} else if (data.obj?._values.has(data.result?.value)) {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
'use strict';
|
|
16
16
|
const { patchType } = require('../../common');
|
|
17
17
|
const { userDefinedType } = require('./common');
|
|
18
|
-
const { traverseValues, DataflowTag,
|
|
18
|
+
const { traverseValues, DataflowTag, StringPrototypeSubstring } = require('@contrast/common');
|
|
19
19
|
|
|
20
20
|
module.exports = function (core) {
|
|
21
21
|
const {
|
|
@@ -36,7 +36,7 @@ module.exports = function (core) {
|
|
|
36
36
|
mongooseInstrumentation.schemaMap = schemaMap;
|
|
37
37
|
|
|
38
38
|
const handleString = (strInfo, orig, value, name) => {
|
|
39
|
-
const methodName =
|
|
39
|
+
const methodName = StringPrototypeSubstring.call(name, name.indexOf('.') + 1);
|
|
40
40
|
|
|
41
41
|
// copy because we mutate the metadata value inline
|
|
42
42
|
const history = [{ ...strInfo }];
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
'use strict';
|
|
16
16
|
const { patchType } = require('../../common');
|
|
17
17
|
const { userDefinedType } = require('./common');
|
|
18
|
-
const { traverseValues, DataflowTag,
|
|
18
|
+
const { traverseValues, DataflowTag, StringPrototypeSubstring } = require('@contrast/common');
|
|
19
19
|
|
|
20
20
|
module.exports = function (core) {
|
|
21
21
|
const {
|
|
@@ -36,7 +36,7 @@ module.exports = function (core) {
|
|
|
36
36
|
mongooseInstrumentation.schemaMixed = schemaMixed;
|
|
37
37
|
|
|
38
38
|
const handleString = (strInfo, orig, value, name) => {
|
|
39
|
-
const methodName =
|
|
39
|
+
const methodName = StringPrototypeSubstring.call(name, name.indexOf('.') + 1);
|
|
40
40
|
|
|
41
41
|
// copy because we mutate the metadata value inline
|
|
42
42
|
const history = [{ ...strInfo }];
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const { DataflowTag,
|
|
18
|
+
const { DataflowTag, StringPrototypeSubstring } = require('@contrast/common');
|
|
19
19
|
const { patchType } = require('../../common');
|
|
20
20
|
const { userDefinedType } = require('./common');
|
|
21
21
|
|
|
@@ -141,7 +141,7 @@ module.exports = function (core) {
|
|
|
141
141
|
const strInfo = tracker.getData(value);
|
|
142
142
|
if (!strInfo) return;
|
|
143
143
|
|
|
144
|
-
const methodName =
|
|
144
|
+
const methodName = StringPrototypeSubstring.call(name, name.indexOf('.') + 1);
|
|
145
145
|
// copy because we mutate the metadata value inline
|
|
146
146
|
const history = [{ ...strInfo }];
|
|
147
147
|
const event = createPropagationEvent({
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
|
-
const { isString,
|
|
17
|
+
const { isString, ArrayPrototypeJoin } = require('@contrast/common');
|
|
18
18
|
const { patchType } = require('../../common');
|
|
19
19
|
const {
|
|
20
20
|
excludeExtensionDotFromTags,
|
|
@@ -82,7 +82,7 @@ module.exports = function(core) {
|
|
|
82
82
|
name,
|
|
83
83
|
moduleName: 'path',
|
|
84
84
|
methodName: 'basename',
|
|
85
|
-
context: `path.basename(${
|
|
85
|
+
context: `path.basename(${ArrayPrototypeJoin.call(args.map(a => `'${a.value}'`))})`,
|
|
86
86
|
history: [strInfo],
|
|
87
87
|
object: {
|
|
88
88
|
value: 'path',
|