@contrast/assess 1.10.0 → 1.11.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/dataflow/event-factory.js +1 -1
- package/lib/dataflow/index.js +1 -1
- package/lib/dataflow/propagation/common.js +1 -1
- package/lib/dataflow/propagation/index.js +2 -1
- package/lib/dataflow/propagation/install/JSON/index.js +1 -1
- package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
- package/lib/dataflow/propagation/install/JSON/parse.js +1 -1
- package/lib/dataflow/propagation/install/JSON/stringify.js +1 -1
- package/lib/dataflow/propagation/install/array-prototype-join.js +1 -1
- package/lib/dataflow/propagation/install/buffer.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/add.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/index.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/number.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/string.js +1 -1
- package/lib/dataflow/propagation/install/contrast-methods/tag.js +1 -1
- package/lib/dataflow/propagation/install/decode-uri-component.js +1 -1
- package/lib/dataflow/propagation/install/ejs/escape-xml.js +1 -1
- package/lib/dataflow/propagation/install/ejs/index.js +1 -1
- package/lib/dataflow/propagation/install/encode-uri-component.js +1 -1
- package/lib/dataflow/propagation/install/escape-html.js +1 -1
- package/lib/dataflow/propagation/install/escape.js +1 -1
- package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +1 -1
- package/lib/dataflow/propagation/install/isnumeric-0.js +1 -1
- package/lib/dataflow/propagation/install/mongoose/common.js +20 -0
- package/lib/dataflow/propagation/install/mongoose/index.js +5 -9
- package/lib/dataflow/propagation/install/mongoose/schema-map.js +149 -0
- package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +162 -0
- package/lib/dataflow/propagation/install/mongoose/schema-string.js +91 -37
- package/lib/dataflow/propagation/install/mysql-connection-escape.js +1 -1
- package/lib/dataflow/propagation/install/parse-int.js +1 -1
- package/lib/dataflow/propagation/install/path/basename.js +1 -1
- package/lib/dataflow/propagation/install/path/common.js +1 -1
- package/lib/dataflow/propagation/install/path/index.js +1 -1
- package/lib/dataflow/propagation/install/path/join-and-resolve.js +1 -1
- package/lib/dataflow/propagation/install/path/normalize.js +1 -1
- package/lib/dataflow/propagation/install/pug/index.js +1 -1
- package/lib/dataflow/propagation/install/pug-runtime-escape.js +1 -1
- package/lib/dataflow/propagation/install/querystring/index.js +1 -1
- package/lib/dataflow/propagation/install/querystring/parse.js +1 -1
- package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +182 -0
- package/lib/dataflow/propagation/install/sequelize.js +1 -1
- package/lib/dataflow/propagation/install/sql-template-strings.js +1 -1
- package/lib/dataflow/propagation/install/string/concat.js +1 -1
- package/lib/dataflow/propagation/install/string/format-methods.js +1 -1
- package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
- package/lib/dataflow/propagation/install/string/index.js +65 -1
- package/lib/dataflow/propagation/install/string/match-all.js +236 -0
- package/lib/dataflow/propagation/install/string/match.js +83 -37
- package/lib/dataflow/propagation/install/string/replace.js +2 -2
- package/lib/dataflow/propagation/install/string/slice.js +1 -1
- package/lib/dataflow/propagation/install/string/split.js +1 -1
- package/lib/dataflow/propagation/install/string/substring.js +1 -1
- package/lib/dataflow/propagation/install/string/trim.js +1 -1
- package/lib/dataflow/propagation/install/unescape.js +1 -1
- package/lib/dataflow/propagation/install/url/domain-parsers.js +1 -1
- package/lib/dataflow/propagation/install/url/index.js +3 -1
- package/lib/dataflow/propagation/install/url/parse.js +131 -0
- package/lib/dataflow/propagation/install/url/searchParams.js +133 -0
- package/lib/dataflow/propagation/install/url/url.js +9 -52
- package/lib/dataflow/propagation/install/validator/hooks.js +1 -1
- package/lib/dataflow/propagation/install/validator/index.js +1 -1
- package/lib/dataflow/propagation/install/validator/methods.js +1 -1
- package/lib/dataflow/sinks/common.js +1 -1
- package/lib/dataflow/sinks/index.js +1 -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/index.js +1 -1
- package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/fastify/index.js +1 -1
- package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +1 -1
- package/lib/dataflow/sinks/install/fs.js +1 -1
- package/lib/dataflow/sinks/install/function.js +1 -1
- package/lib/dataflow/sinks/install/http/index.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/index.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 +31 -24
- package/lib/dataflow/sinks/install/mssql.js +1 -1
- package/lib/dataflow/sinks/install/mysql.js +1 -1
- 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/common.js +1 -1
- package/lib/dataflow/sources/handler.js +1 -1
- package/lib/dataflow/sources/index.js +1 -1
- package/lib/dataflow/sources/install/body-parser1.js +1 -1
- package/lib/dataflow/sources/install/busboy1.js +1 -1
- package/lib/dataflow/sources/install/cookie-parser1.js +1 -1
- package/lib/dataflow/sources/install/express/index.js +1 -1
- package/lib/dataflow/sources/install/express/params.js +1 -1
- package/lib/dataflow/sources/install/express/parsedUrl.js +1 -1
- package/lib/dataflow/sources/install/fastify/fastify.js +1 -1
- package/lib/dataflow/sources/install/fastify/index.js +1 -1
- package/lib/dataflow/sources/install/formidable1.js +1 -1
- package/lib/dataflow/sources/install/http.js +1 -1
- package/lib/dataflow/sources/install/koa/index.js +1 -1
- package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +1 -1
- package/lib/dataflow/sources/install/koa/koa-routers.js +1 -1
- package/lib/dataflow/sources/install/koa/koa2.js +1 -1
- package/lib/dataflow/sources/install/qs6.js +1 -1
- package/lib/dataflow/sources/install/querystring.js +1 -1
- package/lib/dataflow/tag-utils.js +1 -1
- package/lib/dataflow/tracker.js +1 -1
- package/lib/dataflow/utils/is-safe-content-type.js +1 -1
- package/lib/dataflow/utils/is-vulnerable.js +1 -1
- package/lib/index.js +1 -1
- package/lib/response-scanning/handlers/index.js +36 -30
- package/lib/response-scanning/handlers/utils.js +1 -1
- package/lib/response-scanning/index.js +1 -1
- package/lib/response-scanning/install/http.js +3 -3
- package/lib/session-configuration/index.js +1 -1
- package/lib/session-configuration/install/http.js +1 -1
- package/package.json +2 -2
package/lib/dataflow/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -44,6 +44,7 @@ module.exports = function(core) {
|
|
|
44
44
|
require('./install/sequelize')(core);
|
|
45
45
|
require('./install/JSON')(core);
|
|
46
46
|
require('./install/path')(core);
|
|
47
|
+
require('./install/reg-exp-prototype-exec')(core);
|
|
47
48
|
|
|
48
49
|
propagation.install = function() {
|
|
49
50
|
callChildComponentMethodsSync(propagation, 'install');
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
module.exports = {
|
|
19
|
+
userDefinedType: 'user defined',
|
|
20
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2023 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -15,22 +15,18 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const { callChildComponentMethodsSync } = require('@contrast/common');
|
|
19
19
|
|
|
20
20
|
module.exports = function(core) {
|
|
21
21
|
const component = core.assess.dataflow.propagation.mongooseInstrumentation = {
|
|
22
22
|
install() {
|
|
23
|
-
|
|
23
|
+
callChildComponentMethodsSync(component, 'install');
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
// todo NODE-3103
|
|
28
|
-
// require('./schema-map')(core);
|
|
29
|
-
|
|
30
|
-
// todo NODE-3102
|
|
31
|
-
// require('./schema-mixed')(core);
|
|
32
|
-
|
|
33
27
|
require('./schema-string')(core);
|
|
28
|
+
require('./schema-mixed')(core);
|
|
29
|
+
require('./schema-map')(core);
|
|
34
30
|
|
|
35
31
|
return component;
|
|
36
32
|
};
|
|
@@ -0,0 +1,149 @@
|
|
|
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
|
+
'use strict';
|
|
16
|
+
const { patchType } = require('../../common');
|
|
17
|
+
const { userDefinedType } = require('./common');
|
|
18
|
+
const { traverseValues, DataflowTag, substring } = require('@contrast/common');
|
|
19
|
+
|
|
20
|
+
module.exports = function (core) {
|
|
21
|
+
const {
|
|
22
|
+
config: { assess },
|
|
23
|
+
scopes: { sources },
|
|
24
|
+
patcher,
|
|
25
|
+
depHooks,
|
|
26
|
+
assess: {
|
|
27
|
+
dataflow: {
|
|
28
|
+
tracker,
|
|
29
|
+
eventFactory: { createPropagationEvent },
|
|
30
|
+
propagation: { mongooseInstrumentation },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} = core;
|
|
34
|
+
|
|
35
|
+
const schemaMap = {};
|
|
36
|
+
mongooseInstrumentation.schemaMap = schemaMap;
|
|
37
|
+
|
|
38
|
+
const handleString = (strInfo, orig, value, name) => {
|
|
39
|
+
const methodName = substring(name, name.indexOf('.') + 1);
|
|
40
|
+
|
|
41
|
+
// copy because we mutate the metadata value inline
|
|
42
|
+
const history = [{ ...strInfo }];
|
|
43
|
+
const event = createPropagationEvent({
|
|
44
|
+
addedTags: [DataflowTag.CUSTOM_VALIDATED],
|
|
45
|
+
name,
|
|
46
|
+
moduleName: 'mongoose',
|
|
47
|
+
methodName,
|
|
48
|
+
history,
|
|
49
|
+
object: {
|
|
50
|
+
tracked: false,
|
|
51
|
+
value: 'mongoose.SchemaMap',
|
|
52
|
+
},
|
|
53
|
+
args: [{ tracked: true, value: strInfo.value }],
|
|
54
|
+
result: {
|
|
55
|
+
tracked: false,
|
|
56
|
+
value: undefined,
|
|
57
|
+
},
|
|
58
|
+
source: 'P0',
|
|
59
|
+
tags: {
|
|
60
|
+
...strInfo.tags,
|
|
61
|
+
[DataflowTag.CUSTOM_VALIDATED]: [0, value.length - 1],
|
|
62
|
+
},
|
|
63
|
+
target: 'P0',
|
|
64
|
+
stacktraceOpts: {
|
|
65
|
+
prependFrames: [orig],
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!event) return;
|
|
70
|
+
|
|
71
|
+
// in case the event type changed e.g. Source->Propagation
|
|
72
|
+
for (const key of Object.keys(strInfo)) {
|
|
73
|
+
if (key === 'value' || key === 'extern') continue;
|
|
74
|
+
delete strInfo[key];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Object.assign(strInfo, event);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const mapInstrumentation = (data, name) => {
|
|
81
|
+
const { orig, args } = data;
|
|
82
|
+
|
|
83
|
+
const hasCustomValidator = data.obj.validators.some(
|
|
84
|
+
(validator) => validator.type === userDefinedType
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (!hasCustomValidator) return;
|
|
88
|
+
|
|
89
|
+
const input = args[0].toJSON();
|
|
90
|
+
|
|
91
|
+
const weakMapOfStrInfo = new WeakMap();
|
|
92
|
+
traverseValues(input, (path, type, value) => {
|
|
93
|
+
const strInfo = tracker.getData(value);
|
|
94
|
+
if (!strInfo || weakMapOfStrInfo.has(strInfo)) return;
|
|
95
|
+
weakMapOfStrInfo.set(strInfo, true);
|
|
96
|
+
|
|
97
|
+
handleString(strInfo, orig, value, name);
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
schemaMap.install = function () {
|
|
102
|
+
depHooks.resolve(
|
|
103
|
+
{ name: 'mongoose', file: 'lib/schema/map.js', version: '>=5.0.0' },
|
|
104
|
+
(SchemaMap) => {
|
|
105
|
+
const doValidateSyncName = 'mongoose.map.prototype.doValidateSync';
|
|
106
|
+
patcher.patch(SchemaMap.prototype, 'doValidateSync', {
|
|
107
|
+
name: doValidateSyncName,
|
|
108
|
+
patchType,
|
|
109
|
+
post: (data) => {
|
|
110
|
+
if (!assess.trust_custom_validators || data.result || !sources.getStore()?.assess) return;
|
|
111
|
+
|
|
112
|
+
mapInstrumentation(data, doValidateSyncName);
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// called when `Model.validate(data)` static method is used, as well as `model.validate()` instance method
|
|
117
|
+
const doValidateName = 'mongoose.map.prototype.doValidate';
|
|
118
|
+
patcher.patch(SchemaMap.prototype, 'doValidate', {
|
|
119
|
+
name: doValidateName,
|
|
120
|
+
patchType,
|
|
121
|
+
pre: (data) => {
|
|
122
|
+
if (!assess.trust_custom_validators) return;
|
|
123
|
+
|
|
124
|
+
const [value, cb] = data.args;
|
|
125
|
+
if (
|
|
126
|
+
!value ||
|
|
127
|
+
typeof cb !== 'function' ||
|
|
128
|
+
!sources.getStore()?.assess
|
|
129
|
+
) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
data.args[1] = patcher.patch(cb, {
|
|
134
|
+
name: doValidateName,
|
|
135
|
+
patchType,
|
|
136
|
+
pre({ args: [err] }) {
|
|
137
|
+
if (err) return;
|
|
138
|
+
|
|
139
|
+
mapInstrumentation(data, doValidateName);
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return schemaMap;
|
|
149
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
'use strict';
|
|
16
|
+
const { patchType } = require('../../common');
|
|
17
|
+
const { userDefinedType } = require('./common');
|
|
18
|
+
const { traverseValues, DataflowTag, substring } = require('@contrast/common');
|
|
19
|
+
|
|
20
|
+
module.exports = function (core) {
|
|
21
|
+
const {
|
|
22
|
+
config: { assess },
|
|
23
|
+
scopes: { sources },
|
|
24
|
+
patcher,
|
|
25
|
+
depHooks,
|
|
26
|
+
assess: {
|
|
27
|
+
dataflow: {
|
|
28
|
+
tracker,
|
|
29
|
+
eventFactory: { createPropagationEvent },
|
|
30
|
+
propagation: { mongooseInstrumentation },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
} = core;
|
|
34
|
+
|
|
35
|
+
const schemaMixed = {};
|
|
36
|
+
mongooseInstrumentation.schemaMixed = schemaMixed;
|
|
37
|
+
|
|
38
|
+
const handleString = (strInfo, orig, value, name) => {
|
|
39
|
+
const methodName = substring(name, name.indexOf('.') + 1);
|
|
40
|
+
|
|
41
|
+
// copy because we mutate the metadata value inline
|
|
42
|
+
const history = [{ ...strInfo }];
|
|
43
|
+
const event = createPropagationEvent({
|
|
44
|
+
addedTags: [DataflowTag.CUSTOM_VALIDATED],
|
|
45
|
+
name,
|
|
46
|
+
moduleName: 'mongoose',
|
|
47
|
+
methodName,
|
|
48
|
+
history,
|
|
49
|
+
object: {
|
|
50
|
+
tracked: false,
|
|
51
|
+
value: 'mongoose.SchemaMixed',
|
|
52
|
+
},
|
|
53
|
+
args: [{ tracked: true, value: strInfo.value }],
|
|
54
|
+
result: {
|
|
55
|
+
tracked: false,
|
|
56
|
+
value: undefined,
|
|
57
|
+
},
|
|
58
|
+
source: 'P0',
|
|
59
|
+
tags: {
|
|
60
|
+
...strInfo.tags,
|
|
61
|
+
[DataflowTag.CUSTOM_VALIDATED]: [0, value.length - 1],
|
|
62
|
+
},
|
|
63
|
+
target: 'P0',
|
|
64
|
+
stacktraceOpts: {
|
|
65
|
+
prependFrames: [orig],
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!event) return;
|
|
70
|
+
|
|
71
|
+
// in case the event type changed e.g. Source->Propagation
|
|
72
|
+
for (const key of Object.keys(strInfo)) {
|
|
73
|
+
if (key === 'value' || key === 'extern') continue;
|
|
74
|
+
delete strInfo[key];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Object.assign(strInfo, event);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const mixedInstrumentation = (data, name) => {
|
|
81
|
+
const hasCustomValidator = data.obj.validators.some(
|
|
82
|
+
(validator) => validator.type === userDefinedType
|
|
83
|
+
);
|
|
84
|
+
if (!hasCustomValidator) return;
|
|
85
|
+
|
|
86
|
+
const { orig, args } = data;
|
|
87
|
+
|
|
88
|
+
const input = args[0];
|
|
89
|
+
const inputType = typeof input;
|
|
90
|
+
|
|
91
|
+
if (inputType !== 'string' && inputType !== 'object') return;
|
|
92
|
+
|
|
93
|
+
if (inputType === 'string') {
|
|
94
|
+
const strInfo = tracker.getData(input);
|
|
95
|
+
if (!strInfo) return;
|
|
96
|
+
|
|
97
|
+
return handleString(strInfo, orig, input, name);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const weakMapOfStrInfo = new WeakMap();
|
|
101
|
+
traverseValues(input, (path, type, value) => {
|
|
102
|
+
const strInfo = tracker.getData(value);
|
|
103
|
+
if (!strInfo || weakMapOfStrInfo.has(strInfo)) return;
|
|
104
|
+
weakMapOfStrInfo.set(strInfo, true);
|
|
105
|
+
|
|
106
|
+
handleString(strInfo, orig, value, name);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
schemaMixed.install = function () {
|
|
111
|
+
depHooks.resolve(
|
|
112
|
+
{ name: 'mongoose', file: 'lib/schema/mixed.js', version: '>=5.0.0' },
|
|
113
|
+
(SchemaMixed) => {
|
|
114
|
+
const doValidateSyncName = 'mongoose.mixed.prototype.doValidateSync';
|
|
115
|
+
patcher.patch(SchemaMixed.prototype, 'doValidateSync', {
|
|
116
|
+
name: doValidateSyncName,
|
|
117
|
+
patchType,
|
|
118
|
+
post: (data) => {
|
|
119
|
+
if (
|
|
120
|
+
!assess.trust_custom_validators ||
|
|
121
|
+
data.result ||
|
|
122
|
+
!sources.getStore()?.assess
|
|
123
|
+
) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
mixedInstrumentation(data, doValidateSyncName);
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// called when `Model.validate(data)` static method is used, as well as `model.validate()` instance method
|
|
132
|
+
const doValidateName = 'mongoose.mixed.prototype.doValidate';
|
|
133
|
+
patcher.patch(SchemaMixed.prototype, 'doValidate', {
|
|
134
|
+
name: doValidateName,
|
|
135
|
+
patchType,
|
|
136
|
+
pre: (data) => {
|
|
137
|
+
if (!assess.trust_custom_validators || !sources.getStore()?.assess) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const [value, cb] = data.args;
|
|
142
|
+
if (!value || typeof cb !== 'function') {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
data.args[1] = patcher.patch(cb, {
|
|
147
|
+
name: doValidateName,
|
|
148
|
+
patchType,
|
|
149
|
+
pre({ args: [err] }) {
|
|
150
|
+
if (err) return;
|
|
151
|
+
|
|
152
|
+
mixedInstrumentation(data, doValidateName);
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
return schemaMixed;
|
|
162
|
+
};
|