@contrast/assess 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright: 2023 Contrast Security, Inc
2
+ Contact: support@contrastsecurity.com
3
+ License: Commercial
4
+
5
+ NOTICE: This Software and the patented inventions embodied within may only be
6
+ used as part of Contrast Security’s commercial offerings. Even though it is
7
+ made available through public repositories, use of this Software is subject to
8
+ the applicable End User Licensing Agreement found at
9
+ https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
10
+ between Contrast Security and the End User. The Software may not be reverse
11
+ engineered, modified, repackaged, sold, redistributed or otherwise used in a
12
+ way not consistent with the End User License Agreement.
@@ -45,6 +45,8 @@ module.exports = function(core) {
45
45
  require('./install/JSON')(core);
46
46
  require('./install/path')(core);
47
47
  require('./install/reg-exp-prototype-exec')(core);
48
+ require('./install/joi')(core);
49
+ require('./install/send')(core);
48
50
 
49
51
  propagation.install = function() {
50
52
  callChildComponentMethodsSync(propagation, 'install');
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright: 2023 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const { callChildComponentMethodsSync } = require('@contrast/common');
19
+
20
+ module.exports = function(core) {
21
+ const joiInstrumentation = core.assess.dataflow.propagation.joiInstrumentation = {
22
+ install() {
23
+ callChildComponentMethodsSync(joiInstrumentation, 'install');
24
+ },
25
+ uninstall() {
26
+ callChildComponentMethodsSync(joiInstrumentation, 'uninstall');
27
+ },
28
+ };
29
+
30
+ require('./keys')(core);
31
+ require('./string-schema')(core);
32
+ require('./values')(core);
33
+
34
+ return joiInstrumentation;
35
+ };
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Copyright: 2023 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const {
19
+ isNonEmptyObject, join,
20
+ } = require('@contrast/common');
21
+ const { patchType } = require('../../common');
22
+
23
+ module.exports = function(core) {
24
+ const {
25
+ depHooks,
26
+ patcher,
27
+ } = core;
28
+
29
+ function addMetadata(schema, refTargetPath, refPath, isInReference) {
30
+ if (!schema.__CONTRAST__) {
31
+ Object.defineProperty(schema, '__CONTRAST__', {
32
+ enumerable: false,
33
+ configurable: true,
34
+ value: {
35
+ inReferenceTargets: new Set(),
36
+ refTargets: {}
37
+ },
38
+ writable: true,
39
+ });
40
+ }
41
+
42
+ let path = join(refTargetPath, '.');
43
+
44
+ if (isInReference) {
45
+ path = join(refTargetPath.slice(0, -1), '.');
46
+ schema.__CONTRAST__.inReferenceTargets.add(path);
47
+ refPath = refPath.slice(0, -1);
48
+ }
49
+
50
+ const refs = schema.__CONTRAST__.refTargets[path] || [];
51
+ refs.push(join(refPath, '.'));
52
+ schema.__CONTRAST__.refTargets[path] = refs;
53
+ }
54
+
55
+ function traverseChildSchemas(schema, refTargetPath, currentPath, refOpts) {
56
+ const traversable = schema.type === 'object' ? schema._ids._byKey.entries() : Object.entries(schema.$_terms.items);
57
+
58
+ for (const [childKey, item] of traversable) {
59
+ const value = schema.type === 'object' ? item.schema : item;
60
+ const newRefTargetPath = [...refTargetPath, childKey];
61
+ const newCurrentPath = [...currentPath, childKey];
62
+
63
+ if (value.type === 'string') {
64
+ addMetadata(value, newRefTargetPath, newCurrentPath, refOpts.in);
65
+ } else if (value.type === 'object') {
66
+ traverseChildSchemas(value, newRefTargetPath, newCurrentPath, refOpts);
67
+ }
68
+ }
69
+ }
70
+
71
+ function traverseSchemas(
72
+ joi,
73
+ currentSchema,
74
+ obj,
75
+ ancestorRef = [],
76
+ currentPath = [],
77
+ ) {
78
+ ancestorRef.unshift(obj);
79
+ if (joi.isSchema(currentSchema) || joi.isExpression(currentSchema)) return;
80
+ if (currentSchema && joi.isRef(currentSchema) && !currentSchema.__CONTRAST__?.isVisited) {
81
+ const targetSchemaRef = currentSchema.path.reduce((acc, value) => {
82
+ let ret = acc?.[value] || acc;
83
+
84
+ if (joi.isSchema(acc)) {
85
+ ret = acc?.$_terms?.keys.find(i => i.key === value);
86
+ }
87
+
88
+ return ret;
89
+ }, ancestorRef[currentSchema.ancestor - 1]);
90
+
91
+ const refTargetPath = currentSchema.absolute({ path: currentPath });
92
+ const targetSchemaInstace =
93
+ typeof targetSchemaRef?.schema === 'object'
94
+ ? targetSchemaRef.schema
95
+ : targetSchemaRef;
96
+
97
+ if (!targetSchemaInstace) return;
98
+
99
+ if (['object', 'array'].includes(targetSchemaInstace.type)) {
100
+ traverseChildSchemas(targetSchemaInstace, refTargetPath, currentPath, currentSchema);
101
+ } else {
102
+ addMetadata(targetSchemaInstace, refTargetPath, currentPath);
103
+ }
104
+ Object.defineProperty(currentSchema, '__CONTRAST__', {
105
+ enumerable: false,
106
+ configurable: true,
107
+ value: {
108
+ isVisited: true,
109
+ },
110
+ writable: true
111
+ });
112
+ } else {
113
+ if (isNonEmptyObject(currentSchema)) {
114
+ for (const [objKey, objValue] of Object.entries(currentSchema)) {
115
+ traverseSchemas(joi, objValue, currentSchema, ancestorRef, [...currentPath, objKey]);
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ return (core.assess.dataflow.propagation.joiInstrumentation.keys = {
122
+ install() {
123
+ depHooks.resolve(
124
+ { name: 'joi', file: 'lib/types/keys.js', version: '>=17.0.0' },
125
+ (joi) => {
126
+ patcher.patch(Object.getPrototypeOf(joi), 'keys', {
127
+ name: 'joi.keys',
128
+ patchType,
129
+ pre(data) {
130
+ const [value] = data.args;
131
+ const joi = data.obj.$_root;
132
+
133
+ traverseSchemas(joi, value, value);
134
+ },
135
+ });
136
+ }
137
+ );
138
+ },
139
+ });
140
+ };
@@ -0,0 +1,269 @@
1
+ /*
2
+ * Copyright: 2023 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const {
19
+ DataflowTag: { ALPHANUM_SPACE_HYPHEN, LIMITED_CHARS, STRING_TYPE_CHECKED },
20
+ inspect,
21
+ join,
22
+ split,
23
+ } = require('@contrast/common');
24
+ const { createFullLengthCopyTags } = require('../../../tag-utils');
25
+ const { patchType } = require('../../common');
26
+ const VALIDATORS = {
27
+ base64: ALPHANUM_SPACE_HYPHEN,
28
+ guid: ALPHANUM_SPACE_HYPHEN,
29
+ alphanum: ALPHANUM_SPACE_HYPHEN,
30
+ hex: ALPHANUM_SPACE_HYPHEN,
31
+ isoDate: ALPHANUM_SPACE_HYPHEN,
32
+ isoDuration: ALPHANUM_SPACE_HYPHEN,
33
+ token: ALPHANUM_SPACE_HYPHEN,
34
+ creditCard: LIMITED_CHARS,
35
+ ip: LIMITED_CHARS,
36
+ hostname: ALPHANUM_SPACE_HYPHEN,
37
+ domain: ALPHANUM_SPACE_HYPHEN,
38
+ };
39
+
40
+ module.exports = function(core) {
41
+ const {
42
+ depHooks,
43
+ scopes: { sources, instrumentation },
44
+ patcher,
45
+ assess: {
46
+ eventFactory: { createPropagationEvent },
47
+ dataflow: { tracker },
48
+ },
49
+ } = core;
50
+
51
+ function definePropagation(methodName, tagName, inspectedSchema, origFn) {
52
+ function propagationFn(strInfo) {
53
+ const event = createPropagationEvent({
54
+ addedTags: [tagName],
55
+ name: `Joi.string.${methodName}`,
56
+ moduleName: 'joi',
57
+ methodName: `string.${methodName}`,
58
+ history: [{ ...strInfo }],
59
+ object: {
60
+ tracked: false,
61
+ value: 'Joi.string',
62
+ },
63
+ args: [
64
+ { tracked: true, value: strInfo.value },
65
+ { tracked: false, value: inspectedSchema },
66
+ ],
67
+ result: {
68
+ tracked: false,
69
+ value: undefined,
70
+ },
71
+ source: 'P0',
72
+ tags: {
73
+ ...strInfo.tags,
74
+ [tagName]: [0, strInfo.value.length - 1],
75
+ },
76
+ target: 'P0',
77
+ stacktraceOpts: {
78
+ prependFrames: [origFn],
79
+ },
80
+ });
81
+
82
+ if (event) {
83
+ Object.assign(strInfo, event);
84
+ }
85
+ }
86
+
87
+ Object.defineProperty(propagationFn, 'name', {
88
+ value: tagName,
89
+ writable: false,
90
+ });
91
+
92
+ return propagationFn;
93
+ }
94
+
95
+ function getRefInstancesTrackingData(obj, refInstancesPaths) {
96
+ return refInstancesPaths
97
+ .map((referenceInstance) => {
98
+ const value = split(referenceInstance, '.').reduce(
99
+ (acc, v) => acc[v] || acc,
100
+ obj
101
+ );
102
+ return tracker.getData(value);
103
+ })
104
+ .filter(Boolean);
105
+ }
106
+
107
+ function patchValidator(
108
+ validatorObj,
109
+ patchName,
110
+ validatorName,
111
+ tagName,
112
+ ) {
113
+ patcher.patch(validatorObj, 'validate', {
114
+ name: patchName,
115
+ patchType,
116
+ post(data) {
117
+ const [input, schema] = data.args;
118
+
119
+ if (
120
+ !input ||
121
+ (validatorName !== 'validate' && typeof data.result !== 'string') ||
122
+ (validatorName === 'validate' && data.result) ||
123
+ !sources.getStore()?.assess ||
124
+ instrumentation.isLocked()
125
+ )
126
+ return;
127
+
128
+ const contrastData = schema?.schema?.__CONTRAST__;
129
+ let refTargetPath = join(schema.state.path, '.');
130
+ const inReferenceTargetPath = join(schema.state.path.slice(0, -1), '.');
131
+ if (contrastData?.inReferenceTargets.has(inReferenceTargetPath)) {
132
+ refTargetPath = join(
133
+ schema.state.path.slice(0, -1),
134
+ '.'
135
+ );
136
+ }
137
+ const references = contrastData?.refTargets[refTargetPath];
138
+
139
+ const strInfo = tracker.getData(input);
140
+
141
+ const inspectedSchema = inspect(schema);
142
+ const validation = definePropagation(
143
+ validatorName,
144
+ tagName,
145
+ inspectedSchema,
146
+ data.orig
147
+ );
148
+ if (references?.length) {
149
+ getRefInstancesTrackingData(
150
+ schema.state.ancestors[schema.state.ancestors.length - 1],
151
+ references
152
+ ).forEach((refMetadata) => {
153
+ let { eventualValidations } = refMetadata;
154
+ if (!eventualValidations) {
155
+ eventualValidations = { [refTargetPath]: [validation] };
156
+ } else if (!eventualValidations[refTargetPath]) {
157
+ eventualValidations[refTargetPath] = [validation];
158
+ } else if (
159
+ !eventualValidations[refTargetPath].find(
160
+ (v) => v.name === tagName
161
+ )
162
+ ) {
163
+ eventualValidations[refTargetPath].push(validation);
164
+ }
165
+
166
+ refMetadata.eventualValidations = eventualValidations;
167
+ });
168
+ }
169
+
170
+ if (strInfo) {
171
+ validation(strInfo);
172
+ }
173
+ },
174
+ });
175
+ }
176
+
177
+ function reTrackCoercedValue(coerce) {
178
+ patcher.patch(coerce, 'method', {
179
+ name: 'joi.string._definition.coerce',
180
+ patchType,
181
+ post(data) {
182
+ const { args, result } = data;
183
+
184
+ if (
185
+ !args[0] ||
186
+ // currently, we are losing track of coerced isoDate only
187
+ !args[1].schema.$_getRule('isoDate') ||
188
+ !sources.getStore()?.assess ||
189
+ instrumentation.isLocked()
190
+ )
191
+ return;
192
+
193
+ const argInfo = tracker.getData(args[0]);
194
+
195
+ if (!argInfo) {
196
+ return;
197
+ }
198
+
199
+ const event = createPropagationEvent({
200
+ name: 'Joi.string.isoDate.coerce',
201
+ moduleName: 'joi',
202
+ methodName: 'string.isDate.coerce',
203
+ history: [argInfo],
204
+ object: {
205
+ tracked: false,
206
+ value: 'Joi.string',
207
+ },
208
+ args: [
209
+ { tracked: true, value: argInfo.value },
210
+ { tracked: false, value: inspect(args[1]) },
211
+ ],
212
+ result: {
213
+ tracked: false,
214
+ value: result,
215
+ },
216
+ source: 'P0',
217
+ tags: createFullLengthCopyTags(argInfo.tags, result.value.length),
218
+ target: 'R',
219
+ stacktraceOpts: {
220
+ prependFrames: [data.orig],
221
+ },
222
+ });
223
+
224
+ const { extern } = tracker.track(result.value, event);
225
+
226
+ if (extern) {
227
+ data.result.value = extern;
228
+ }
229
+ },
230
+ });
231
+ }
232
+
233
+ return (core.assess.dataflow.propagation.joiInstrumentation.stringSchema = {
234
+ install() {
235
+ depHooks.resolve(
236
+ { name: 'joi', file: 'lib/types/string.js', version: '>=17.0.0' },
237
+ (stringType) => {
238
+ const stringTypePrototype = Object.getPrototypeOf(stringType);
239
+ const definition = stringTypePrototype?._definition;
240
+ const rules = definition?.rules || {};
241
+
242
+ patchValidator(
243
+ definition,
244
+ 'joi.string.validate',
245
+ 'validate',
246
+ STRING_TYPE_CHECKED
247
+ );
248
+
249
+ for (const rule in VALIDATORS) {
250
+ if (rules[rule]) {
251
+ patchValidator(
252
+ rules[rule],
253
+ 'joi.string._definition.rules',
254
+ rule,
255
+ VALIDATORS[rule],
256
+ );
257
+ }
258
+ }
259
+
260
+ const coerce = definition?.coerce;
261
+
262
+ if (coerce && rules['isoDate']) {
263
+ reTrackCoercedValue(coerce);
264
+ }
265
+ }
266
+ );
267
+ },
268
+ });
269
+ };
@@ -0,0 +1,141 @@
1
+ /*
2
+ * Copyright: 2023 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const {
19
+ isNonEmptyObject, isString, inspect, traverseValues, join
20
+ } = require('@contrast/common');
21
+ const { createMergedTags } = require('../../../tag-utils');
22
+ const { patchType } = require('../../common');
23
+
24
+ module.exports = function(core) {
25
+ const {
26
+ depHooks,
27
+ scopes: { sources, instrumentation },
28
+ patcher,
29
+ assess: {
30
+ eventFactory: { createPropagationEvent },
31
+ dataflow: { tracker },
32
+ },
33
+ } = core;
34
+
35
+ function instrumentJoiValues(values) {
36
+ patcher.patch(values.prototype, 'get', {
37
+ name: 'joi.values',
38
+ patchType,
39
+ post(data) {
40
+ const {
41
+ args: [value, state, prefs],
42
+ result,
43
+ } = data;
44
+
45
+ if (
46
+ !value ||
47
+ !result ||
48
+ !sources.getStore()?.assess ||
49
+ instrumentation.isLocked()
50
+ ) return;
51
+
52
+ const metadata = {
53
+ state: inspect(state),
54
+ prefs: inspect(prefs),
55
+ orig: data.orig
56
+ };
57
+ const targetAbsolutePath = join(result.ref.absolute(state), '.');
58
+
59
+ if (isString(value)) {
60
+ validateStringValue(value, result.value, result.ref, targetAbsolutePath, metadata);
61
+ } else if (isNonEmptyObject(value)) {
62
+ traverseValues(value, (path, _type, v) => {
63
+ validateStringValue(v, result.value, result.ref, join([...targetAbsolutePath, ...path], '.'), metadata, path);
64
+ });
65
+ }
66
+ },
67
+ });
68
+ }
69
+
70
+ function validateStringValue(value, resValue, ref, targetAbsolutePath, metadata, path = []) {
71
+ const strInfo = ref && tracker.getData(value);
72
+ const resStringValue = path.reduce((acc, val) => acc[val] || acc, resValue);
73
+
74
+ if (strInfo) {
75
+ const validations = strInfo.eventualValidations?.[targetAbsolutePath];
76
+ const mappedValueInfo = ref.map && tracker.getData(resStringValue);
77
+ const adjustedValueInfo = ref.adjust && tracker.getData(resStringValue);
78
+
79
+ if (validations?.length && !ref.map && !ref.adjust) {
80
+ validations.forEach(validation => validation(strInfo));
81
+
82
+ delete strInfo.eventualValidations[targetAbsolutePath];
83
+ !Object.keys(strInfo.eventualValidations).length && delete strInfo.eventualValidations;
84
+ }
85
+
86
+ if (mappedValueInfo || adjustedValueInfo) {
87
+ const resultInfo = mappedValueInfo || adjustedValueInfo;
88
+ const mergedTags = createMergedTags(strInfo.tags, resultInfo.tags);
89
+ const addedTags = [
90
+ Object.keys(resultInfo.tags).filter((tag) => !(Object.keys(strInfo.tags).find(t => t === tag))),
91
+ Object.keys(strInfo.tags).filter((tag) => !(Object.keys(resultInfo.tags).find(t => t === tag)))
92
+ ];
93
+
94
+ [strInfo, resultInfo].forEach((info, idx) => {
95
+ const event = createPropagationEvent({
96
+ addedTags: [addedTags[idx]],
97
+ name: 'Joi.values.get',
98
+ moduleName: 'joi',
99
+ methodName: 'values.get',
100
+ history: [{ ...info }],
101
+ object: {
102
+ tracked: false,
103
+ value: 'Joi.string',
104
+ },
105
+ args: [
106
+ { tracked: true, value: info.value },
107
+ { tracked: false, value: metadata.state },
108
+ { tracked: false, value: metadata.prefs },
109
+ ],
110
+ result: {
111
+ tracked: false,
112
+ value: inspect({ value: resultInfo.value, ref }),
113
+ },
114
+ source: 'P0',
115
+ tags: mergedTags,
116
+ target: 'A',
117
+ stacktraceOpts: {
118
+ prependFrames: [metadata.orig],
119
+ },
120
+ });
121
+
122
+ if (event) {
123
+ Object.assign(info, event);
124
+ }
125
+ });
126
+ } else {
127
+ (ref.map || ref.adjust) && tracker.untrack(value);
128
+ }
129
+ }
130
+ }
131
+
132
+ return (core.assess.dataflow.propagation.joiInstrumentation.values = {
133
+ install() {
134
+ depHooks.resolve(
135
+ { name: 'joi', file: 'lib/values.js', version: '>=17.0.0' },
136
+ instrumentJoiValues
137
+ );
138
+ },
139
+ });
140
+ };
141
+
@@ -16,7 +16,7 @@
16
16
 
17
17
  const { patchType } = require('../../common');
18
18
 
19
- module.exports = function(core) {
19
+ module.exports = function (core) {
20
20
  const store = { lock: true, name: 'assess:propagators:pug-compile' };
21
21
  const {
22
22
  scopes: { sources, instrumentation },
@@ -28,7 +28,7 @@ module.exports = function(core) {
28
28
  const pugInstrumentation = {
29
29
  install() {
30
30
  depHooks.resolve(
31
- { name: 'pug', file: 'lib/index.js' },
31
+ { name: 'pug' },
32
32
  (pug) => patcher.patch(pug, 'compile', {
33
33
  name: 'pug.compile',
34
34
  patchType,
@@ -0,0 +1,60 @@
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
+
17
+ const { patchType } = require('../common');
18
+ const { slice } = require('@contrast/common');
19
+
20
+ module.exports = function (core) {
21
+ const {
22
+ scopes: { sources, instrumentation },
23
+ depHooks,
24
+ patcher
25
+ } = core;
26
+
27
+ const send = {};
28
+ core.assess.dataflow.propagation.send = send;
29
+
30
+ function patchSendModule(sendModuleExport) {
31
+ return patcher.patch(sendModuleExport, {
32
+ name: 'send',
33
+ patchType,
34
+ post(data) {
35
+ patcher.patch(data.result, 'sendFile', {
36
+ name: 'send.sendFile',
37
+ patchType,
38
+ pre(data) {
39
+ const { args } = data;
40
+
41
+ if (!sources.getStore()?.assess || instrumentation.isLocked()) {
42
+ return;
43
+ }
44
+
45
+ const untrackedPath = slice(` ${args[0]}`, 1);
46
+ args[0] = untrackedPath;
47
+ },
48
+ });
49
+ },
50
+ });
51
+ }
52
+
53
+ send.install = function () {
54
+ depHooks.resolve({ name: 'send' }, (sendModule) =>
55
+ patchSendModule(sendModule)
56
+ );
57
+ };
58
+
59
+ return send;
60
+ };
@@ -32,7 +32,7 @@ module.exports = function(core) {
32
32
  },
33
33
  } = core;
34
34
 
35
- function getFormatPostions(str) {
35
+ function getFormatPositions(str) {
36
36
  const positions = [];
37
37
  let index = -1;
38
38
 
@@ -50,7 +50,7 @@ module.exports = function(core) {
50
50
  return Array.from(matches, (match) => ({ [match[1]]: match.index }));
51
51
  }
52
52
 
53
- return (core.assess.dataflow.propagation.sequelizeInstrumentation = {
53
+ return core.assess.dataflow.propagation.sequelizeInstrumentation = {
54
54
  install() {
55
55
  depHooks.resolve(
56
56
  { name: 'sequelize', file: 'lib/sql-string.js' },
@@ -133,7 +133,7 @@ module.exports = function(core) {
133
133
  return;
134
134
  }
135
135
 
136
- const positions = getFormatPostions(data.args[0]);
136
+ const positions = getFormatPositions(data.args[0]);
137
137
  const firstArgInfo = tracker.getData(data.args[0]);
138
138
 
139
139
  if (!positions.length) {
@@ -307,5 +307,5 @@ module.exports = function(core) {
307
307
  }
308
308
  );
309
309
  },
310
- });
310
+ };
311
311
  };
@@ -34,7 +34,7 @@ module.exports = function(core) {
34
34
  const {
35
35
  depHooks,
36
36
  patcher,
37
- scopes: { sources },
37
+ scopes: { instrumentation, sources },
38
38
  assess: {
39
39
  eventFactory: { createSinkEvent },
40
40
  dataflow: {
@@ -62,7 +62,7 @@ module.exports = function(core) {
62
62
  const pre = (name, method, moduleName = 'fs', fullMethodName = '') => (data) => {
63
63
  const { name: methodName, indices } = method;
64
64
  const store = sources.getStore()?.assess;
65
- if (!store) return;
65
+ if (!store || instrumentation.isLocked()) return;
66
66
 
67
67
  const values = getValues(indices, data.args);
68
68
  if (!values.length) return;
@@ -31,7 +31,7 @@ module.exports = function init(core) {
31
31
 
32
32
  const createPreHook = (name) => (data) => {
33
33
  const [req, , next] = data.args;
34
- data.args[2] = function contrastNext(...args) {
34
+ data.args[2] = scopes.wrap(function contrastNext(...args) {
35
35
  const sourceContext = scopes.sources.getStore()?.assess;
36
36
 
37
37
  if (!sourceContext) {
@@ -86,7 +86,7 @@ module.exports = function init(core) {
86
86
  }
87
87
 
88
88
  return next(...args);
89
- };
89
+ });
90
90
  };
91
91
 
92
92
  assess.dataflow.sources.bodyParser1Instrumentation = {
@@ -18,7 +18,7 @@
18
18
  const { InputType } = require('@contrast/common');
19
19
  const { patchType } = require('../../common');
20
20
 
21
- module.exports = function(core) {
21
+ module.exports = function (core) {
22
22
  const {
23
23
  logger,
24
24
  depHooks,
@@ -73,17 +73,18 @@ module.exports = function(core) {
73
73
  }
74
74
  });
75
75
 
76
- patcher.patch(res, 'setHeader', {
77
- alwaysRun: true,
78
- name: 'set-header',
79
- patchType,
80
- pre(data) {
81
- const [name = '', value] = data.args;
82
- if (toLowerCase(name) === 'content-type' && value) {
83
- store.assess.responseData.contentType = value;
76
+ if (!patcher.hooks.get(res?.setHeader)?.funcKeys.has(`${patchType}:set-header`)) {
77
+ patcher.patch(res, 'setHeader', {
78
+ name: 'set-header',
79
+ patchType,
80
+ pre(data) {
81
+ const [name = '', value] = data.args;
82
+ if (toLowerCase(name) === 'content-type' && scopes.sources.getStore()?.assess && value) {
83
+ store.assess.responseData.contentType = value;
84
+ }
84
85
  }
85
- }
86
- });
86
+ });
87
+ }
87
88
 
88
89
  let uriPath, queries;
89
90
  const ix = req.url.indexOf('?');
@@ -38,8 +38,9 @@ module.exports = function(core) {
38
38
  } = core;
39
39
  const http = core.assess.responseScanning.httpInstrumentation = {};
40
40
 
41
- function parseHeaders(rawHeaders = '') {
42
- const headersArray = split(rawHeaders, '\r\n').filter(Boolean);
41
+ function parseHeaders(rawHeaders) {
42
+ const headersToParse = rawHeaders || '';
43
+ const headersArray = split(headersToParse, '\r\n').filter(Boolean);
43
44
  return headersArray.reduce((acc, header) => {
44
45
  const idx = header.indexOf(':');
45
46
 
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@contrast/assess",
3
- "version": "1.12.0",
4
- "description": "",
3
+ "version": "1.13.0",
4
+ "description": "Contrast service providing framework-agnostic Assess support",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
7
+ "files": [
8
+ "lib/"
9
+ ],
5
10
  "main": "lib/index.js",
6
- "scripts": {
7
- "test": "../scripts/test.sh"
8
- },
9
- "author": "",
10
- "license": "ISC",
11
+ "types": "lib/index.d.ts",
11
12
  "engines": {
12
13
  "npm": ">=6.13.7 <7 || >= 8.3.1",
13
14
  "node": ">= 14.15.0"
@@ -15,7 +16,7 @@
15
16
  "dependencies": {
16
17
  "@contrast/distringuish": "^4.4.0",
17
18
  "@contrast/scopes": "1.4.0",
18
- "@contrast/common": "1.14.0",
19
+ "@contrast/common": "1.15.0",
19
20
  "parseurl": "^1.3.3"
20
21
  }
21
- }
22
+ }