@contrast/agent 4.4.0-beta.0 → 4.5.2
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/bin/VERSION +1 -1
- package/bin/linux/contrast-service +0 -0
- package/bin/mac/contrast-service +0 -0
- package/bin/windows/contrast-service.exe +0 -0
- package/lib/assess/hapi/route-coverage.js +3 -3
- package/lib/assess/membrane/index.js +2 -8
- package/lib/assess/membrane/source-membrane.js +3 -4
- package/lib/assess/models/base-event.js +2 -2
- package/lib/assess/models/call-context.js +0 -3
- package/lib/assess/models/tag-range/index.js +6 -16
- package/lib/assess/policy/signatures.json +95 -0
- package/lib/assess/policy/util.js +9 -2
- package/lib/assess/propagators/path/common.js +165 -36
- package/lib/assess/propagators/path/join.js +5 -1
- package/lib/assess/propagators/path/normalize.js +5 -1
- package/lib/assess/propagators/path/resolve.js +11 -2
- package/lib/assess/response-scanning/autocomplete-missing.js +0 -2
- package/lib/assess/response-scanning/parameter-pollution.js +0 -2
- package/lib/assess/sinks/mongodb.js +11 -7
- package/lib/core/arch-components/dynamodb.js +1 -2
- package/lib/core/arch-components/dynamodbv3.js +44 -0
- package/lib/core/arch-components/index.js +1 -0
- package/lib/core/async-storage/hooks/bluebird.js +20 -0
- package/lib/core/express/utils.js +1 -1
- package/lib/core/logger/debug-logger.js +15 -17
- package/lib/core/stacktrace.js +1 -3
- package/lib/feature-set.js +2 -1
- package/lib/hooks/encoding.js +1 -1
- package/lib/hooks/patcher.js +10 -12
- package/lib/protect/analysis/aho-corasick.js +13 -30
- package/lib/protect/rules/cmd-injection-command-backdoors/backdoor-detector.js +3 -3
- package/lib/protect/rules/signatures/reflected-xss/helpers/function-call.js +1 -1
- package/lib/protect/rules/xss/helpers/function-call.js +1 -1
- package/lib/util/clean-stack.js +1 -1
- package/lib/util/clean-string/brackets.js +3 -3
- package/lib/util/clean-string/concatenations.js +1 -1
- package/lib/util/clean-string/util.js +1 -2
- package/lib/util/ip-analyzer.js +1 -1
- package/lib/util/some.js +27 -0
- package/lib/util/xml-analyzer/external-entity-finder.js +1 -1
- package/node_modules/unix-dgram/build/Makefile +2 -2
- package/node_modules/unix-dgram/build/Release/.deps/Release/obj.target/unix_dgram/src/unix_dgram.o.d +35 -35
- package/node_modules/unix-dgram/build/config.gypi +8 -8
- package/node_modules/unix-dgram/build/unix_dgram.target.mk +14 -14
- package/package.json +4 -2
|
@@ -30,14 +30,21 @@ const path = require('path');
|
|
|
30
30
|
*/
|
|
31
31
|
function splitString(str, win32) {
|
|
32
32
|
// windows treats both (forward and backward) slashes as separators
|
|
33
|
-
|
|
33
|
+
const posixRegEx = /(?=\/)/g;
|
|
34
|
+
const win32RegEx = /(?=[/\\])/g;
|
|
35
|
+
|
|
36
|
+
if (win32) {
|
|
37
|
+
str = str.replace(/\//g, '\\').split(win32RegEx);
|
|
38
|
+
} else {
|
|
39
|
+
str = str.split(posixRegEx);
|
|
40
|
+
}
|
|
34
41
|
if (str.length) {
|
|
35
42
|
// if there is an extension split it out.
|
|
36
43
|
const ix = str[str.length - 1].lastIndexOf('.');
|
|
37
44
|
if (ix > 0) {
|
|
38
45
|
const last = str[str.length - 1];
|
|
39
46
|
str[str.length - 1] = last.substr(0, ix);
|
|
40
|
-
str.push(last.substr(ix));
|
|
47
|
+
str.push(last.substr(ix + 1));
|
|
41
48
|
}
|
|
42
49
|
}
|
|
43
50
|
return str;
|
|
@@ -48,16 +55,25 @@ function splitString(str, win32) {
|
|
|
48
55
|
*
|
|
49
56
|
* @param {Object} meta object of metadata from result/arg
|
|
50
57
|
* @param {(segmentOffset: number) => boolean} meta.evaluator expression to determine the proper position of segment in string
|
|
51
|
-
* @param {number} meta.offset offset of full arg from result of path.resolve
|
|
52
58
|
* @param {string} meta.str result from path.resolve or arg
|
|
59
|
+
* @param {number} offset offset of full arg from result of path.resolve
|
|
53
60
|
* @param {string} segment path segment from one of the args to path.resolve
|
|
54
61
|
*/
|
|
55
|
-
function getSegmentOffset({ str,
|
|
62
|
+
function getSegmentOffset({ str, evaluator }, offset, segment, win32) {
|
|
56
63
|
// as the segments in each arg and in the result get traversed,
|
|
57
64
|
// winnow away the string to ensure we are finding the proper
|
|
58
65
|
// segment within the path
|
|
59
66
|
const substr = str.substring(offset);
|
|
60
|
-
|
|
67
|
+
let segmentOffset = substr.indexOf(segment);
|
|
68
|
+
// If tracking separators, evaluator will fail on extensions
|
|
69
|
+
if (substr === `.${segment}`) {
|
|
70
|
+
return segmentOffset + offset;
|
|
71
|
+
}
|
|
72
|
+
// Adjust offset if the segment does not start with a separator
|
|
73
|
+
const { sep } = path[win32 ? 'win32' : 'posix'];
|
|
74
|
+
if (substr.startsWith(sep) && !segment.startsWith(sep)) {
|
|
75
|
+
segmentOffset--;
|
|
76
|
+
}
|
|
61
77
|
|
|
62
78
|
return evaluator(segmentOffset) ? segmentOffset + offset : -1;
|
|
63
79
|
}
|
|
@@ -71,7 +87,12 @@ function getSegmentOffset({ str, offset, evaluator }, segment) {
|
|
|
71
87
|
*/
|
|
72
88
|
function isWithinTag(str, start, tag) {
|
|
73
89
|
const stop = str.length - 1 + start;
|
|
74
|
-
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
(stop <= tag.stop && stop >= tag.start) ||
|
|
93
|
+
(start >= tag.start && start <= tag.stop) ||
|
|
94
|
+
(tag.start >= start && tag.start <= stop)
|
|
95
|
+
);
|
|
75
96
|
}
|
|
76
97
|
|
|
77
98
|
/**
|
|
@@ -84,6 +105,7 @@ function isWithinTag(str, start, tag) {
|
|
|
84
105
|
*/
|
|
85
106
|
function adjustStart({ tag, argOffset, offset }) {
|
|
86
107
|
const start = tag.start - argOffset;
|
|
108
|
+
|
|
87
109
|
return start > 0 ? start + offset : offset;
|
|
88
110
|
}
|
|
89
111
|
|
|
@@ -135,15 +157,13 @@ function maybeUpdateResultMeta({ index, arg, resultMeta }) {
|
|
|
135
157
|
}
|
|
136
158
|
|
|
137
159
|
/**
|
|
138
|
-
*
|
|
160
|
+
* Calculates a new offset based on a segment
|
|
139
161
|
*
|
|
140
|
-
* @param {Object}
|
|
141
|
-
* @param {Object} argMeta metadata for a given argument
|
|
162
|
+
* @param {Object} offset offset of the object
|
|
142
163
|
* @param {string} segment path segment from one of the args to path.resolve
|
|
143
164
|
*/
|
|
144
|
-
function calculateNewOffset(
|
|
145
|
-
|
|
146
|
-
argMeta.offset = argMeta.offset + segment.length + 1;
|
|
165
|
+
function calculateNewOffset(offset, segment) {
|
|
166
|
+
return offset + segment.length;
|
|
147
167
|
}
|
|
148
168
|
|
|
149
169
|
/**
|
|
@@ -153,10 +173,89 @@ function calculateNewOffset(resultMeta, argMeta, segment) {
|
|
|
153
173
|
* @param {string} segment path segment to check
|
|
154
174
|
* @return {boolean}
|
|
155
175
|
*/
|
|
156
|
-
function
|
|
176
|
+
function isApplicableSegment(segment) {
|
|
157
177
|
return segment !== '.' && segment !== '..' && segment !== '';
|
|
158
178
|
}
|
|
159
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Filters invalid segments like those that are not part of the end result.
|
|
182
|
+
* It also calculates additional offset.
|
|
183
|
+
*
|
|
184
|
+
* @param {*} segments splitted path into segments
|
|
185
|
+
* @param {Object} resultMeta metadata from result of path.resolve
|
|
186
|
+
* @param {Object} data the data object of the propagate function
|
|
187
|
+
* @param {number} index the iteration index
|
|
188
|
+
* @param {boolean} win32 indicating win32 to replace `/` with `\'
|
|
189
|
+
*/
|
|
190
|
+
function filterSegmentsAndCalculateOffset(
|
|
191
|
+
segments,
|
|
192
|
+
resultMeta,
|
|
193
|
+
data,
|
|
194
|
+
index,
|
|
195
|
+
win32
|
|
196
|
+
) {
|
|
197
|
+
const { sep } = path[win32 ? 'win32' : 'posix'];
|
|
198
|
+
const isFirstIteration = index === 0;
|
|
199
|
+
const validSegments = [];
|
|
200
|
+
let additionalOffset = 0;
|
|
201
|
+
|
|
202
|
+
segments.reduce(
|
|
203
|
+
// eslint-disable-next-line complexity
|
|
204
|
+
(accumulator, segment) => {
|
|
205
|
+
let hasChange = false;
|
|
206
|
+
if (!isApplicableSegment(segment)) return accumulator;
|
|
207
|
+
|
|
208
|
+
if (!accumulator.isModified && !isFirstIteration) {
|
|
209
|
+
const previousArg = data.args[index - 1];
|
|
210
|
+
|
|
211
|
+
const sepAdded = !segment.startsWith(sep) && !previousArg.endsWith(sep);
|
|
212
|
+
const sepTaken = segment.startsWith(sep) && previousArg.endsWith(sep);
|
|
213
|
+
accumulator.isModified = sepAdded || sepTaken;
|
|
214
|
+
hasChange = sepAdded || sepTaken;
|
|
215
|
+
additionalOffset = hasChange ? (sepAdded ? 1 : -1) : 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const offset = getSegmentOffset(
|
|
219
|
+
resultMeta,
|
|
220
|
+
accumulator.offset + additionalOffset + accumulator.fileDotSeparator,
|
|
221
|
+
segment,
|
|
222
|
+
win32
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
// no reason to proceed if segment is not in final result
|
|
226
|
+
if (offset === -1) {
|
|
227
|
+
if (hasChange) {
|
|
228
|
+
additionalOffset = 0;
|
|
229
|
+
accumulator.isModified = false;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return accumulator;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// in case we have a file we need to increment the offset
|
|
236
|
+
if (resultMeta.str[offset + segment.length] === '.') {
|
|
237
|
+
accumulator.fileDotSeparator = 1;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
validSegments.push(segment);
|
|
241
|
+
accumulator.offset = calculateNewOffset(accumulator.offset, segment);
|
|
242
|
+
accumulator.isModified = true;
|
|
243
|
+
|
|
244
|
+
return accumulator;
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
offset: resultMeta.offset,
|
|
248
|
+
fileDotSeparator: 0,
|
|
249
|
+
isModified: false
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
additionalOffset,
|
|
255
|
+
segments: validSegments
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
160
259
|
/**
|
|
161
260
|
* Moves the tag ranges properly based on if a path segment exists in the
|
|
162
261
|
* result
|
|
@@ -164,42 +263,66 @@ function applicableSegment(segment) {
|
|
|
164
263
|
* @param {Object} resultMeta metadata for the result
|
|
165
264
|
* @param {Object} argMeta meta for a given argument
|
|
166
265
|
* @param {boolean} win32 indicating win32 to replace `/` with `\'
|
|
266
|
+
* @param {Object} data the data object of the propagate function
|
|
267
|
+
* @param {number} index the iteration index
|
|
167
268
|
*/
|
|
168
|
-
function adjustTagsToPart(resultMeta, argMeta, win32) {
|
|
269
|
+
function adjustTagsToPart(resultMeta, argMeta, win32, data, index) {
|
|
169
270
|
const { str, tagRanges } = argMeta;
|
|
170
|
-
const segments =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
271
|
+
const { segments, additionalOffset } = filterSegmentsAndCalculateOffset(
|
|
272
|
+
splitString(str, win32),
|
|
273
|
+
resultMeta,
|
|
274
|
+
data,
|
|
275
|
+
index,
|
|
276
|
+
win32
|
|
277
|
+
);
|
|
176
278
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (offset === -1) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
279
|
+
// updating the offset
|
|
280
|
+
resultMeta.offset += additionalOffset;
|
|
182
281
|
|
|
183
|
-
|
|
282
|
+
return segments.reduce((newTags, segment) => {
|
|
283
|
+
const offset = getSegmentOffset(
|
|
284
|
+
resultMeta,
|
|
285
|
+
resultMeta.offset,
|
|
286
|
+
segment,
|
|
287
|
+
win32
|
|
288
|
+
);
|
|
184
289
|
|
|
185
|
-
|
|
290
|
+
const argOffset = getSegmentOffset(argMeta, argMeta.offset, segment, win32);
|
|
291
|
+
|
|
292
|
+
// updating the offset
|
|
293
|
+
resultMeta.offset = calculateNewOffset(resultMeta.offset, segment);
|
|
294
|
+
argMeta.offset = calculateNewOffset(argMeta.offset, segment);
|
|
295
|
+
|
|
296
|
+
// in case we have a file we need to increment the offset
|
|
297
|
+
if (resultMeta.str[offset + segment.length] === '.') {
|
|
298
|
+
resultMeta.offset += 1;
|
|
299
|
+
}
|
|
186
300
|
|
|
187
301
|
tagRanges.forEach((tag) => {
|
|
188
|
-
if (isWithinTag(segment, argOffset, tag))
|
|
189
|
-
const start = adjustStart({ tag, argOffset, offset });
|
|
190
|
-
const stop = adjustStop({ tag, argOffset, offset, segment });
|
|
302
|
+
if (!isWithinTag(segment, argOffset, tag)) return;
|
|
191
303
|
|
|
192
|
-
|
|
193
|
-
|
|
304
|
+
const start = adjustStart({
|
|
305
|
+
tag,
|
|
306
|
+
argOffset,
|
|
307
|
+
offset
|
|
308
|
+
});
|
|
309
|
+
const stop = adjustStop({
|
|
310
|
+
tag,
|
|
311
|
+
argOffset,
|
|
312
|
+
offset,
|
|
313
|
+
segment
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
newTags.push(new TagRange(start, stop, tag.tag));
|
|
194
317
|
});
|
|
195
|
-
});
|
|
196
318
|
|
|
197
|
-
|
|
319
|
+
return newTags;
|
|
320
|
+
}, []);
|
|
198
321
|
}
|
|
199
322
|
|
|
200
323
|
function propagate({ resultMeta, data, win32 }) {
|
|
201
324
|
if (!resultMeta.evaluator) {
|
|
202
|
-
resultMeta.evaluator = (segmentOffset) => segmentOffset ===
|
|
325
|
+
resultMeta.evaluator = (segmentOffset) => segmentOffset === 0;
|
|
203
326
|
}
|
|
204
327
|
|
|
205
328
|
data.args.forEach((arg, index) => {
|
|
@@ -213,7 +336,13 @@ function propagate({ resultMeta, data, win32 }) {
|
|
|
213
336
|
tagRanges: argData.tracked ? argData.tagRanges : []
|
|
214
337
|
};
|
|
215
338
|
|
|
216
|
-
const targetTagRanges = adjustTagsToPart(
|
|
339
|
+
const targetTagRanges = adjustTagsToPart(
|
|
340
|
+
resultMeta,
|
|
341
|
+
argMeta,
|
|
342
|
+
win32,
|
|
343
|
+
data,
|
|
344
|
+
index
|
|
345
|
+
);
|
|
217
346
|
|
|
218
347
|
if (targetTagRanges.length > 0) {
|
|
219
348
|
resultMeta.parents.push(argData.event);
|
|
@@ -31,7 +31,11 @@ function hookPath(path) {
|
|
|
31
31
|
resultMeta.offset = 0;
|
|
32
32
|
resultMeta.evaluator = (segmentOffset) => segmentOffset === 0;
|
|
33
33
|
}
|
|
34
|
-
propagate({
|
|
34
|
+
propagate({
|
|
35
|
+
data,
|
|
36
|
+
resultMeta,
|
|
37
|
+
win32: os === 'win32'
|
|
38
|
+
});
|
|
35
39
|
}
|
|
36
40
|
});
|
|
37
41
|
}
|
|
@@ -43,7 +43,11 @@ module.exports.handle = function handle() {
|
|
|
43
43
|
resultMeta.evaluator = (segmentOffset) => segmentOffset > -1;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
propagate({
|
|
46
|
+
propagate({
|
|
47
|
+
resultMeta,
|
|
48
|
+
data,
|
|
49
|
+
win32: os === 'win32'
|
|
50
|
+
});
|
|
47
51
|
}
|
|
48
52
|
});
|
|
49
53
|
}
|
|
@@ -34,7 +34,12 @@ module.exports.handle = function handle() {
|
|
|
34
34
|
if (!data.args[0]) return;
|
|
35
35
|
const resultMeta = getResultMeta(data, 'resolve');
|
|
36
36
|
const isAbsolute = absolutePath(data.args[0]);
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
plus one in case isAbsolute is false since our working deretory ends without slash
|
|
40
|
+
example: /Users/John/Documents/Projects/node-agent
|
|
41
|
+
*/
|
|
42
|
+
resultMeta.offset = isAbsolute ? 0 : process.cwd().length + 1;
|
|
38
43
|
|
|
39
44
|
// a work-around for paths like C:\Windows
|
|
40
45
|
if (
|
|
@@ -45,7 +50,11 @@ module.exports.handle = function handle() {
|
|
|
45
50
|
resultMeta.evaluator = (segmentOffset) => segmentOffset > -1;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
propagate({
|
|
53
|
+
propagate({
|
|
54
|
+
data,
|
|
55
|
+
resultMeta,
|
|
56
|
+
win32: os === 'win32'
|
|
57
|
+
});
|
|
49
58
|
}
|
|
50
59
|
});
|
|
51
60
|
}
|
|
@@ -33,6 +33,7 @@ const { PATCH_TYPES } = require('../../constants');
|
|
|
33
33
|
const requireHook = require('../../hooks/require');
|
|
34
34
|
const { Signature, CallContext } = require('../models');
|
|
35
35
|
const policy = require('../policy');
|
|
36
|
+
const Scopes = require('../../core/async-storage/scopes');
|
|
36
37
|
|
|
37
38
|
const ruleId = 'nosql-injection';
|
|
38
39
|
const disallowedTags = [
|
|
@@ -268,13 +269,16 @@ module.exports = ({ common }) => {
|
|
|
268
269
|
*/
|
|
269
270
|
mongoSink.assess = (query, context) => {
|
|
270
271
|
const searchDepth = 3;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
272
|
+
let vulnerableString;
|
|
273
|
+
|
|
274
|
+
Scopes.runInAllowAllScope(() => {
|
|
275
|
+
vulnerableString = common.isVulnerable({
|
|
276
|
+
searchDepth,
|
|
277
|
+
disallowedTags,
|
|
278
|
+
requiredTags,
|
|
279
|
+
input: query
|
|
280
|
+
});
|
|
281
|
+
}, 'mongodbSink.assess');
|
|
278
282
|
|
|
279
283
|
if (vulnerableString) {
|
|
280
284
|
mongoSink.report(vulnerableString, context);
|
|
@@ -18,7 +18,6 @@ const agentEmitter = require('../../agent-emitter');
|
|
|
18
18
|
const { PATCH_TYPES } = require('../../constants');
|
|
19
19
|
const ModuleHook = require('../../hooks/require');
|
|
20
20
|
const patcher = require('../../hooks/patcher');
|
|
21
|
-
const _ = require('lodash');
|
|
22
21
|
|
|
23
22
|
ModuleHook.resolve({ name: 'aws-sdk' }, (AWS) => {
|
|
24
23
|
patcher.patch(AWS.DynamoDB.prototype, 'makeRequest', {
|
|
@@ -27,7 +26,7 @@ ModuleHook.resolve({ name: 'aws-sdk' }, (AWS) => {
|
|
|
27
26
|
alwaysRun: true,
|
|
28
27
|
post(ctx) {
|
|
29
28
|
try {
|
|
30
|
-
const endpoint =
|
|
29
|
+
const { endpoint } = this;
|
|
31
30
|
agentEmitter.emit('architectureComponent', {
|
|
32
31
|
vendor: 'DynamoDB',
|
|
33
32
|
url: new URL(`${endpoint.protocol}//${endpoint.hostname}`).toString(),
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Copyright: 2021 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 logger = require('../logger')('contrast:arch-component');
|
|
17
|
+
const agentEmitter = require('../../agent-emitter');
|
|
18
|
+
const { PATCH_TYPES } = require('../../constants');
|
|
19
|
+
const ModuleHook = require('../../hooks/require');
|
|
20
|
+
const patcher = require('../../hooks/patcher');
|
|
21
|
+
|
|
22
|
+
function emitArchitectureComponent(endpoint) {
|
|
23
|
+
agentEmitter.emit('architectureComponent', {
|
|
24
|
+
vendor: 'DynamoDB',
|
|
25
|
+
url: new URL(`${endpoint.protocol}//${endpoint.hostname}`).toString(),
|
|
26
|
+
remoteHost: '',
|
|
27
|
+
remotePort: endpoint.port
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ModuleHook.resolve({ name: '@aws-sdk/client-dynamodb' }, (AWS) => {
|
|
32
|
+
patcher.patch(AWS.DynamoDBClient.prototype, 'send', {
|
|
33
|
+
name: 'DynamoDBv3.arch_component',
|
|
34
|
+
patchType: PATCH_TYPES.ARCH_COMPONENT,
|
|
35
|
+
alwaysRun: true,
|
|
36
|
+
post(ctx) {
|
|
37
|
+
try {
|
|
38
|
+
this.config.endpoint().then(emitArchitectureComponent);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
logger.warn('unable to report DynamoDB architecture component\n', err);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -23,6 +23,26 @@ module.exports = function() {
|
|
|
23
23
|
moduleHook.resolve({ name: 'bluebird' }, (bluebird) => {
|
|
24
24
|
module.exports.patchConfig(bluebird);
|
|
25
25
|
module.exports.patchAddCallbacks(bluebird);
|
|
26
|
+
module.exports.patchGetNewLibraryCopy(bluebird);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Ensures that new library copies are also instrumented.
|
|
32
|
+
* @param {function} bluebird the library export
|
|
33
|
+
*/
|
|
34
|
+
module.exports.patchGetNewLibraryCopy = function(bluebird) {
|
|
35
|
+
if (typeof bluebird.getNewLibraryCopy !== 'function') {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
patcher.patch(bluebird, 'getNewLibraryCopy', {
|
|
40
|
+
alwaysRun: true,
|
|
41
|
+
name: 'bluebird.getNewLibraryCopy',
|
|
42
|
+
patchType: PATCH_TYPES.ASYNC_CONTEXT,
|
|
43
|
+
post(data) {
|
|
44
|
+
module.exports.patchAddCallbacks(data.result);
|
|
45
|
+
}
|
|
26
46
|
});
|
|
27
47
|
};
|
|
28
48
|
|
|
@@ -273,7 +273,7 @@ const normalizeSegment = (segment) => {
|
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
} else if (segment instanceof RegExp) {
|
|
276
|
-
segment = segment.toString().replace(
|
|
276
|
+
segment = segment.toString().replace(/(^\/?)|(\/?$)/g, '');
|
|
277
277
|
segment = `/{${segment}}`;
|
|
278
278
|
} else if (Array.isArray(segment)) {
|
|
279
279
|
segment = segment.map((s) => `${normalizeSignatureArg(`${s}`)}`);
|
|
@@ -314,23 +314,21 @@ class DebugLogFactory {
|
|
|
314
314
|
};
|
|
315
315
|
|
|
316
316
|
[...levelNames, 'console'].forEach((level) => {
|
|
317
|
-
if (level
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
};
|
|
333
|
-
}
|
|
317
|
+
if (level === 'console') {
|
|
318
|
+
const orig = logger[level].bind(logger);
|
|
319
|
+
logger[level] = function(...args) {
|
|
320
|
+
return Scopes.runInNoInstrumentationScope(
|
|
321
|
+
() => orig(...args),
|
|
322
|
+
DEADZONE_NAME
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
} else {
|
|
326
|
+
logger[level] = function(message, ...splat) {
|
|
327
|
+
return Scopes.runInNoInstrumentationScope(
|
|
328
|
+
() => logger.log({ level, message, splat }),
|
|
329
|
+
DEADZONE_NAME
|
|
330
|
+
);
|
|
331
|
+
};
|
|
334
332
|
}
|
|
335
333
|
});
|
|
336
334
|
|
package/lib/core/stacktrace.js
CHANGED
|
@@ -21,7 +21,6 @@ const _isAgentPath = require('../util/is-agent-path');
|
|
|
21
21
|
|
|
22
22
|
const STACK_TRACE_LIMIT = 25;
|
|
23
23
|
const EVAL_ORIGIN_REGEX = /\((.*?):(\d+):\d+\)/;
|
|
24
|
-
const EJS_EVAL_ORIGIN_REGEX = /(.*\.ejs$)/;
|
|
25
24
|
const EVENTS_FILE = semver.gte(process.version, '16.0.0')
|
|
26
25
|
? 'node:events'
|
|
27
26
|
: 'events.js';
|
|
@@ -146,8 +145,7 @@ class Factory {
|
|
|
146
145
|
if (callsite.isEval()) {
|
|
147
146
|
evalOrigin = Factory.formatFileName(callsite.getEvalOrigin());
|
|
148
147
|
[, file, lineNumber, columnNumber] =
|
|
149
|
-
evalOrigin.match(EVAL_ORIGIN_REGEX) ||
|
|
150
|
-
evalOrigin.match(EJS_EVAL_ORIGIN_REGEX);
|
|
148
|
+
evalOrigin.match(EVAL_ORIGIN_REGEX) || evalOrigin.endsWith('.ejs');
|
|
151
149
|
}
|
|
152
150
|
|
|
153
151
|
file = file || callsite.getFileName();
|
package/lib/feature-set.js
CHANGED
package/lib/hooks/encoding.js
CHANGED
|
@@ -31,7 +31,7 @@ module.exports = function() {
|
|
|
31
31
|
hardPatchEncoding(Buffer.prototype, 'Buffer', 'lastIndexOf', 0);
|
|
32
32
|
hardPatchEncoding(Buffer.prototype, 'Buffer', 'includes', 0);
|
|
33
33
|
|
|
34
|
-
hardPatchEncoding(Buffer, 'Buffer', 'alloc', 0
|
|
34
|
+
hardPatchEncoding(Buffer, 'Buffer', 'alloc', 0);
|
|
35
35
|
hardPatchEncoding(Buffer.prototype, 'Buffer', 'fill', 0);
|
|
36
36
|
};
|
|
37
37
|
|
package/lib/hooks/patcher.js
CHANGED
|
@@ -22,19 +22,21 @@ Copyright: 2021 Contrast Security, Inc
|
|
|
22
22
|
// the arguments keyword instead of providing a `...args` rest param.
|
|
23
23
|
/* eslint-disable prefer-rest-params */
|
|
24
24
|
|
|
25
|
-
const { promisify } = require('util');
|
|
26
25
|
const logger = require('../core/logger')('contrast:hooks');
|
|
27
26
|
const agent = require('../agent');
|
|
28
|
-
const perfLogger = require('../core/logger/perf-logger')(agent);
|
|
29
|
-
const _ = require('lodash');
|
|
30
27
|
const perfLoggingEnabled =
|
|
31
28
|
agent.config && agent.config.agent.node.req_perf_logging;
|
|
29
|
+
const perfLogger = perfLoggingEnabled
|
|
30
|
+
? require('../core/logger/perf-logger')(agent)
|
|
31
|
+
: undefined;
|
|
32
32
|
const tracker = require('../tracker.js');
|
|
33
33
|
const { AsyncStorage } = require('../core/async-storage');
|
|
34
34
|
const {
|
|
35
35
|
Scopes,
|
|
36
36
|
SCOPE_NAMES: { NO_PROPAGATION }
|
|
37
37
|
} = require('../core/async-storage/scopes');
|
|
38
|
+
const promisifyCustom = Symbol.for('nodejs.util.promisify.custom');
|
|
39
|
+
const some = require('../util/some');
|
|
38
40
|
|
|
39
41
|
// When a pre-hook returns the result of this function, the value passed will
|
|
40
42
|
// be used in place of the original function's return value, and the original
|
|
@@ -43,12 +45,8 @@ function preempt(value) {
|
|
|
43
45
|
return new PatcherPreempt(value);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
const { toString } = {};
|
|
47
|
-
|
|
48
48
|
function isFunction(fn) {
|
|
49
|
-
return
|
|
50
|
-
toString.call(this, fn) === '[object Function]' || fn instanceof Function
|
|
51
|
-
);
|
|
49
|
+
return fn instanceof Function || typeof fn === 'function';
|
|
52
50
|
}
|
|
53
51
|
|
|
54
52
|
function PatcherPreempt(v) {
|
|
@@ -118,7 +116,7 @@ function runHooks(type, options, data, fn, thisTarget) {
|
|
|
118
116
|
* @return {boolean}
|
|
119
117
|
*/
|
|
120
118
|
function argsTracked(args) {
|
|
121
|
-
return
|
|
119
|
+
return some(args, (arg) => arg && tracker.getData(arg).tracked);
|
|
122
120
|
}
|
|
123
121
|
|
|
124
122
|
/**
|
|
@@ -283,7 +281,7 @@ function hookFunction(fn, options) {
|
|
|
283
281
|
return data.result;
|
|
284
282
|
}
|
|
285
283
|
|
|
286
|
-
// copy over all properties if there are properties on the original
|
|
284
|
+
// copy over all properties if there are properties on the original function.
|
|
287
285
|
// an example of this is the version of buffer you get from require('buffer')
|
|
288
286
|
// see NODE-335 for further background.
|
|
289
287
|
const descriptors = Object.getOwnPropertyDescriptors(fn);
|
|
@@ -292,7 +290,7 @@ function hookFunction(fn, options) {
|
|
|
292
290
|
...Object.getOwnPropertyNames(descriptors)
|
|
293
291
|
]) {
|
|
294
292
|
if (
|
|
295
|
-
key ===
|
|
293
|
+
key === promisifyCustom &&
|
|
296
294
|
typeof descriptors[key].value === 'function'
|
|
297
295
|
) {
|
|
298
296
|
// We must assume that custom promisified function values are true aliases
|
|
@@ -482,7 +480,7 @@ function patch(obj, props, options) {
|
|
|
482
480
|
}
|
|
483
481
|
|
|
484
482
|
const hookedMethods = hookableMethods(obj, props).map(function(prop) {
|
|
485
|
-
const opts =
|
|
483
|
+
const opts = typeof options === 'object' ? { ...options } : options;
|
|
486
484
|
|
|
487
485
|
// staticName means do not append methods to final name
|
|
488
486
|
// only used for Function(aka global.ContrastFunction)
|