@contrast/assess 1.11.0 → 1.13.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/LICENSE +12 -0
- package/lib/dataflow/index.js +0 -1
- package/lib/dataflow/propagation/index.js +2 -0
- package/lib/dataflow/propagation/install/JSON/parse.js +2 -4
- package/lib/dataflow/propagation/install/JSON/stringify.js +2 -1
- package/lib/dataflow/propagation/install/array-prototype-join.js +2 -1
- package/lib/dataflow/propagation/install/buffer.js +2 -4
- package/lib/dataflow/propagation/install/contrast-methods/add.js +2 -1
- package/lib/dataflow/propagation/install/contrast-methods/string.js +2 -4
- package/lib/dataflow/propagation/install/contrast-methods/tag.js +2 -4
- package/lib/dataflow/propagation/install/decode-uri-component.js +2 -1
- package/lib/dataflow/propagation/install/ejs/escape-xml.js +2 -1
- package/lib/dataflow/propagation/install/encode-uri-component.js +2 -1
- package/lib/dataflow/propagation/install/escape-html.js +2 -1
- package/lib/dataflow/propagation/install/escape.js +2 -1
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +2 -1
- package/lib/dataflow/propagation/install/joi/index.js +35 -0
- package/lib/dataflow/propagation/install/joi/keys.js +140 -0
- package/lib/dataflow/propagation/install/joi/string-schema.js +269 -0
- package/lib/dataflow/propagation/install/joi/values.js +141 -0
- package/lib/dataflow/propagation/install/mongoose/schema-map.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/schema-string.js +2 -4
- package/lib/dataflow/propagation/install/mysql-connection-escape.js +2 -1
- package/lib/dataflow/propagation/install/path/basename.js +2 -4
- package/lib/dataflow/propagation/install/path/join-and-resolve.js +2 -4
- package/lib/dataflow/propagation/install/path/normalize.js +2 -4
- package/lib/dataflow/propagation/install/pug/index.js +2 -2
- package/lib/dataflow/propagation/install/pug-runtime-escape.js +2 -1
- package/lib/dataflow/propagation/install/querystring/parse.js +2 -1
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +2 -4
- package/lib/dataflow/propagation/install/send.js +60 -0
- package/lib/dataflow/propagation/install/sequelize.js +6 -8
- package/lib/dataflow/propagation/install/sql-template-strings.js +2 -1
- package/lib/dataflow/propagation/install/string/concat.js +2 -1
- package/lib/dataflow/propagation/install/string/format-methods.js +2 -1
- package/lib/dataflow/propagation/install/string/html-methods.js +2 -1
- package/lib/dataflow/propagation/install/string/index.js +2 -1
- package/lib/dataflow/propagation/install/string/match-all.js +1 -1
- package/lib/dataflow/propagation/install/string/match.js +1 -1
- package/lib/dataflow/propagation/install/string/replace.js +2 -1
- package/lib/dataflow/propagation/install/string/slice.js +2 -1
- package/lib/dataflow/propagation/install/string/split.js +2 -1
- package/lib/dataflow/propagation/install/string/substring.js +2 -1
- package/lib/dataflow/propagation/install/string/trim.js +2 -1
- package/lib/dataflow/propagation/install/unescape.js +2 -1
- package/lib/dataflow/propagation/install/url/domain-parsers.js +2 -1
- package/lib/dataflow/propagation/install/url/parse.js +3 -2
- package/lib/dataflow/propagation/install/url/searchParams.js +17 -10
- package/lib/dataflow/propagation/install/url/url.js +2 -1
- package/lib/dataflow/propagation/install/validator/hooks.js +2 -1
- package/lib/dataflow/sinks/install/child-process.js +1 -1
- package/lib/dataflow/sinks/install/eval.js +1 -1
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +2 -2
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/fs.js +3 -3
- package/lib/dataflow/sinks/install/function.js +1 -1
- package/lib/dataflow/sinks/install/http/request.js +1 -1
- package/lib/dataflow/sinks/install/http/server-response.js +1 -1
- package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/marsdb.js +1 -1
- package/lib/dataflow/sinks/install/mongodb.js +2 -2
- package/lib/dataflow/sinks/install/mssql.js +1 -1
- package/lib/dataflow/sinks/install/mysql.js +2 -2
- package/lib/dataflow/sinks/install/postgres.js +1 -1
- package/lib/dataflow/sinks/install/sequelize.js +1 -1
- package/lib/dataflow/sinks/install/sqlite3.js +1 -1
- package/lib/dataflow/sinks/install/vm.js +1 -1
- package/lib/dataflow/sources/handler.js +2 -2
- package/lib/dataflow/sources/install/body-parser1.js +2 -2
- package/lib/dataflow/sources/install/fastify/fastify.js +1 -1
- package/lib/dataflow/sources/install/http.js +11 -10
- package/lib/dataflow/tracker.js +1 -5
- package/lib/{dataflow/event-factory.js → event-factory.js} +57 -1
- package/lib/index.js +3 -1
- package/lib/response-scanning/install/http.js +3 -2
- package/lib/session-configuration/common.js +19 -0
- package/lib/session-configuration/handlers.js +86 -0
- package/lib/session-configuration/index.js +5 -8
- package/lib/session-configuration/install/express-session.js +131 -0
- package/package.json +11 -10
- package/lib/session-configuration/install/http.js +0 -79
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright: 2023 Contrast Security, Inc
|
|
2
|
+
Contact: support@contrastsecurity.com
|
|
3
|
+
License: Commercial
|
|
4
|
+
|
|
5
|
+
NOTICE: This Software and the patented inventions embodied within may only be
|
|
6
|
+
used as part of Contrast Security’s commercial offerings. Even though it is
|
|
7
|
+
made available through public repositories, use of this Software is subject to
|
|
8
|
+
the applicable End User Licensing Agreement found at
|
|
9
|
+
https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
10
|
+
between Contrast Security and the End User. The Software may not be reverse
|
|
11
|
+
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
12
|
+
way not consistent with the End User License Agreement.
|
package/lib/dataflow/index.js
CHANGED
|
@@ -20,7 +20,6 @@ const { callChildComponentMethodsSync } = require('@contrast/common');
|
|
|
20
20
|
module.exports = function(core) {
|
|
21
21
|
const dataflow = core.assess.dataflow = {};
|
|
22
22
|
|
|
23
|
-
require('./event-factory')(core);
|
|
24
23
|
require('./tracker')(core);
|
|
25
24
|
require('./sources')(core);
|
|
26
25
|
require('./propagation')(core);
|
|
@@ -45,6 +45,8 @@ module.exports = function(core) {
|
|
|
45
45
|
require('./install/JSON')(core);
|
|
46
46
|
require('./install/path')(core);
|
|
47
47
|
require('./install/reg-exp-prototype-exec')(core);
|
|
48
|
+
require('./install/joi')(core);
|
|
49
|
+
require('./install/send')(core);
|
|
48
50
|
|
|
49
51
|
propagation.install = function() {
|
|
50
52
|
callChildComponentMethodsSync(propagation, 'install');
|
|
@@ -52,10 +52,8 @@ module.exports = function (core) {
|
|
|
52
52
|
scopes: { sources, instrumentation },
|
|
53
53
|
patcher,
|
|
54
54
|
assess: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
eventFactory: { createPropagationEvent },
|
|
58
|
-
},
|
|
55
|
+
eventFactory: { createPropagationEvent },
|
|
56
|
+
dataflow: { tracker },
|
|
59
57
|
},
|
|
60
58
|
} = core;
|
|
61
59
|
|
|
@@ -32,10 +32,8 @@ module.exports = function(core) {
|
|
|
32
32
|
scopes: { sources, instrumentation },
|
|
33
33
|
patcher,
|
|
34
34
|
assess: {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
eventFactory: { createPropagationEvent },
|
|
38
|
-
},
|
|
35
|
+
eventFactory: { createPropagationEvent },
|
|
36
|
+
dataflow: { tracker },
|
|
39
37
|
}
|
|
40
38
|
} = core;
|
|
41
39
|
|
|
@@ -20,10 +20,8 @@ const { patchType } = require('../../common');
|
|
|
20
20
|
module.exports = function(core) {
|
|
21
21
|
const {
|
|
22
22
|
assess: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
eventFactory: { createPropagationEvent },
|
|
26
|
-
},
|
|
23
|
+
eventFactory: { createPropagationEvent },
|
|
24
|
+
dataflow: { tracker },
|
|
27
25
|
},
|
|
28
26
|
patcher,
|
|
29
27
|
scopes: { sources, instrumentation },
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { callChildComponentMethodsSync } = require('@contrast/common');
|
|
19
|
+
|
|
20
|
+
module.exports = function(core) {
|
|
21
|
+
const joiInstrumentation = core.assess.dataflow.propagation.joiInstrumentation = {
|
|
22
|
+
install() {
|
|
23
|
+
callChildComponentMethodsSync(joiInstrumentation, 'install');
|
|
24
|
+
},
|
|
25
|
+
uninstall() {
|
|
26
|
+
callChildComponentMethodsSync(joiInstrumentation, 'uninstall');
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
require('./keys')(core);
|
|
31
|
+
require('./string-schema')(core);
|
|
32
|
+
require('./values')(core);
|
|
33
|
+
|
|
34
|
+
return joiInstrumentation;
|
|
35
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
isNonEmptyObject, join,
|
|
20
|
+
} = require('@contrast/common');
|
|
21
|
+
const { patchType } = require('../../common');
|
|
22
|
+
|
|
23
|
+
module.exports = function(core) {
|
|
24
|
+
const {
|
|
25
|
+
depHooks,
|
|
26
|
+
patcher,
|
|
27
|
+
} = core;
|
|
28
|
+
|
|
29
|
+
function addMetadata(schema, refTargetPath, refPath, isInReference) {
|
|
30
|
+
if (!schema.__CONTRAST__) {
|
|
31
|
+
Object.defineProperty(schema, '__CONTRAST__', {
|
|
32
|
+
enumerable: false,
|
|
33
|
+
configurable: true,
|
|
34
|
+
value: {
|
|
35
|
+
inReferenceTargets: new Set(),
|
|
36
|
+
refTargets: {}
|
|
37
|
+
},
|
|
38
|
+
writable: true,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let path = join(refTargetPath, '.');
|
|
43
|
+
|
|
44
|
+
if (isInReference) {
|
|
45
|
+
path = join(refTargetPath.slice(0, -1), '.');
|
|
46
|
+
schema.__CONTRAST__.inReferenceTargets.add(path);
|
|
47
|
+
refPath = refPath.slice(0, -1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const refs = schema.__CONTRAST__.refTargets[path] || [];
|
|
51
|
+
refs.push(join(refPath, '.'));
|
|
52
|
+
schema.__CONTRAST__.refTargets[path] = refs;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function traverseChildSchemas(schema, refTargetPath, currentPath, refOpts) {
|
|
56
|
+
const traversable = schema.type === 'object' ? schema._ids._byKey.entries() : Object.entries(schema.$_terms.items);
|
|
57
|
+
|
|
58
|
+
for (const [childKey, item] of traversable) {
|
|
59
|
+
const value = schema.type === 'object' ? item.schema : item;
|
|
60
|
+
const newRefTargetPath = [...refTargetPath, childKey];
|
|
61
|
+
const newCurrentPath = [...currentPath, childKey];
|
|
62
|
+
|
|
63
|
+
if (value.type === 'string') {
|
|
64
|
+
addMetadata(value, newRefTargetPath, newCurrentPath, refOpts.in);
|
|
65
|
+
} else if (value.type === 'object') {
|
|
66
|
+
traverseChildSchemas(value, newRefTargetPath, newCurrentPath, refOpts);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function traverseSchemas(
|
|
72
|
+
joi,
|
|
73
|
+
currentSchema,
|
|
74
|
+
obj,
|
|
75
|
+
ancestorRef = [],
|
|
76
|
+
currentPath = [],
|
|
77
|
+
) {
|
|
78
|
+
ancestorRef.unshift(obj);
|
|
79
|
+
if (joi.isSchema(currentSchema) || joi.isExpression(currentSchema)) return;
|
|
80
|
+
if (currentSchema && joi.isRef(currentSchema) && !currentSchema.__CONTRAST__?.isVisited) {
|
|
81
|
+
const targetSchemaRef = currentSchema.path.reduce((acc, value) => {
|
|
82
|
+
let ret = acc?.[value] || acc;
|
|
83
|
+
|
|
84
|
+
if (joi.isSchema(acc)) {
|
|
85
|
+
ret = acc?.$_terms?.keys.find(i => i.key === value);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return ret;
|
|
89
|
+
}, ancestorRef[currentSchema.ancestor - 1]);
|
|
90
|
+
|
|
91
|
+
const refTargetPath = currentSchema.absolute({ path: currentPath });
|
|
92
|
+
const targetSchemaInstace =
|
|
93
|
+
typeof targetSchemaRef?.schema === 'object'
|
|
94
|
+
? targetSchemaRef.schema
|
|
95
|
+
: targetSchemaRef;
|
|
96
|
+
|
|
97
|
+
if (!targetSchemaInstace) return;
|
|
98
|
+
|
|
99
|
+
if (['object', 'array'].includes(targetSchemaInstace.type)) {
|
|
100
|
+
traverseChildSchemas(targetSchemaInstace, refTargetPath, currentPath, currentSchema);
|
|
101
|
+
} else {
|
|
102
|
+
addMetadata(targetSchemaInstace, refTargetPath, currentPath);
|
|
103
|
+
}
|
|
104
|
+
Object.defineProperty(currentSchema, '__CONTRAST__', {
|
|
105
|
+
enumerable: false,
|
|
106
|
+
configurable: true,
|
|
107
|
+
value: {
|
|
108
|
+
isVisited: true,
|
|
109
|
+
},
|
|
110
|
+
writable: true
|
|
111
|
+
});
|
|
112
|
+
} else {
|
|
113
|
+
if (isNonEmptyObject(currentSchema)) {
|
|
114
|
+
for (const [objKey, objValue] of Object.entries(currentSchema)) {
|
|
115
|
+
traverseSchemas(joi, objValue, currentSchema, ancestorRef, [...currentPath, objKey]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return (core.assess.dataflow.propagation.joiInstrumentation.keys = {
|
|
122
|
+
install() {
|
|
123
|
+
depHooks.resolve(
|
|
124
|
+
{ name: 'joi', file: 'lib/types/keys.js', version: '>=17.0.0' },
|
|
125
|
+
(joi) => {
|
|
126
|
+
patcher.patch(Object.getPrototypeOf(joi), 'keys', {
|
|
127
|
+
name: 'joi.keys',
|
|
128
|
+
patchType,
|
|
129
|
+
pre(data) {
|
|
130
|
+
const [value] = data.args;
|
|
131
|
+
const joi = data.obj.$_root;
|
|
132
|
+
|
|
133
|
+
traverseSchemas(joi, value, value);
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
};
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
DataflowTag: { ALPHANUM_SPACE_HYPHEN, LIMITED_CHARS, STRING_TYPE_CHECKED },
|
|
20
|
+
inspect,
|
|
21
|
+
join,
|
|
22
|
+
split,
|
|
23
|
+
} = require('@contrast/common');
|
|
24
|
+
const { createFullLengthCopyTags } = require('../../../tag-utils');
|
|
25
|
+
const { patchType } = require('../../common');
|
|
26
|
+
const VALIDATORS = {
|
|
27
|
+
base64: ALPHANUM_SPACE_HYPHEN,
|
|
28
|
+
guid: ALPHANUM_SPACE_HYPHEN,
|
|
29
|
+
alphanum: ALPHANUM_SPACE_HYPHEN,
|
|
30
|
+
hex: ALPHANUM_SPACE_HYPHEN,
|
|
31
|
+
isoDate: ALPHANUM_SPACE_HYPHEN,
|
|
32
|
+
isoDuration: ALPHANUM_SPACE_HYPHEN,
|
|
33
|
+
token: ALPHANUM_SPACE_HYPHEN,
|
|
34
|
+
creditCard: LIMITED_CHARS,
|
|
35
|
+
ip: LIMITED_CHARS,
|
|
36
|
+
hostname: ALPHANUM_SPACE_HYPHEN,
|
|
37
|
+
domain: ALPHANUM_SPACE_HYPHEN,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = function(core) {
|
|
41
|
+
const {
|
|
42
|
+
depHooks,
|
|
43
|
+
scopes: { sources, instrumentation },
|
|
44
|
+
patcher,
|
|
45
|
+
assess: {
|
|
46
|
+
eventFactory: { createPropagationEvent },
|
|
47
|
+
dataflow: { tracker },
|
|
48
|
+
},
|
|
49
|
+
} = core;
|
|
50
|
+
|
|
51
|
+
function definePropagation(methodName, tagName, inspectedSchema, origFn) {
|
|
52
|
+
function propagationFn(strInfo) {
|
|
53
|
+
const event = createPropagationEvent({
|
|
54
|
+
addedTags: [tagName],
|
|
55
|
+
name: `Joi.string.${methodName}`,
|
|
56
|
+
moduleName: 'joi',
|
|
57
|
+
methodName: `string.${methodName}`,
|
|
58
|
+
history: [{ ...strInfo }],
|
|
59
|
+
object: {
|
|
60
|
+
tracked: false,
|
|
61
|
+
value: 'Joi.string',
|
|
62
|
+
},
|
|
63
|
+
args: [
|
|
64
|
+
{ tracked: true, value: strInfo.value },
|
|
65
|
+
{ tracked: false, value: inspectedSchema },
|
|
66
|
+
],
|
|
67
|
+
result: {
|
|
68
|
+
tracked: false,
|
|
69
|
+
value: undefined,
|
|
70
|
+
},
|
|
71
|
+
source: 'P0',
|
|
72
|
+
tags: {
|
|
73
|
+
...strInfo.tags,
|
|
74
|
+
[tagName]: [0, strInfo.value.length - 1],
|
|
75
|
+
},
|
|
76
|
+
target: 'P0',
|
|
77
|
+
stacktraceOpts: {
|
|
78
|
+
prependFrames: [origFn],
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (event) {
|
|
83
|
+
Object.assign(strInfo, event);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Object.defineProperty(propagationFn, 'name', {
|
|
88
|
+
value: tagName,
|
|
89
|
+
writable: false,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return propagationFn;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getRefInstancesTrackingData(obj, refInstancesPaths) {
|
|
96
|
+
return refInstancesPaths
|
|
97
|
+
.map((referenceInstance) => {
|
|
98
|
+
const value = split(referenceInstance, '.').reduce(
|
|
99
|
+
(acc, v) => acc[v] || acc,
|
|
100
|
+
obj
|
|
101
|
+
);
|
|
102
|
+
return tracker.getData(value);
|
|
103
|
+
})
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function patchValidator(
|
|
108
|
+
validatorObj,
|
|
109
|
+
patchName,
|
|
110
|
+
validatorName,
|
|
111
|
+
tagName,
|
|
112
|
+
) {
|
|
113
|
+
patcher.patch(validatorObj, 'validate', {
|
|
114
|
+
name: patchName,
|
|
115
|
+
patchType,
|
|
116
|
+
post(data) {
|
|
117
|
+
const [input, schema] = data.args;
|
|
118
|
+
|
|
119
|
+
if (
|
|
120
|
+
!input ||
|
|
121
|
+
(validatorName !== 'validate' && typeof data.result !== 'string') ||
|
|
122
|
+
(validatorName === 'validate' && data.result) ||
|
|
123
|
+
!sources.getStore()?.assess ||
|
|
124
|
+
instrumentation.isLocked()
|
|
125
|
+
)
|
|
126
|
+
return;
|
|
127
|
+
|
|
128
|
+
const contrastData = schema?.schema?.__CONTRAST__;
|
|
129
|
+
let refTargetPath = join(schema.state.path, '.');
|
|
130
|
+
const inReferenceTargetPath = join(schema.state.path.slice(0, -1), '.');
|
|
131
|
+
if (contrastData?.inReferenceTargets.has(inReferenceTargetPath)) {
|
|
132
|
+
refTargetPath = join(
|
|
133
|
+
schema.state.path.slice(0, -1),
|
|
134
|
+
'.'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const references = contrastData?.refTargets[refTargetPath];
|
|
138
|
+
|
|
139
|
+
const strInfo = tracker.getData(input);
|
|
140
|
+
|
|
141
|
+
const inspectedSchema = inspect(schema);
|
|
142
|
+
const validation = definePropagation(
|
|
143
|
+
validatorName,
|
|
144
|
+
tagName,
|
|
145
|
+
inspectedSchema,
|
|
146
|
+
data.orig
|
|
147
|
+
);
|
|
148
|
+
if (references?.length) {
|
|
149
|
+
getRefInstancesTrackingData(
|
|
150
|
+
schema.state.ancestors[schema.state.ancestors.length - 1],
|
|
151
|
+
references
|
|
152
|
+
).forEach((refMetadata) => {
|
|
153
|
+
let { eventualValidations } = refMetadata;
|
|
154
|
+
if (!eventualValidations) {
|
|
155
|
+
eventualValidations = { [refTargetPath]: [validation] };
|
|
156
|
+
} else if (!eventualValidations[refTargetPath]) {
|
|
157
|
+
eventualValidations[refTargetPath] = [validation];
|
|
158
|
+
} else if (
|
|
159
|
+
!eventualValidations[refTargetPath].find(
|
|
160
|
+
(v) => v.name === tagName
|
|
161
|
+
)
|
|
162
|
+
) {
|
|
163
|
+
eventualValidations[refTargetPath].push(validation);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
refMetadata.eventualValidations = eventualValidations;
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (strInfo) {
|
|
171
|
+
validation(strInfo);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function reTrackCoercedValue(coerce) {
|
|
178
|
+
patcher.patch(coerce, 'method', {
|
|
179
|
+
name: 'joi.string._definition.coerce',
|
|
180
|
+
patchType,
|
|
181
|
+
post(data) {
|
|
182
|
+
const { args, result } = data;
|
|
183
|
+
|
|
184
|
+
if (
|
|
185
|
+
!args[0] ||
|
|
186
|
+
// currently, we are losing track of coerced isoDate only
|
|
187
|
+
!args[1].schema.$_getRule('isoDate') ||
|
|
188
|
+
!sources.getStore()?.assess ||
|
|
189
|
+
instrumentation.isLocked()
|
|
190
|
+
)
|
|
191
|
+
return;
|
|
192
|
+
|
|
193
|
+
const argInfo = tracker.getData(args[0]);
|
|
194
|
+
|
|
195
|
+
if (!argInfo) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const event = createPropagationEvent({
|
|
200
|
+
name: 'Joi.string.isoDate.coerce',
|
|
201
|
+
moduleName: 'joi',
|
|
202
|
+
methodName: 'string.isDate.coerce',
|
|
203
|
+
history: [argInfo],
|
|
204
|
+
object: {
|
|
205
|
+
tracked: false,
|
|
206
|
+
value: 'Joi.string',
|
|
207
|
+
},
|
|
208
|
+
args: [
|
|
209
|
+
{ tracked: true, value: argInfo.value },
|
|
210
|
+
{ tracked: false, value: inspect(args[1]) },
|
|
211
|
+
],
|
|
212
|
+
result: {
|
|
213
|
+
tracked: false,
|
|
214
|
+
value: result,
|
|
215
|
+
},
|
|
216
|
+
source: 'P0',
|
|
217
|
+
tags: createFullLengthCopyTags(argInfo.tags, result.value.length),
|
|
218
|
+
target: 'R',
|
|
219
|
+
stacktraceOpts: {
|
|
220
|
+
prependFrames: [data.orig],
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
const { extern } = tracker.track(result.value, event);
|
|
225
|
+
|
|
226
|
+
if (extern) {
|
|
227
|
+
data.result.value = extern;
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return (core.assess.dataflow.propagation.joiInstrumentation.stringSchema = {
|
|
234
|
+
install() {
|
|
235
|
+
depHooks.resolve(
|
|
236
|
+
{ name: 'joi', file: 'lib/types/string.js', version: '>=17.0.0' },
|
|
237
|
+
(stringType) => {
|
|
238
|
+
const stringTypePrototype = Object.getPrototypeOf(stringType);
|
|
239
|
+
const definition = stringTypePrototype?._definition;
|
|
240
|
+
const rules = definition?.rules || {};
|
|
241
|
+
|
|
242
|
+
patchValidator(
|
|
243
|
+
definition,
|
|
244
|
+
'joi.string.validate',
|
|
245
|
+
'validate',
|
|
246
|
+
STRING_TYPE_CHECKED
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
for (const rule in VALIDATORS) {
|
|
250
|
+
if (rules[rule]) {
|
|
251
|
+
patchValidator(
|
|
252
|
+
rules[rule],
|
|
253
|
+
'joi.string._definition.rules',
|
|
254
|
+
rule,
|
|
255
|
+
VALIDATORS[rule],
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const coerce = definition?.coerce;
|
|
261
|
+
|
|
262
|
+
if (coerce && rules['isoDate']) {
|
|
263
|
+
reTrackCoercedValue(coerce);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
};
|