@contrast/assess 1.1.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 (111) hide show
  1. package/coverage/lcov-report/base.css +224 -0
  2. package/coverage/lcov-report/block-navigation.js +87 -0
  3. package/coverage/lcov-report/favicon.png +0 -0
  4. package/coverage/lcov-report/index.html +266 -0
  5. package/coverage/lcov-report/lib/dataflow/common.js.html +154 -0
  6. package/coverage/lcov-report/lib/dataflow/event-factory.js.html +598 -0
  7. package/coverage/lcov-report/lib/dataflow/index.html +191 -0
  8. package/coverage/lcov-report/lib/dataflow/index.js.html +190 -0
  9. package/coverage/lcov-report/lib/dataflow/propagation/common.js.html +145 -0
  10. package/coverage/lcov-report/lib/dataflow/propagation/index.html +131 -0
  11. package/coverage/lcov-report/lib/dataflow/propagation/index.js.html +190 -0
  12. package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/index.html +131 -0
  13. package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/index.js.html +184 -0
  14. package/coverage/lcov-report/lib/dataflow/propagation/install/contrast-methods/plus.js.html +397 -0
  15. package/coverage/lcov-report/lib/dataflow/propagation/install/string/concat.js.html +478 -0
  16. package/coverage/lcov-report/lib/dataflow/propagation/install/string/index.html +176 -0
  17. package/coverage/lcov-report/lib/dataflow/propagation/install/string/index.js.html +202 -0
  18. package/coverage/lcov-report/lib/dataflow/propagation/install/string/replace.js.html +496 -0
  19. package/coverage/lcov-report/lib/dataflow/propagation/install/string/substring.js.html +415 -0
  20. package/coverage/lcov-report/lib/dataflow/propagation/install/string/trim.js.html +403 -0
  21. package/coverage/lcov-report/lib/dataflow/signatures.js.html +5923 -0
  22. package/coverage/lcov-report/lib/dataflow/sinks/common.js.html +145 -0
  23. package/coverage/lcov-report/lib/dataflow/sinks/index.html +131 -0
  24. package/coverage/lcov-report/lib/dataflow/sinks/index.js.html +211 -0
  25. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/index.html +146 -0
  26. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/index.js.html +172 -0
  27. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js.html +319 -0
  28. package/coverage/lcov-report/lib/dataflow/sinks/install/fastify/xss.js.html +721 -0
  29. package/coverage/lcov-report/lib/dataflow/sinks/install/http.js.html +340 -0
  30. package/coverage/lcov-report/lib/dataflow/sinks/install/index.html +116 -0
  31. package/coverage/lcov-report/lib/dataflow/sources/common.js.html +145 -0
  32. package/coverage/lcov-report/lib/dataflow/sources/index.html +131 -0
  33. package/coverage/lcov-report/lib/dataflow/sources/index.js.html +226 -0
  34. package/coverage/lcov-report/lib/dataflow/sources/install/fastify.js.html +379 -0
  35. package/coverage/lcov-report/lib/dataflow/sources/install/http.js.html +502 -0
  36. package/coverage/lcov-report/lib/dataflow/sources/install/index.html +146 -0
  37. package/coverage/lcov-report/lib/dataflow/sources/install/qs.js.html +322 -0
  38. package/coverage/lcov-report/lib/dataflow/tag-utils.js.html +418 -0
  39. package/coverage/lcov-report/lib/dataflow/tracker.js.html +466 -0
  40. package/coverage/lcov-report/lib/dataflow/utils/index.html +116 -0
  41. package/coverage/lcov-report/lib/dataflow/utils/is-vulnerable.js.html +424 -0
  42. package/coverage/lcov-report/lib/index.html +116 -0
  43. package/coverage/lcov-report/lib/index.js.html +193 -0
  44. package/coverage/lcov-report/prettify.css +1 -0
  45. package/coverage/lcov-report/prettify.js +2 -0
  46. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  47. package/coverage/lcov-report/sorter.js +196 -0
  48. package/coverage/lcov.info +4856 -0
  49. package/coverage/tmp/coverage-9548-1675168551025-0.json +1 -0
  50. package/coverage/tmp/coverage-9551-1675168550963-0.json +1 -0
  51. package/coverage/tmp/coverage-9552-1675168550969-0.json +1 -0
  52. package/coverage/tmp/coverage-9553-1675168550970-0.json +1 -0
  53. package/coverage/tmp/coverage-9554-1675168550962-0.json +1 -0
  54. package/coverage/tmp/coverage-9555-1675168550965-0.json +1 -0
  55. package/coverage/tmp/coverage-9556-1675168550964-0.json +1 -0
  56. package/coverage/tmp/coverage-9557-1675168550969-0.json +1 -0
  57. package/coverage/tmp/coverage-9558-1675168550964-0.json +1 -0
  58. package/coverage/tmp/coverage-9559-1675168550971-0.json +1 -0
  59. package/lib/dataflow/event-factory.js +256 -0
  60. package/lib/dataflow/index.js +35 -0
  61. package/lib/dataflow/propagation/common.js +26 -0
  62. package/lib/dataflow/propagation/index.js +50 -0
  63. package/lib/dataflow/propagation/install/array-prototype-join.js +125 -0
  64. package/lib/dataflow/propagation/install/contrast-methods/add.js +104 -0
  65. package/lib/dataflow/propagation/install/contrast-methods/index.js +34 -0
  66. package/lib/dataflow/propagation/install/contrast-methods/tag.js +102 -0
  67. package/lib/dataflow/propagation/install/decode-uri-component.js +88 -0
  68. package/lib/dataflow/propagation/install/ejs/escape-xml.js +89 -0
  69. package/lib/dataflow/propagation/install/ejs/index.js +30 -0
  70. package/lib/dataflow/propagation/install/encode-uri-component.js +87 -0
  71. package/lib/dataflow/propagation/install/escape-html.js +89 -0
  72. package/lib/dataflow/propagation/install/escape.js +89 -0
  73. package/lib/dataflow/propagation/install/handlebars-utils-escape-expression.js +89 -0
  74. package/lib/dataflow/propagation/install/mysql-connection-escape.js +111 -0
  75. package/lib/dataflow/propagation/install/pug/index.js +64 -0
  76. package/lib/dataflow/propagation/install/pug-runtime-escape.js +89 -0
  77. package/lib/dataflow/propagation/install/sql-template-strings.js +103 -0
  78. package/lib/dataflow/propagation/install/string/concat.js +108 -0
  79. package/lib/dataflow/propagation/install/string/format-methods.js +83 -0
  80. package/lib/dataflow/propagation/install/string/html-methods.js +163 -0
  81. package/lib/dataflow/propagation/install/string/index.js +38 -0
  82. package/lib/dataflow/propagation/install/string/replace.js +197 -0
  83. package/lib/dataflow/propagation/install/string/substring.js +117 -0
  84. package/lib/dataflow/propagation/install/string/trim.js +115 -0
  85. package/lib/dataflow/propagation/install/unescape.js +90 -0
  86. package/lib/dataflow/propagation/install/url/domain-parsers.js +89 -0
  87. package/lib/dataflow/propagation/install/url/index.js +33 -0
  88. package/lib/dataflow/propagation/install/validator/hooks.js +172 -0
  89. package/lib/dataflow/propagation/install/validator/index.js +28 -0
  90. package/lib/dataflow/propagation/install/validator/methods.js +82 -0
  91. package/lib/dataflow/signatures.js +2022 -0
  92. package/lib/dataflow/sinks/common.js +20 -0
  93. package/lib/dataflow/sinks/index.js +44 -0
  94. package/lib/dataflow/sinks/install/fastify/index.js +30 -0
  95. package/lib/dataflow/sinks/install/fastify/unvalidated-redirect.js +107 -0
  96. package/lib/dataflow/sinks/install/http.js +119 -0
  97. package/lib/dataflow/sinks/install/postgres/index.js +129 -0
  98. package/lib/dataflow/sources/common.js +20 -0
  99. package/lib/dataflow/sources/handler.js +114 -0
  100. package/lib/dataflow/sources/index.js +35 -0
  101. package/lib/dataflow/sources/install/fastify/cookie.js +61 -0
  102. package/lib/dataflow/sources/install/fastify/fastify.js +89 -0
  103. package/lib/dataflow/sources/install/fastify/index.js +31 -0
  104. package/lib/dataflow/sources/install/http.js +181 -0
  105. package/lib/dataflow/sources/install/qs.js +88 -0
  106. package/lib/dataflow/tag-utils.js +122 -0
  107. package/lib/dataflow/tracker.js +127 -0
  108. package/lib/dataflow/utils/is-safe-content-type.js +30 -0
  109. package/lib/dataflow/utils/is-vulnerable.js +113 -0
  110. package/lib/index.js +36 -0
  111. package/package.json +21 -0
@@ -0,0 +1,256 @@
1
+ /*
2
+ * Copyright: 2022 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
+
19
+ const { InputType } = require('@contrast/common');
20
+ const annotationRegExp = /^(A|O|R|P|P\d+)$/;
21
+
22
+ module.exports = function(core) {
23
+ const {
24
+ createSnapshot,
25
+ config,
26
+ logger,
27
+ scopes: { sources },
28
+ assess: {
29
+ dataflow: { signatures }
30
+ }
31
+ } = core;
32
+ const eventFactory = core.assess.dataflow.eventFactory = {};
33
+
34
+ eventFactory.createdEvents = new WeakSet();
35
+
36
+ eventFactory.createSourceEvent = function(data = {}) {
37
+ const {
38
+ name,
39
+ result = { value: null, isTracked: false },
40
+ tags,
41
+ inputType,
42
+ } = data;
43
+
44
+ const baseMessage = 'Source event not created: %s';
45
+
46
+ if (!result.value) {
47
+ logger.debug({ result }, baseMessage, 'invalid result');
48
+ return null;
49
+ }
50
+
51
+ if (!name) {
52
+ logger.debug({ name }, baseMessage, 'invalid name');
53
+ return null;
54
+ }
55
+
56
+ if (!(inputType in InputType)) {
57
+ logger.debug({ inputType }, baseMessage, 'invalid inputType');
58
+ return null;
59
+ }
60
+
61
+ if (!tags) {
62
+ logger.debug({ data }, baseMessage, 'event has no tags');
63
+ return null;
64
+ }
65
+
66
+ eventFactory.createdEvents.add(data);
67
+
68
+ return data;
69
+ };
70
+
71
+ eventFactory.createPropagationEvent = function(data) {
72
+ const {
73
+ name = '',
74
+ history = [],
75
+ object = { value: null, isTracked: false },
76
+ args = [],
77
+ result = { value: null, isTracked: false },
78
+ tags = {},
79
+ addedTags = [],
80
+ removedTags = [],
81
+ source,
82
+ target,
83
+ stacktraceOpts
84
+ } = data;
85
+
86
+ const sourceContext = sources.getStore()?.assess;
87
+
88
+ if (!sourceContext) {
89
+ logger.debug({ name }, 'No sourceContext found during Propagation event creation');
90
+ return null;
91
+ }
92
+
93
+ if (sourceContext.propagationEventsCount >= config.assess.max_propagation_events) {
94
+ logger.debug({ name }, 'Maximum number of Propagation events reached. Event not created');
95
+ return null;
96
+ }
97
+
98
+ const signature = signatures.get(name);
99
+
100
+ if (!signature) {
101
+ logger.debug({ name }, 'Propagation event not created: no signature found for this name');
102
+ return null;
103
+ }
104
+
105
+ if (!history.length) {
106
+ logger.debug({ name, history }, 'Propagation event not created: invalid history');
107
+ return null;
108
+ }
109
+
110
+ if (
111
+ ((source && !source.match(annotationRegExp)) || (!source && !signature.source)) ||
112
+ ((target && !target.match(annotationRegExp)) || (!target && !signature.target))
113
+ ) {
114
+ logger.debug({ name, source, target }, 'Propagation event not created: %s', 'invalid source/target');
115
+ return null;
116
+ }
117
+
118
+ let stack;
119
+ if (config.assess.stacktraces === 'ALL') {
120
+ stack = createSnapshot(stacktraceOpts)();
121
+ } else {
122
+ stack = [];
123
+ }
124
+
125
+ const event = {
126
+ time: Date.now(),
127
+ history,
128
+ name,
129
+ object,
130
+ args,
131
+ result,
132
+ tags,
133
+ addedTags,
134
+ removedTags,
135
+ source,
136
+ target,
137
+ stack
138
+ };
139
+
140
+ eventFactory.createdEvents.add(event);
141
+ sourceContext.propagationEventsCount++;
142
+
143
+ return event;
144
+ };
145
+
146
+ eventFactory.createSinkEvent = function(data) {
147
+ const {
148
+ name = '',
149
+ history = [],
150
+ object = { value: null, isTracked: false },
151
+ args = [],
152
+ result = { value: null, isTracked: false },
153
+ tags = {},
154
+ source,
155
+ stacktraceOpts
156
+ } = data;
157
+ const sourceContext = sources.getStore()?.assess;
158
+
159
+ if (!sourceContext) {
160
+ logger.debug('No sourceContext found during Sink event creation');
161
+ return null;
162
+ }
163
+
164
+ const signature = signatures.get(name);
165
+
166
+ if (
167
+ !signature ||
168
+ !history.length ||
169
+ ((source && !source.match(annotationRegExp)) || (!source && !signature.source))
170
+ ) {
171
+ logger.debug({ data }, 'Wrong sink event data submited. Sink event not created');
172
+ return null;
173
+ }
174
+
175
+ let stack;
176
+ if (config.assess.stacktraces !== 'NONE') {
177
+ stack = createSnapshot(stacktraceOpts);
178
+ } else {
179
+ stack = [];
180
+ }
181
+
182
+ const event = {
183
+ time: Date.now(),
184
+ history,
185
+ name,
186
+ object,
187
+ args,
188
+ result,
189
+ tags,
190
+ source,
191
+ stack
192
+ };
193
+
194
+ eventFactory.createdEvents.add(event);
195
+
196
+ return event;
197
+ };
198
+
199
+ return eventFactory;
200
+ };
201
+
202
+
203
+ // Sample event data
204
+ // const e = {
205
+ // // we need the time the event occurred
206
+ // time: '1234',
207
+ // history: ['argsTrackedInfo'],
208
+ // name: 'ContrastMethods.add', // as this method is used to rewrite not only `+` but `+=` too
209
+ // context: {
210
+ // obj: null,
211
+ // args: ['...args'],
212
+ // resultTracked: 'result'
213
+ // },
214
+ // stack: 'createSnapshot()',
215
+ // tags: 'newTags',
216
+ // // we need a property with add/removed tags
217
+ // addedTags: [],
218
+ // removedTags: [],
219
+ // // we need info for the source and the targeto
220
+ // source: 'A | P | O | R',
221
+ // target: 'A | P | O | R',
222
+ // // optional code property for the propagation through the ContrastMethods
223
+ // code: 'const a = b + c',
224
+ // // we need a signature property
225
+ // signature: {
226
+ // // in v4 we are storing all the signatures in a json file,
227
+ // // so we get the values from there and format them accordingly
228
+ // }
229
+ // };
230
+
231
+ // Sample payload for a discovered vulnerability
232
+ // const payload = {
233
+ // created: Date.now(),
234
+ // events: [
235
+ // {
236
+ // action: e.addedTags.length || e.removedTags.length ? 'TAG' : `${e.source}2${e.target}`,
237
+ // args: e.context.args, // they will be "expanded" before reporting
238
+ // code: e.code,
239
+ // eventSources: [], // only for SourceEvents
240
+ // fieldName: '', // we don't set it in v4
241
+ // object: e.context.obj, // again it will be expanded later
242
+ // parentObjectsIds: [], // we don't set it in v4
243
+ // properties: [], // not needed for dataflow
244
+ // ret: e.context.resultTracked,
245
+ // signature: e.signature,
246
+ // source: e.source,
247
+ // stacktrace: e.stack,
248
+ // tags: e.addedTags.join(), // in v4 we set all tags here, idk why
249
+ // taintRanges: e.tags.map(), // the tag ranges we want highlighted in ContrastUI
250
+ // target: e.target,
251
+ // thread: process.pid,
252
+ // time: e.time,
253
+ // type: e.addedTags.length || e.removedTags.length ? 'TAG' : 'PROPAGATION'
254
+ // }
255
+ // ]
256
+ // };
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright: 2022 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 dataflow = core.assess.dataflow = {};
22
+
23
+ require('./signatures')(core);
24
+ require('./event-factory')(core);
25
+ require('./tracker')(core);
26
+ require('./sources')(core);
27
+ require('./propagation')(core);
28
+ require('./sinks')(core);
29
+
30
+ dataflow.install = function() {
31
+ callChildComponentMethodsSync(dataflow, 'install');
32
+ };
33
+
34
+ return dataflow;
35
+ };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright: 2022 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
+ patchType: 'assess-dataflow-propagator',
20
+ createModuleLabel(name, version = '1.0.0') {
21
+ return `Module<${name}@${version}>`;
22
+ },
23
+ createObjectLabel(name, id = '0001') {
24
+ return `Object<${name}@${id}>`;
25
+ }
26
+ };
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright: 2022 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 propagation = core.assess.dataflow.propagation = {};
22
+
23
+ require('./install/string')(core);
24
+ require('./install/array-prototype-join')(core);
25
+ require('./install/pug')(core);
26
+ require('./install/contrast-methods')(core);
27
+ require('./install/validator')(core);
28
+ require('./install/url')(core);
29
+ require('./install/ejs')(core);
30
+ require('./install/encode-uri-component')(core);
31
+ require('./install/decode-uri-component')(core);
32
+ require('./install/escape-html')(core);
33
+ require('./install/escape')(core);
34
+ require('./install/handlebars-utils-escape-expression')(core);
35
+ require('./install/mysql-connection-escape')(core);
36
+ require('./install/pug-runtime-escape')(core);
37
+ require('./install/sql-template-strings')(core);
38
+ require('./install/unescape')(core);
39
+
40
+
41
+ propagation.install = function() {
42
+ callChildComponentMethodsSync(propagation, 'install');
43
+ };
44
+
45
+ propagation.uninstall = function() {
46
+ callChildComponentMethodsSync(propagation, 'uninstall');
47
+ };
48
+
49
+ return propagation;
50
+ };
@@ -0,0 +1,125 @@
1
+ /*
2
+ * Copyright: 2022 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
+ createAppendTags
20
+ } = require('../../tag-utils');
21
+ const { patchType } = require('../common');
22
+ const { isString } = require('@contrast/common');
23
+
24
+ module.exports = function(core) {
25
+ const {
26
+ scopes: { sources, instrumentation },
27
+ patcher,
28
+ assess: {
29
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
30
+ }
31
+ } = core;
32
+
33
+ function accumulateTags(array, tags, offset, history, delimiterLength = 1, delimiterTags = {}) {
34
+ let globalOffset = offset;
35
+ let newTags = tags;
36
+ let newHistory = history;
37
+ for (let i = 0; i < array.length; i++) {
38
+ const elem = array[i];
39
+ if ((!isString(elem) && !Array.isArray(elem)) || !elem) continue;
40
+
41
+ if (Array.isArray(elem)) {
42
+ ({ newTags, newHistory, globalOffset } = accumulateTags(elem, newTags, globalOffset, newHistory));
43
+ } else {
44
+ const elInfo = tracker.getData(elem);
45
+ if (elInfo) {
46
+ const elTags = elInfo.tags || {};
47
+ newHistory.add(elInfo);
48
+ Object.assign(newTags, createAppendTags(newTags, elTags, globalOffset));
49
+ }
50
+
51
+ globalOffset += elem.length;
52
+ }
53
+
54
+ if (i !== array.length - 1) {
55
+ Object.keys(delimiterTags).length && Object.assign(newTags, createAppendTags(newTags, delimiterTags, globalOffset));
56
+
57
+ globalOffset += delimiterLength;
58
+ }
59
+ }
60
+
61
+ return { newTags, newHistory, globalOffset };
62
+ }
63
+
64
+ return core.assess.dataflow.propagation.arrayJoin = {
65
+ install() {
66
+ const originalJoin = Array.prototype.join;
67
+ patcher.patch(Array.prototype, 'join', {
68
+ name: 'Array.prototype.join',
69
+ patchType,
70
+ post(data) {
71
+ const { args, obj, result, hooked, orig } = data;
72
+ if (!result || !sources.getStore()?.assess || instrumentation.isLocked()) return;
73
+
74
+ const resultInfo = tracker.getData(result);
75
+ const delimiter = args[0] === undefined ? ',' : args[0];
76
+ const delimiterLength = delimiter.length;
77
+ const delimiterInfo = tracker.getData(delimiter);
78
+ const initHistory = delimiterInfo ? new Set([delimiterInfo]) : new Set();
79
+ const { newTags, newHistory: history } = accumulateTags(obj, {}, 0, initHistory, delimiterLength, delimiterInfo?.tags);
80
+
81
+ if (history.size) {
82
+ const event = createPropagationEvent({
83
+ name: 'Array.prototype.join',
84
+ object: {
85
+ value: originalJoin.call(obj),
86
+ isTracked: false
87
+ },
88
+ result: {
89
+ value: resultInfo ? resultInfo.value : result,
90
+ isTracked: true
91
+ },
92
+ args: [{
93
+ value: delimiterInfo ? delimiterInfo.value : delimiter,
94
+ isTracked: !!delimiterInfo
95
+ }],
96
+ tags: newTags,
97
+ history: Array.from(history),
98
+ source: delimiterInfo ? (history.size > 1 ? 'A' : 'P') : 'O',
99
+ target: 'R',
100
+ stacktraceOpts: {
101
+ constructorOpt: hooked,
102
+ prependFrames: [orig]
103
+ },
104
+ });
105
+
106
+ if (!event) return;
107
+
108
+ if (resultInfo) {
109
+ Object.assign(resultInfo, event);
110
+ }
111
+
112
+ const { extern } = resultInfo || tracker.track(result, event);
113
+
114
+ if (extern) {
115
+ data.result = extern;
116
+ }
117
+ }
118
+ }
119
+ });
120
+ },
121
+ uninstall() {
122
+ Array.prototype.join = patcher.unwrap(Array.prototype.join);
123
+ },
124
+ };
125
+ };
@@ -0,0 +1,104 @@
1
+ /*
2
+ * Copyright: 2022 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
+ createAppendTags
20
+ } = require('../../../tag-utils');
21
+ const { patchType, createObjectLabel } = require('../../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ scopes: { instrumentation, sources },
26
+ patcher,
27
+ assess: {
28
+ dataflow: { tracker, eventFactory: { createPropagationEvent } }
29
+ }
30
+ } = core;
31
+
32
+ return core.assess.dataflow.propagation.contrastMethodsInstrumentation.add = {
33
+ install() {
34
+ patcher.patch(global.ContrastMethods, 'add', {
35
+ name: 'ContrastMethods.add',
36
+ patchType,
37
+ post(data) {
38
+ const { args, result, hooked, orig } = data;
39
+ if (!result || !sources.getStore()?.assess || instrumentation.isLocked()) return;
40
+
41
+ const rInfo = tracker.getData(result);
42
+ if (rInfo) {
43
+ // this may happen w/ '' + 'tracked' => 'tracked'
44
+ return;
45
+ }
46
+
47
+ const leftStringInfo = tracker.getData(args[0]);
48
+ const rightStringInfo = tracker.getData(args[1]);
49
+
50
+ let newTags = {};
51
+ const history = [];
52
+
53
+ if (leftStringInfo) {
54
+ history.push(leftStringInfo);
55
+ newTags = leftStringInfo.tags || {};
56
+ }
57
+
58
+ if (rightStringInfo) {
59
+ history.push(rightStringInfo);
60
+ newTags = createAppendTags(newTags, rightStringInfo.tags, args[0].length);
61
+ }
62
+
63
+ if (history.length) {
64
+ const event = createPropagationEvent({
65
+ name: 'ContrastMethods.add',
66
+ history,
67
+ object: {
68
+ value: createObjectLabel('ContrastMethods'),
69
+ isTracked: false
70
+ },
71
+ args: [
72
+ {
73
+ value: args[0],
74
+ isTracked: !!leftStringInfo
75
+ },
76
+ {
77
+ value: args[1],
78
+ isTracked: !!rightStringInfo
79
+ }
80
+ ],
81
+ result: {
82
+ value: result,
83
+ isTracked: true
84
+ },
85
+ tags: newTags,
86
+ stacktraceOpts: {
87
+ constructorOpt: hooked,
88
+ prependFrames: [orig]
89
+ }
90
+ });
91
+ const { extern } = tracker.track(result, event);
92
+
93
+ if (extern) {
94
+ data.result = extern;
95
+ }
96
+ }
97
+ }
98
+ });
99
+ },
100
+ uninstall() {
101
+ global.ContrastMethods.add = patcher.unwrap(global.ContrastMethods.add);
102
+ },
103
+ };
104
+ };
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright: 2022 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 contrastMethodsInstrumentation = core.assess.dataflow.propagation.contrastMethodsInstrumentation = {
22
+ install() {
23
+ callChildComponentMethodsSync(contrastMethodsInstrumentation, 'install');
24
+ },
25
+ uninstall() {
26
+ callChildComponentMethodsSync(contrastMethodsInstrumentation, 'uninstall');
27
+ },
28
+ };
29
+
30
+ require('./add')(core);
31
+ require('./tag')(core);
32
+
33
+ return contrastMethodsInstrumentation;
34
+ };