@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.
Files changed (116) hide show
  1. package/lib/dataflow/event-factory.js +1 -1
  2. package/lib/dataflow/index.js +1 -1
  3. package/lib/dataflow/propagation/common.js +1 -1
  4. package/lib/dataflow/propagation/index.js +2 -1
  5. package/lib/dataflow/propagation/install/JSON/index.js +1 -1
  6. package/lib/dataflow/propagation/install/JSON/parse-fn.js +1 -1
  7. package/lib/dataflow/propagation/install/JSON/parse.js +1 -1
  8. package/lib/dataflow/propagation/install/JSON/stringify.js +1 -1
  9. package/lib/dataflow/propagation/install/array-prototype-join.js +1 -1
  10. package/lib/dataflow/propagation/install/buffer.js +1 -1
  11. package/lib/dataflow/propagation/install/contrast-methods/add.js +1 -1
  12. package/lib/dataflow/propagation/install/contrast-methods/index.js +1 -1
  13. package/lib/dataflow/propagation/install/contrast-methods/number.js +1 -1
  14. package/lib/dataflow/propagation/install/contrast-methods/string.js +1 -1
  15. package/lib/dataflow/propagation/install/contrast-methods/tag.js +1 -1
  16. package/lib/dataflow/propagation/install/decode-uri-component.js +1 -1
  17. package/lib/dataflow/propagation/install/ejs/escape-xml.js +1 -1
  18. package/lib/dataflow/propagation/install/ejs/index.js +1 -1
  19. package/lib/dataflow/propagation/install/encode-uri-component.js +1 -1
  20. package/lib/dataflow/propagation/install/escape-html.js +1 -1
  21. package/lib/dataflow/propagation/install/escape.js +1 -1
  22. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +1 -1
  23. package/lib/dataflow/propagation/install/isnumeric-0.js +1 -1
  24. package/lib/dataflow/propagation/install/mongoose/common.js +20 -0
  25. package/lib/dataflow/propagation/install/mongoose/index.js +5 -9
  26. package/lib/dataflow/propagation/install/mongoose/schema-map.js +149 -0
  27. package/lib/dataflow/propagation/install/mongoose/schema-mixed.js +162 -0
  28. package/lib/dataflow/propagation/install/mongoose/schema-string.js +91 -37
  29. package/lib/dataflow/propagation/install/mysql-connection-escape.js +1 -1
  30. package/lib/dataflow/propagation/install/parse-int.js +1 -1
  31. package/lib/dataflow/propagation/install/path/basename.js +1 -1
  32. package/lib/dataflow/propagation/install/path/common.js +1 -1
  33. package/lib/dataflow/propagation/install/path/index.js +1 -1
  34. package/lib/dataflow/propagation/install/path/join-and-resolve.js +1 -1
  35. package/lib/dataflow/propagation/install/path/normalize.js +1 -1
  36. package/lib/dataflow/propagation/install/pug/index.js +1 -1
  37. package/lib/dataflow/propagation/install/pug-runtime-escape.js +1 -1
  38. package/lib/dataflow/propagation/install/querystring/index.js +1 -1
  39. package/lib/dataflow/propagation/install/querystring/parse.js +1 -1
  40. package/lib/dataflow/propagation/install/reg-exp-prototype-exec.js +182 -0
  41. package/lib/dataflow/propagation/install/sequelize.js +1 -1
  42. package/lib/dataflow/propagation/install/sql-template-strings.js +1 -1
  43. package/lib/dataflow/propagation/install/string/concat.js +1 -1
  44. package/lib/dataflow/propagation/install/string/format-methods.js +1 -1
  45. package/lib/dataflow/propagation/install/string/html-methods.js +1 -1
  46. package/lib/dataflow/propagation/install/string/index.js +65 -1
  47. package/lib/dataflow/propagation/install/string/match-all.js +236 -0
  48. package/lib/dataflow/propagation/install/string/match.js +83 -37
  49. package/lib/dataflow/propagation/install/string/replace.js +2 -2
  50. package/lib/dataflow/propagation/install/string/slice.js +1 -1
  51. package/lib/dataflow/propagation/install/string/split.js +1 -1
  52. package/lib/dataflow/propagation/install/string/substring.js +1 -1
  53. package/lib/dataflow/propagation/install/string/trim.js +1 -1
  54. package/lib/dataflow/propagation/install/unescape.js +1 -1
  55. package/lib/dataflow/propagation/install/url/domain-parsers.js +1 -1
  56. package/lib/dataflow/propagation/install/url/index.js +3 -1
  57. package/lib/dataflow/propagation/install/url/parse.js +131 -0
  58. package/lib/dataflow/propagation/install/url/searchParams.js +133 -0
  59. package/lib/dataflow/propagation/install/url/url.js +9 -52
  60. package/lib/dataflow/propagation/install/validator/hooks.js +1 -1
  61. package/lib/dataflow/propagation/install/validator/index.js +1 -1
  62. package/lib/dataflow/propagation/install/validator/methods.js +1 -1
  63. package/lib/dataflow/sinks/common.js +1 -1
  64. package/lib/dataflow/sinks/index.js +1 -1
  65. package/lib/dataflow/sinks/install/child-process.js +1 -1
  66. package/lib/dataflow/sinks/install/eval.js +1 -1
  67. package/lib/dataflow/sinks/install/express/index.js +1 -1
  68. package/lib/dataflow/sinks/install/express/unvalidated-redirect.js +1 -1
  69. package/lib/dataflow/sinks/install/fastify/index.js +1 -1
  70. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +1 -1
  71. package/lib/dataflow/sinks/install/fs.js +1 -1
  72. package/lib/dataflow/sinks/install/function.js +1 -1
  73. package/lib/dataflow/sinks/install/http/index.js +1 -1
  74. package/lib/dataflow/sinks/install/http/request.js +1 -1
  75. package/lib/dataflow/sinks/install/http/server-response.js +1 -1
  76. package/lib/dataflow/sinks/install/koa/index.js +1 -1
  77. package/lib/dataflow/sinks/install/koa/unvalidated-redirect.js +1 -1
  78. package/lib/dataflow/sinks/install/marsdb.js +1 -1
  79. package/lib/dataflow/sinks/install/mongodb.js +31 -24
  80. package/lib/dataflow/sinks/install/mssql.js +1 -1
  81. package/lib/dataflow/sinks/install/mysql.js +1 -1
  82. package/lib/dataflow/sinks/install/postgres.js +1 -1
  83. package/lib/dataflow/sinks/install/sequelize.js +1 -1
  84. package/lib/dataflow/sinks/install/sqlite3.js +1 -1
  85. package/lib/dataflow/sinks/install/vm.js +1 -1
  86. package/lib/dataflow/sources/common.js +1 -1
  87. package/lib/dataflow/sources/handler.js +1 -1
  88. package/lib/dataflow/sources/index.js +1 -1
  89. package/lib/dataflow/sources/install/body-parser1.js +1 -1
  90. package/lib/dataflow/sources/install/busboy1.js +1 -1
  91. package/lib/dataflow/sources/install/cookie-parser1.js +1 -1
  92. package/lib/dataflow/sources/install/express/index.js +1 -1
  93. package/lib/dataflow/sources/install/express/params.js +1 -1
  94. package/lib/dataflow/sources/install/express/parsedUrl.js +1 -1
  95. package/lib/dataflow/sources/install/fastify/fastify.js +1 -1
  96. package/lib/dataflow/sources/install/fastify/index.js +1 -1
  97. package/lib/dataflow/sources/install/formidable1.js +1 -1
  98. package/lib/dataflow/sources/install/http.js +1 -1
  99. package/lib/dataflow/sources/install/koa/index.js +1 -1
  100. package/lib/dataflow/sources/install/koa/koa-bodyparsers.js +1 -1
  101. package/lib/dataflow/sources/install/koa/koa-routers.js +1 -1
  102. package/lib/dataflow/sources/install/koa/koa2.js +1 -1
  103. package/lib/dataflow/sources/install/qs6.js +1 -1
  104. package/lib/dataflow/sources/install/querystring.js +1 -1
  105. package/lib/dataflow/tag-utils.js +1 -1
  106. package/lib/dataflow/tracker.js +1 -1
  107. package/lib/dataflow/utils/is-safe-content-type.js +1 -1
  108. package/lib/dataflow/utils/is-vulnerable.js +1 -1
  109. package/lib/index.js +1 -1
  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/index.js +1 -1
  115. package/lib/session-configuration/install/http.js +1 -1
  116. package/package.json +2 -2
@@ -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
 
@@ -17,32 +17,23 @@
17
17
 
18
18
  const { DataflowTag, substring } = require('@contrast/common');
19
19
  const { patchType } = require('../../common');
20
+ const { userDefinedType } = require('./common');
20
21
 
21
- module.exports = function(core) {
22
+ module.exports = function (core) {
22
23
  const {
24
+ config: {
25
+ assess: { trust_custom_validators },
26
+ },
23
27
  scopes: { sources },
24
28
  patcher,
25
29
  depHooks,
26
30
  assess: {
27
31
  dataflow: {
28
32
  tracker,
29
- eventFactory: { createPropagationEvent }
30
- }
31
- }
32
- } = core;
33
-
34
- return core.assess.dataflow.propagation.mongooseInstrumentation.schemaString = {
35
- install() {
36
- depHooks.resolve(
37
- { name: 'mongoose', file: 'lib/schema/string.js', version: '>=6.0.0' },
38
- (SchemaString) => {
39
- patchEnum(SchemaString);
40
- patchDoValidate(SchemaString);
41
- patchDoValidateSync(SchemaString);
42
- }
43
- );
33
+ eventFactory: { createPropagationEvent },
34
+ },
44
35
  },
45
- };
36
+ } = core;
46
37
 
47
38
  function patchEnum(SchemaString) {
48
39
  patcher.patch(SchemaString.prototype, 'enum', {
@@ -67,9 +58,9 @@ module.exports = function(core) {
67
58
  if (data.result) {
68
59
  tracker.untrack(data.args[0]);
69
60
  }
70
- }
61
+ },
71
62
  });
72
- }
63
+ },
73
64
  });
74
65
  }
75
66
 
@@ -81,16 +72,38 @@ module.exports = function(core) {
81
72
  patchType,
82
73
  pre(data) {
83
74
  const [value, cb] = data.args;
84
- if (value && typeof cb === 'function' && sources.getStore()?.assess) {
85
- data.args[1] = patcher.patch(cb, {
86
- name,
87
- patchType,
88
- pre({ args: [err] }) {
89
- if (!err) propagate(name, data.orig, value);
90
- }
91
- });
75
+ if (!value || typeof cb !== 'function' || !sources.getStore()?.assess) {
76
+ return;
92
77
  }
93
- }
78
+
79
+ const hasCustomValidator = data.obj.validators.some(
80
+ (validator) => validator.type === userDefinedType
81
+ );
82
+
83
+ data.args[1] = patcher.patch(cb, {
84
+ name,
85
+ patchType,
86
+ pre(data) {
87
+ const {
88
+ args: [err],
89
+ } = data;
90
+
91
+ if (!err) {
92
+ propagate(
93
+ name,
94
+ data.orig,
95
+ value,
96
+ trust_custom_validators
97
+ ? hasCustomValidator
98
+ : false
99
+ );
100
+ }
101
+
102
+ if (err && err.kind === userDefinedType)
103
+ propagate(name, data.orig, value, false);
104
+ },
105
+ });
106
+ },
94
107
  });
95
108
  }
96
109
 
@@ -99,16 +112,34 @@ module.exports = function(core) {
99
112
  patcher.patch(SchemaString.prototype, 'doValidateSync', {
100
113
  name,
101
114
  patchType,
102
- post({ orig, args: [value] }) {
103
- if (value?.length) {
104
- propagate(name, orig, value);
115
+ post(data) {
116
+ const {
117
+ args: [value],
118
+ result
119
+ } = data;
120
+
121
+ const hasCustomValidator = data.obj.validators.some(
122
+ (validator) => validator.type === userDefinedType
123
+ );
124
+
125
+ if (!result) {
126
+ propagate(
127
+ name,
128
+ data.orig,
129
+ value,
130
+ trust_custom_validators
131
+ ? hasCustomValidator
132
+ : false
133
+ );
105
134
  }
106
- }
107
- });
108
135
 
136
+ if (result && result.kind === userDefinedType)
137
+ propagate(name, data.orig, value, false);
138
+ },
139
+ });
109
140
  }
110
141
 
111
- function propagate(name, orig, value) {
142
+ function propagate(name, orig, value, customValidated = false) {
112
143
  const strInfo = tracker.getData(value);
113
144
  if (!strInfo) return;
114
145
 
@@ -116,7 +147,10 @@ module.exports = function(core) {
116
147
  // copy because we mutate the metadata value inline
117
148
  const history = [{ ...strInfo }];
118
149
  const event = createPropagationEvent({
119
- addedTags: [DataflowTag.STRING_TYPE_CHECKED],
150
+ addedTags: [
151
+ DataflowTag.STRING_TYPE_CHECKED,
152
+ customValidated ? DataflowTag.CUSTOM_VALIDATED : null,
153
+ ].filter(Boolean),
120
154
  name,
121
155
  moduleName: 'mongoose',
122
156
  methodName,
@@ -134,11 +168,14 @@ module.exports = function(core) {
134
168
  tags: {
135
169
  ...strInfo.tags,
136
170
  [DataflowTag.STRING_TYPE_CHECKED]: [0, value.length - 1],
171
+ ...(customValidated
172
+ ? { [DataflowTag.CUSTOM_VALIDATED]: [0, value.length - 1] }
173
+ : {}),
137
174
  },
138
175
  target: 'P0',
139
176
  stacktraceOpts: {
140
177
  prependFrames: [orig],
141
- }
178
+ },
142
179
  });
143
180
 
144
181
  if (!event) {
@@ -153,4 +190,21 @@ module.exports = function(core) {
153
190
 
154
191
  Object.assign(strInfo, event);
155
192
  }
193
+
194
+ return core.assess.dataflow.propagation.mongooseInstrumentation.schemaString = {
195
+ install() {
196
+ depHooks.resolve(
197
+ {
198
+ name: 'mongoose',
199
+ file: 'lib/schema/string.js',
200
+ version: '>=6.0.0',
201
+ },
202
+ (SchemaString) => {
203
+ patchEnum(SchemaString);
204
+ patchDoValidate(SchemaString);
205
+ patchDoValidateSync(SchemaString);
206
+ }
207
+ );
208
+ },
209
+ };
156
210
  };
@@ -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
 
@@ -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
 
@@ -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
 
@@ -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
 
@@ -0,0 +1,182 @@
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
+ const { inspect } = require('@contrast/common');
18
+ const { createSubsetTags } = require('../../tag-utils');
19
+ const { patchType } = require('../common');
20
+
21
+ module.exports = function(core) {
22
+ const {
23
+ scopes: { sources, instrumentation },
24
+ patcher,
25
+ assess: {
26
+ dataflow: {
27
+ tracker,
28
+ eventFactory: { createPropagationEvent },
29
+ },
30
+ },
31
+ } = core;
32
+
33
+ function createPropagationEventForMatch({
34
+ strInfo,
35
+ startIdx,
36
+ match,
37
+ untrackedResult,
38
+ metadata,
39
+ }) {
40
+ const tags = createSubsetTags(strInfo.tags, startIdx, match.length);
41
+ const { name, obj, hooked, orig } = metadata;
42
+
43
+ return createPropagationEvent({
44
+ name,
45
+ moduleName: 'RegExp',
46
+ methodName: 'prototype.exec',
47
+ context: `'${obj}'.exec('${strInfo.value}')`,
48
+ history: [strInfo],
49
+ object: {
50
+ value: obj,
51
+ tracked: false,
52
+ },
53
+ args: [
54
+ {
55
+ value: strInfo.value,
56
+ tracked: true,
57
+ },
58
+ ],
59
+ tags,
60
+ result: {
61
+ value: inspect(untrackedResult),
62
+ tracked: false,
63
+ },
64
+ stacktraceOpts: {
65
+ constructorOpt: hooked,
66
+ prependFrames: [orig],
67
+ },
68
+ source: 'P',
69
+ target: 'R',
70
+ });
71
+ }
72
+
73
+ return (core.assess.dataflow.propagation.regExpExec = {
74
+ install() {
75
+ const name = 'RegExp.prototype.exec';
76
+
77
+ patcher.patch(RegExp.prototype, 'exec', {
78
+ name,
79
+ patchType,
80
+ post(data) {
81
+ const { args, obj, result, hooked, orig } = data;
82
+
83
+ if (
84
+ !obj ||
85
+ !args[0] ||
86
+ !result?.length ||
87
+ !sources.getStore()?.assess ||
88
+ instrumentation.isLocked()
89
+ )
90
+ return;
91
+
92
+ const strInfo = tracker.getData(args[0]);
93
+
94
+ if (!strInfo) return;
95
+
96
+ const untrackedResult = [...result];
97
+ untrackedResult.groups = result.groups && { ...result.groups };
98
+ untrackedResult.input = strInfo.value;
99
+ untrackedResult.index = result.index;
100
+ result.indices && (untrackedResult.indices = result.indices);
101
+
102
+ let searchIdx = result.index;
103
+ const metadata = { name, obj, hooked, orig };
104
+
105
+ for (let i = 0; i < result.length; i++) {
106
+ let match = result[i];
107
+
108
+ if (!match) continue;
109
+
110
+ if (match === args[0]) {
111
+ // There is a case where the match
112
+ // is the whole original string in which case the value here is
113
+ // externalized and we need to make sure to track
114
+ // the non-exterrnalized one
115
+ match = strInfo.value;
116
+ }
117
+
118
+ const startIdx = strInfo.value.indexOf(match, searchIdx);
119
+ const event = createPropagationEventForMatch({
120
+ strInfo,
121
+ startIdx,
122
+ match,
123
+ untrackedResult,
124
+ metadata
125
+ });
126
+
127
+ if (i > 0) {
128
+ // The first match is the full match of the regex so we cannot
129
+ // increment the search index.
130
+ // Every match after the first will occur in order of appearance
131
+ // in the original string so we should increment the search index
132
+ searchIdx = startIdx + match.length;
133
+ }
134
+
135
+ if (!event) continue;
136
+
137
+ const { extern } = tracker.track(match, event);
138
+
139
+ if (extern) {
140
+ result[i] = extern;
141
+ }
142
+ }
143
+
144
+ if (result.groups) {
145
+ Object.keys(result.groups).forEach((key) => {
146
+ let res = result.groups[key];
147
+
148
+ if (!res) return;
149
+
150
+ if (res === args[0]) {
151
+ // There is a case where the match
152
+ // is the whole original string in which case the value here is
153
+ // externalized and we need to make sure to track
154
+ // the non-exterrnalized one
155
+ res = strInfo.value;
156
+ }
157
+
158
+ const startIdx = strInfo.value.indexOf(res, result.index);
159
+ const event = createPropagationEventForMatch({
160
+ strInfo,
161
+ startIdx,
162
+ match: res,
163
+ untrackedResult,
164
+ metadata
165
+ });
166
+
167
+ if (event) {
168
+ const { extern } = tracker.track(res, event);
169
+ if (extern) {
170
+ result.groups[key] = extern;
171
+ }
172
+ }
173
+ });
174
+ }
175
+ },
176
+ });
177
+ },
178
+ uninstall() {
179
+ RegExp.prototype.exec = patcher.unwrap(RegExp.prototype.exec);
180
+ },
181
+ });
182
+ };
@@ -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
 
@@ -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
 
@@ -16,21 +16,85 @@
16
16
  'use strict';
17
17
 
18
18
  const { callChildComponentMethodsSync } = require('@contrast/common');
19
+ const { inspect, split } = require('@contrast/common');
19
20
 
20
21
  module.exports = function(core) {
22
+ const {
23
+ scopes: { sources, instrumentation },
24
+ patcher,
25
+ assess: {
26
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
27
+ }
28
+ } = core;
21
29
  const stringInstrumentation = core.assess.dataflow.propagation.stringInstrumentation = {
22
30
  install() {
23
31
  callChildComponentMethodsSync(stringInstrumentation, 'install');
24
32
  },
25
33
  uninstall() {
26
34
  callChildComponentMethodsSync(stringInstrumentation, 'uninstall');
35
+ },
36
+ utils: {
37
+ patchCustomMatcher
27
38
  }
28
39
  };
29
40
 
41
+ function patchCustomMatcher(matcherFn, objInfo, methodArg, name, patchType) {
42
+ const [, , methodName] = split(name, '.');
43
+
44
+ return patcher.patch(matcherFn, {
45
+ name,
46
+ patchType,
47
+ pre(data) {
48
+ const { args: origArgs, hooked, orig } = data;
49
+ if (
50
+ !origArgs.length ||
51
+ typeof origArgs[0] !== 'string' ||
52
+ !sources.getStore()?.assess ||
53
+ instrumentation.isLocked()
54
+ ) return;
55
+
56
+ const args = [{
57
+ value: inspect(methodArg),
58
+ tracked: false
59
+ }];
60
+
61
+ const event = createPropagationEvent({
62
+ name,
63
+ moduleName: 'String',
64
+ methodName: `prototype.${methodName}`,
65
+ context: `'${objInfo.value}'.${methodName}(${args[0].value})`,
66
+ history: [objInfo],
67
+ object: {
68
+ value: objInfo.value,
69
+ tracked: true,
70
+ },
71
+ args,
72
+ tags: objInfo.tags,
73
+ result: undefined,
74
+ stacktraceOpts: {
75
+ constructorOpt: hooked,
76
+ prependFrames: [orig]
77
+ },
78
+ source: 'P',
79
+ target: 'P'
80
+ });
81
+
82
+ if (!event) return;
83
+
84
+ const { extern } = tracker.track(objInfo.value, event);
85
+
86
+ if (extern) {
87
+ origArgs[0] = extern;
88
+ }
89
+ }
90
+ });
91
+ }
92
+
30
93
  require('./concat')(core);
31
94
  require('./format-methods')(core);
32
95
  require('./html-methods')(core);
33
96
  require('./match')(core);
97
+ require('./match-all')(core);
34
98
  require('./replace')(core);
35
99
  require('./split')(core);
36
100
  require('./slice')(core);