@contrast/assess 1.10.0 → 1.12.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.
Files changed (119) hide show
  1. package/lib/dataflow/index.js +1 -2
  2. package/lib/dataflow/propagation/common.js +1 -1
  3. package/lib/dataflow/propagation/index.js +2 -1
  4. package/lib/dataflow/propagation/install/JSON/index.js +1 -1
  5. package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
  6. package/lib/dataflow/propagation/install/JSON/parse.js +3 -5
  7. package/lib/dataflow/propagation/install/JSON/stringify.js +3 -2
  8. package/lib/dataflow/propagation/install/array-prototype-join.js +3 -2
  9. package/lib/dataflow/propagation/install/buffer.js +3 -5
  10. package/lib/dataflow/propagation/install/contrast-methods/add.js +3 -2
  11. package/lib/dataflow/propagation/install/contrast-methods/index.js +1 -1
  12. package/lib/dataflow/propagation/install/contrast-methods/number.js +1 -1
  13. package/lib/dataflow/propagation/install/contrast-methods/string.js +3 -5
  14. package/lib/dataflow/propagation/install/contrast-methods/tag.js +3 -5
  15. package/lib/dataflow/propagation/install/decode-uri-component.js +3 -2
  16. package/lib/dataflow/propagation/install/ejs/escape-xml.js +3 -2
  17. package/lib/dataflow/propagation/install/ejs/index.js +1 -1
  18. package/lib/dataflow/propagation/install/encode-uri-component.js +3 -2
  19. package/lib/dataflow/propagation/install/escape-html.js +3 -2
  20. package/lib/dataflow/propagation/install/escape.js +3 -2
  21. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +3 -2
  22. package/lib/dataflow/propagation/install/isnumeric-0.js +1 -1
  23. package/lib/dataflow/propagation/install/mongoose/common.js +20 -0
  24. package/lib/dataflow/propagation/install/mongoose/index.js +5 -9
  25. package/lib/dataflow/propagation/install/mongoose/schema-map.js +149 -0
  26. package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +162 -0
  27. package/lib/dataflow/propagation/install/mongoose/schema-string.js +91 -39
  28. package/lib/dataflow/propagation/install/mysql-connection-escape.js +3 -2
  29. package/lib/dataflow/propagation/install/parse-int.js +1 -1
  30. package/lib/dataflow/propagation/install/path/basename.js +3 -5
  31. package/lib/dataflow/propagation/install/path/common.js +1 -1
  32. package/lib/dataflow/propagation/install/path/index.js +1 -1
  33. package/lib/dataflow/propagation/install/path/join-and-resolve.js +3 -5
  34. package/lib/dataflow/propagation/install/path/normalize.js +3 -5
  35. package/lib/dataflow/propagation/install/pug/index.js +1 -1
  36. package/lib/dataflow/propagation/install/pug-runtime-escape.js +3 -2
  37. package/lib/dataflow/propagation/install/querystring/index.js +1 -1
  38. package/lib/dataflow/propagation/install/querystring/parse.js +3 -2
  39. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +180 -0
  40. package/lib/dataflow/propagation/install/sequelize.js +3 -5
  41. package/lib/dataflow/propagation/install/sql-template-strings.js +3 -2
  42. package/lib/dataflow/propagation/install/string/concat.js +3 -2
  43. package/lib/dataflow/propagation/install/string/format-methods.js +3 -2
  44. package/lib/dataflow/propagation/install/string/html-methods.js +3 -2
  45. package/lib/dataflow/propagation/install/string/index.js +66 -1
  46. package/lib/dataflow/propagation/install/string/match-all.js +236 -0
  47. package/lib/dataflow/propagation/install/string/match.js +83 -37
  48. package/lib/dataflow/propagation/install/string/replace.js +4 -3
  49. package/lib/dataflow/propagation/install/string/slice.js +3 -2
  50. package/lib/dataflow/propagation/install/string/split.js +3 -2
  51. package/lib/dataflow/propagation/install/string/substring.js +3 -2
  52. package/lib/dataflow/propagation/install/string/trim.js +3 -2
  53. package/lib/dataflow/propagation/install/unescape.js +3 -2
  54. package/lib/dataflow/propagation/install/url/domain-parsers.js +3 -2
  55. package/lib/dataflow/propagation/install/url/index.js +3 -1
  56. package/lib/dataflow/propagation/install/url/parse.js +132 -0
  57. package/lib/dataflow/propagation/install/url/searchParams.js +140 -0
  58. package/lib/dataflow/propagation/install/url/url.js +11 -53
  59. package/lib/dataflow/propagation/install/validator/hooks.js +3 -2
  60. package/lib/dataflow/propagation/install/validator/index.js +1 -1
  61. package/lib/dataflow/propagation/install/validator/methods.js +1 -1
  62. package/lib/dataflow/sinks/common.js +1 -1
  63. package/lib/dataflow/sinks/index.js +1 -1
  64. package/lib/dataflow/sinks/install/child-process.js +2 -2
  65. package/lib/dataflow/sinks/install/eval.js +2 -2
  66. package/lib/dataflow/sinks/install/express/index.js +1 -1
  67. package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +3 -3
  68. package/lib/dataflow/sinks/install/fastify/index.js +1 -1
  69. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +2 -2
  70. package/lib/dataflow/sinks/install/fs.js +2 -2
  71. package/lib/dataflow/sinks/install/function.js +2 -2
  72. package/lib/dataflow/sinks/install/http/index.js +1 -1
  73. package/lib/dataflow/sinks/install/http/request.js +2 -2
  74. package/lib/dataflow/sinks/install/http/server-response.js +2 -2
  75. package/lib/dataflow/sinks/install/koa/index.js +1 -1
  76. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +2 -2
  77. package/lib/dataflow/sinks/install/marsdb.js +2 -2
  78. package/lib/dataflow/sinks/install/mongodb.js +33 -26
  79. package/lib/dataflow/sinks/install/mssql.js +2 -2
  80. package/lib/dataflow/sinks/install/mysql.js +3 -3
  81. package/lib/dataflow/sinks/install/postgres.js +2 -2
  82. package/lib/dataflow/sinks/install/sequelize.js +2 -2
  83. package/lib/dataflow/sinks/install/sqlite3.js +2 -2
  84. package/lib/dataflow/sinks/install/vm.js +2 -2
  85. package/lib/dataflow/sources/common.js +1 -1
  86. package/lib/dataflow/sources/handler.js +3 -3
  87. package/lib/dataflow/sources/index.js +1 -1
  88. package/lib/dataflow/sources/install/body-parser1.js +1 -1
  89. package/lib/dataflow/sources/install/busboy1.js +1 -1
  90. package/lib/dataflow/sources/install/cookie-parser1.js +1 -1
  91. package/lib/dataflow/sources/install/express/index.js +1 -1
  92. package/lib/dataflow/sources/install/express/params.js +1 -1
  93. package/lib/dataflow/sources/install/express/parsedUrl.js +1 -1
  94. package/lib/dataflow/sources/install/fastify/fastify.js +1 -1
  95. package/lib/dataflow/sources/install/fastify/index.js +1 -1
  96. package/lib/dataflow/sources/install/formidable1.js +1 -1
  97. package/lib/dataflow/sources/install/http.js +2 -2
  98. package/lib/dataflow/sources/install/koa/index.js +1 -1
  99. package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +1 -1
  100. package/lib/dataflow/sources/install/koa/koa-routers.js +1 -1
  101. package/lib/dataflow/sources/install/koa/koa2.js +1 -1
  102. package/lib/dataflow/sources/install/qs6.js +1 -1
  103. package/lib/dataflow/sources/install/querystring.js +1 -1
  104. package/lib/dataflow/tag-utils.js +1 -1
  105. package/lib/dataflow/tracker.js +2 -6
  106. package/lib/dataflow/utils/is-safe-content-type.js +1 -1
  107. package/lib/dataflow/utils/is-vulnerable.js +1 -1
  108. package/lib/{dataflow/event-factory.js → event-factory.js} +58 -2
  109. package/lib/index.js +4 -2
  110. package/lib/response-scanning/handlers/index.js +36 -30
  111. package/lib/response-scanning/handlers/utils.js +1 -1
  112. package/lib/response-scanning/index.js +1 -1
  113. package/lib/response-scanning/install/http.js +3 -3
  114. package/lib/session-configuration/common.js +19 -0
  115. package/lib/session-configuration/handlers.js +86 -0
  116. package/lib/session-configuration/index.js +6 -9
  117. package/lib/session-configuration/install/express-session.js +131 -0
  118. package/package.json +3 -3
  119. package/lib/session-configuration/install/http.js +0 -79
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -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);
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
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');
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -52,10 +52,8 @@ module.exports = function (core) {
52
52
  scopes: { sources, instrumentation },
53
53
  patcher,
54
54
  assess: {
55
- dataflow: {
56
- tracker,
57
- eventFactory: { createPropagationEvent },
58
- },
55
+ eventFactory: { createPropagationEvent },
56
+ dataflow: { tracker },
59
57
  },
60
58
  } = core;
61
59
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -76,7 +76,8 @@ module.exports = function(core) {
76
76
  scopes: { sources, instrumentation },
77
77
  patcher,
78
78
  assess: {
79
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
79
+ eventFactory: { createPropagationEvent },
80
+ dataflow: { tracker }
80
81
  }
81
82
  } = core;
82
83
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -26,7 +26,8 @@ module.exports = function(core) {
26
26
  scopes: { sources, instrumentation },
27
27
  patcher,
28
28
  assess: {
29
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
29
+ eventFactory: { createPropagationEvent },
30
+ dataflow: { tracker }
30
31
  }
31
32
  } = core;
32
33
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -19,10 +19,8 @@ const { patchType } = require('../common');
19
19
  module.exports = function(core) {
20
20
  const {
21
21
  assess: {
22
- dataflow: {
23
- eventFactory,
24
- tracker
25
- }
22
+ eventFactory,
23
+ dataflow: { tracker }
26
24
  },
27
25
  patcher,
28
26
  } = core;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -26,7 +26,8 @@ module.exports = function(core) {
26
26
  scopes: { instrumentation, sources },
27
27
  patcher,
28
28
  assess: {
29
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
29
+ eventFactory: { createPropagationEvent },
30
+ dataflow: { tracker }
30
31
  }
31
32
  } = core;
32
33
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -32,10 +32,8 @@ module.exports = function(core) {
32
32
  scopes: { sources, instrumentation },
33
33
  patcher,
34
34
  assess: {
35
- dataflow: {
36
- tracker,
37
- eventFactory: { createPropagationEvent },
38
- },
35
+ eventFactory: { createPropagationEvent },
36
+ dataflow: { tracker },
39
37
  }
40
38
  } = core;
41
39
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -20,10 +20,8 @@ const { patchType } = require('../../common');
20
20
  module.exports = function(core) {
21
21
  const {
22
22
  assess: {
23
- dataflow: {
24
- tracker,
25
- eventFactory: { createPropagationEvent },
26
- },
23
+ eventFactory: { createPropagationEvent },
24
+ dataflow: { tracker },
27
25
  },
28
26
  patcher,
29
27
  scopes: { sources, instrumentation },
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -28,7 +28,8 @@ module.exports = function(core) {
28
28
  scopes: { sources, instrumentation },
29
29
  patcher,
30
30
  assess: {
31
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
31
+ eventFactory: { createPropagationEvent },
32
+ dataflow: { tracker }
32
33
  }
33
34
  } = core;
34
35
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -29,7 +29,8 @@ module.exports = function(core) {
29
29
  patcher,
30
30
  depHooks,
31
31
  assess: {
32
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
32
+ eventFactory: { createPropagationEvent },
33
+ dataflow: { tracker }
33
34
  }
34
35
  } = core;
35
36
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -28,7 +28,8 @@ module.exports = function(core) {
28
28
  scopes: { sources, instrumentation },
29
29
  patcher,
30
30
  assess: {
31
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
31
+ eventFactory: { createPropagationEvent },
32
+ dataflow: { tracker }
32
33
  }
33
34
  } = core;
34
35
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -29,7 +29,8 @@ module.exports = function(core) {
29
29
  patcher,
30
30
  depHooks,
31
31
  assess: {
32
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
32
+ eventFactory: { createPropagationEvent },
33
+ dataflow: { tracker }
33
34
  }
34
35
  } = core;
35
36
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -28,7 +28,8 @@ module.exports = function(core) {
28
28
  scopes: { sources, instrumentation },
29
29
  patcher,
30
30
  assess: {
31
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
31
+ eventFactory: { createPropagationEvent },
32
+ dataflow: { tracker }
32
33
  }
33
34
  } = core;
34
35
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -29,7 +29,8 @@ module.exports = function(core) {
29
29
  patcher,
30
30
  depHooks,
31
31
  assess: {
32
- dataflow: { tracker, eventFactory: { createPropagationEvent } }
32
+ eventFactory: { createPropagationEvent },
33
+ dataflow: { tracker }
33
34
  }
34
35
  } = core;
35
36
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright: 2022 Contrast Security, Inc
2
+ * Copyright: 2023 Contrast Security, Inc
3
3
  * Contact: support@contrastsecurity.com
4
4
  * License: Commercial
5
5
 
@@ -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: 2022 Contrast Security, Inc
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 c = require('@contrast/common');
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
- c.callChildComponentMethodsSync(component, 'install');
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
+ eventFactory: { createPropagationEvent },
28
+ dataflow: {
29
+ tracker,
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
+ };