@contrast/agent 4.18.0 → 4.19.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/changelog.config.js +56 -0
- package/lib/assess/models/call-context.js +18 -0
- package/lib/assess/propagators/joi/index.js +1 -0
- package/lib/assess/propagators/joi/keys.js +72 -0
- package/lib/assess/propagators/joi/string-base.js +32 -3
- package/lib/assess/propagators/joi/string-schema.js +43 -16
- package/lib/assess/propagators/joi/values.js +25 -14
- package/lib/assess/propagators/utils.js +40 -3
- package/lib/core/async-storage/hooks/{mongodb-core.js → mongodb.js} +43 -7
- package/lib/core/config/util.js +4 -0
- package/lib/instrumentation.js +2 -2
- package/lib/reporter/models/finding/event.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
jira: {
|
|
19
|
+
baseUrl: `https://${process.env.JIRA_HOST}`,
|
|
20
|
+
ticketIDPattern: /(NODE+-?[0-9]{4})/i,
|
|
21
|
+
excludeIssueTypes: ['Sub-task', 'Release'],
|
|
22
|
+
api: {
|
|
23
|
+
host: process.env.JIRA_HOST,
|
|
24
|
+
email: process.env.JIRA_EMAIL,
|
|
25
|
+
token: process.env.JIRA_TOKEN
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
hideEmptyBlocks: true,
|
|
29
|
+
template: `## <%= process.env.VERSION -%>
|
|
30
|
+
|
|
31
|
+
<% blockTickets = tickets.all.filter((t) => !t.reverted); -%>
|
|
32
|
+
<% if (blockTickets.length > 0 || !options.hideEmptyBlocks) { -%>
|
|
33
|
+
### Jira Tickets
|
|
34
|
+
---------------------
|
|
35
|
+
<% blockTickets.forEach(ticket => { -%>
|
|
36
|
+
* <<%= ticket.fields.issuetype.name %>> - <%- ticket.fields.summary %>
|
|
37
|
+
[<%= ticket.key %>](<%= jira.baseUrl + '/browse/' + ticket.key %>)
|
|
38
|
+
<% }); -%>
|
|
39
|
+
<% if (!blockTickets.length) {%> ~ None ~ <% } %>
|
|
40
|
+
<% } -%>
|
|
41
|
+
<% blockNoTickets = commits.noTickets; -%>
|
|
42
|
+
<% if (blockNoTickets.length > 0 || !options.hideEmptyBlocks) { -%>
|
|
43
|
+
|
|
44
|
+
### Other Commits
|
|
45
|
+
---------------------
|
|
46
|
+
<% blockNoTickets.forEach(commit => { -%>
|
|
47
|
+
* <%= commit.slackUser ? '@'+commit.slackUser.name : commit.authorName %> - <<%= commit.revision.substr(0, 7) %>> - <%= commit.summary %>
|
|
48
|
+
<% }); -%>
|
|
49
|
+
<% if (!blockNoTickets.length) {%> ~ None ~ <% } %>
|
|
50
|
+
<% } -%>
|
|
51
|
+
<% blockPendingByOwner = tickets.pendingByOwner; -%>
|
|
52
|
+
<% if (blockPendingByOwner.length > 0 || !options.hideEmptyBlocks) { -%>
|
|
53
|
+
<% } -%>
|
|
54
|
+
--------------------
|
|
55
|
+
`
|
|
56
|
+
};
|
|
@@ -20,6 +20,7 @@ const tracker = require('../../tracker');
|
|
|
20
20
|
const stackFactory = require('../../core/stacktrace').singleton;
|
|
21
21
|
const distringuish = require('@contrast/distringuish-prebuilt');
|
|
22
22
|
const { PROXY_TARGET } = require('../../../lib/constants');
|
|
23
|
+
const TagRange = require('../models/tag-range');
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* Holds information about the call context of a function
|
|
@@ -102,6 +103,22 @@ module.exports = class CallContext {
|
|
|
102
103
|
return !!(str && typeof str === 'object' && str[PROXY_TARGET]);
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
static getDisplayRange(arg) {
|
|
107
|
+
if (tracker.getData(arg)) {
|
|
108
|
+
return new TagRange(0, arg.length - 1, 'untrusted');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (arg && typeof arg === 'object') {
|
|
112
|
+
for (let key in arg) {
|
|
113
|
+
if (tracker.getData(arg[key])) {
|
|
114
|
+
const start = CallContext.valueString(arg).indexOf(arg[key]);
|
|
115
|
+
return new TagRange(start, start + arg[key].length - 1, 'untrusted');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return {}
|
|
120
|
+
}
|
|
121
|
+
|
|
105
122
|
set result(result) {
|
|
106
123
|
this.__result = CallContext.valueString(result);
|
|
107
124
|
this.resultTracked = CallContext.isTracked(result);
|
|
@@ -113,6 +130,7 @@ module.exports = class CallContext {
|
|
|
113
130
|
set args(args) {
|
|
114
131
|
this.__args = args.map(CallContext.valueString);
|
|
115
132
|
this.argsTracked = args.map((arg) => CallContext.isTracked(arg));
|
|
133
|
+
this.argsDisplayRanges = args.map((arg) => CallContext.getDisplayRange(arg));
|
|
116
134
|
}
|
|
117
135
|
|
|
118
136
|
get args() {
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
'use strict';
|
|
16
|
+
const patcher = require('../../../hooks/patcher');
|
|
17
|
+
const requireHook = require('../../../hooks/require');
|
|
18
|
+
const {
|
|
19
|
+
PATCH_TYPES: { ASSESS_PROPAGATOR },
|
|
20
|
+
} = require('../../../constants');
|
|
21
|
+
const { isObject } = require('../utils');
|
|
22
|
+
|
|
23
|
+
requireHook.resolve(
|
|
24
|
+
{ name: 'joi', file: 'lib/types/keys.js', version: '>=17.0.0' },
|
|
25
|
+
(joi) => {
|
|
26
|
+
patcher.patch(joi.__proto__, 'keys', {
|
|
27
|
+
name: 'joi.keys',
|
|
28
|
+
alwaysRun: true,
|
|
29
|
+
patchType: ASSESS_PROPAGATOR,
|
|
30
|
+
pre(data) {
|
|
31
|
+
if (!data || !data.args) return;
|
|
32
|
+
const value = data.args[0];
|
|
33
|
+
if (value) {
|
|
34
|
+
traverseObject(data.obj.$_root, value, value);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const traverseObject = (joi, currentValue, originalInput, currentPath = []) => {
|
|
42
|
+
if (joi.isSchema(currentValue) || joi.isExpression(currentValue)) return;
|
|
43
|
+
if (joi.isRef(currentValue)) {
|
|
44
|
+
const referenceInstance = currentValue;
|
|
45
|
+
|
|
46
|
+
const targetSchemaInstace = currentValue.path.reduce(
|
|
47
|
+
(acc, value) => acc[value] || acc,
|
|
48
|
+
originalInput
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
if (!targetSchemaInstace) return;
|
|
52
|
+
|
|
53
|
+
if (!targetSchemaInstace.__CONTRAST__) {
|
|
54
|
+
Object.defineProperty(targetSchemaInstace, '__CONTRAST__', {
|
|
55
|
+
enumerable: false,
|
|
56
|
+
configurable: true,
|
|
57
|
+
value: {
|
|
58
|
+
refInstances: {},
|
|
59
|
+
},
|
|
60
|
+
writable: true,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
targetSchemaInstace.__CONTRAST__.refInstances[currentPath.join('.')] = referenceInstance;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (isObject(currentValue)) {
|
|
68
|
+
for (const [objKey, objValue] of Object.entries(currentValue)) {
|
|
69
|
+
traverseObject(joi, objValue, originalInput, [...currentPath, objKey]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -25,6 +25,7 @@ const { PropagationEvent, Signature, CallContext } = require('../../models');
|
|
|
25
25
|
const TagRange = require('../../models/tag-range');
|
|
26
26
|
const tagRangeUtil = require('../../models/tag-range/util');
|
|
27
27
|
const agent = require('../../../agent');
|
|
28
|
+
const { setProxyTaggedString, getContrastData } = require('../utils');
|
|
28
29
|
|
|
29
30
|
const areThereRules = (obj) =>
|
|
30
31
|
obj &&
|
|
@@ -43,7 +44,35 @@ function instrumentJoiString(string) {
|
|
|
43
44
|
name: 'joi.string.validate',
|
|
44
45
|
patchType: ASSESS_PROPAGATOR,
|
|
45
46
|
post(data) {
|
|
46
|
-
const
|
|
47
|
+
const input = data.args[0];
|
|
48
|
+
const contrastData = getContrastData(data);
|
|
49
|
+
const doesSchemaHaveReferences = !!contrastData;
|
|
50
|
+
|
|
51
|
+
let trackingData = tracker.getData(input);
|
|
52
|
+
|
|
53
|
+
if (!trackingData && !data.result && doesSchemaHaveReferences) {
|
|
54
|
+
const proxyTaggedString = setProxyTaggedString(
|
|
55
|
+
contrastData,
|
|
56
|
+
input,
|
|
57
|
+
tracker
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
trackingData = tracker.getData(proxyTaggedString);
|
|
61
|
+
|
|
62
|
+
Object.values(contrastData.refInstances).forEach(
|
|
63
|
+
(referenceInstance) => {
|
|
64
|
+
Object.defineProperty(referenceInstance, '__CONTRAST__', {
|
|
65
|
+
enumerable: false,
|
|
66
|
+
configurable: true,
|
|
67
|
+
value: {
|
|
68
|
+
proxyTaggedString,
|
|
69
|
+
},
|
|
70
|
+
writable: true,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
47
76
|
if (
|
|
48
77
|
areThereRules(data.args[1]) &&
|
|
49
78
|
data.args[1].schema._rules.find((rule) => rule.name === 'pattern') &&
|
|
@@ -51,11 +80,11 @@ function instrumentJoiString(string) {
|
|
|
51
80
|
)
|
|
52
81
|
return;
|
|
53
82
|
|
|
54
|
-
if (data.result
|
|
83
|
+
if (!data.result && trackingData) {
|
|
55
84
|
const { event } = trackingData;
|
|
56
85
|
trackingData.tagRanges = tagRangeUtil.add(
|
|
57
86
|
trackingData.tagRanges,
|
|
58
|
-
new TagRange(0,
|
|
87
|
+
new TagRange(0, input.length - 1, 'string-type-checked')
|
|
59
88
|
);
|
|
60
89
|
trackingData.event = new PropagationEvent({
|
|
61
90
|
context: new CallContext(data),
|
|
@@ -18,12 +18,13 @@ const _ = require('lodash');
|
|
|
18
18
|
const requireHook = require('../../../hooks/require');
|
|
19
19
|
const patcher = require('../../../hooks/patcher');
|
|
20
20
|
const {
|
|
21
|
-
PATCH_TYPES: { ASSESS_PROPAGATOR }
|
|
21
|
+
PATCH_TYPES: { ASSESS_PROPAGATOR },
|
|
22
22
|
} = require('../../../constants');
|
|
23
23
|
const { PropagationEvent, Signature, CallContext } = require('../../models');
|
|
24
24
|
const TagRange = require('../../models/tag-range');
|
|
25
25
|
const tagRangeUtil = require('../../models/tag-range/util');
|
|
26
26
|
const tracker = require('../../../tracker');
|
|
27
|
+
const { setProxyTaggedString, getContrastData } = require('../utils');
|
|
27
28
|
|
|
28
29
|
const VALIDATORS = {
|
|
29
30
|
base64: 'alphanum-space-hyphen',
|
|
@@ -36,7 +37,7 @@ const VALIDATORS = {
|
|
|
36
37
|
creditCard: 'limited-chars',
|
|
37
38
|
ip: 'limited-chars',
|
|
38
39
|
hostname: 'alphanum-space-hyphen',
|
|
39
|
-
domain: 'alphanum-space-hyphen'
|
|
40
|
+
domain: 'alphanum-space-hyphen',
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
requireHook.resolve(
|
|
@@ -96,12 +97,12 @@ function reTrackCoercedValue(coerce, rule) {
|
|
|
96
97
|
trackedArgsData: argContrastProperties,
|
|
97
98
|
tagRanges: tracked.props.tagRanges,
|
|
98
99
|
target: 'R',
|
|
99
|
-
joiMethod: rule
|
|
100
|
+
joiMethod: rule,
|
|
100
101
|
});
|
|
101
102
|
|
|
102
103
|
data.result = { value: tracked.str };
|
|
103
104
|
}
|
|
104
|
-
}
|
|
105
|
+
},
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
108
|
|
|
@@ -119,27 +120,53 @@ function wrapRuleAsValidator(rules, rule, tagName) {
|
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
const argContrastProperties = tracker.getData(args[0]);
|
|
122
|
-
|
|
123
|
+
|
|
124
|
+
const contrastData = getContrastData(data);
|
|
125
|
+
const doesSchemaHaveReferences = !!contrastData;
|
|
126
|
+
|
|
127
|
+
if (!argContrastProperties && !doesSchemaHaveReferences) {
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
let trackingData = tracker.getData(result);
|
|
132
|
+
|
|
133
|
+
if (!trackingData && doesSchemaHaveReferences) {
|
|
134
|
+
const proxyTaggedString = setProxyTaggedString(
|
|
135
|
+
contrastData,
|
|
136
|
+
result,
|
|
137
|
+
tracker
|
|
138
|
+
);
|
|
139
|
+
trackingData = tracker.getData(proxyTaggedString);
|
|
140
|
+
|
|
141
|
+
Object.values(contrastData.refInstances).forEach(
|
|
142
|
+
(referenceInstance) => {
|
|
143
|
+
Object.defineProperty(referenceInstance, '__CONTRAST__', {
|
|
144
|
+
enumerable: false,
|
|
145
|
+
configurable: true,
|
|
146
|
+
value: {
|
|
147
|
+
proxyTaggedString,
|
|
148
|
+
},
|
|
149
|
+
writable: true,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
}
|
|
127
154
|
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
155
|
+
if (trackingData) {
|
|
156
|
+
trackingData.tagRanges = tagRangeUtil.add(
|
|
157
|
+
trackingData.tagRanges,
|
|
131
158
|
new TagRange(0, result.length - 1, tagName)
|
|
132
159
|
);
|
|
133
160
|
|
|
134
|
-
|
|
161
|
+
trackingData.event = createPropagationEvent({
|
|
135
162
|
data,
|
|
136
|
-
trackedArgsData:
|
|
137
|
-
tagRanges:
|
|
163
|
+
trackedArgsData: trackingData,
|
|
164
|
+
tagRanges: trackingData.tagRanges,
|
|
138
165
|
target: 'A',
|
|
139
|
-
joiMethod: rule
|
|
166
|
+
joiMethod: rule,
|
|
140
167
|
});
|
|
141
168
|
}
|
|
142
|
-
}
|
|
169
|
+
},
|
|
143
170
|
});
|
|
144
171
|
}
|
|
145
172
|
|
|
@@ -148,7 +175,7 @@ function createPropagationEvent({
|
|
|
148
175
|
trackedArgsData,
|
|
149
176
|
tagRanges,
|
|
150
177
|
target,
|
|
151
|
-
joiMethod
|
|
178
|
+
joiMethod,
|
|
152
179
|
}) {
|
|
153
180
|
const { event: lastEvent } = trackedArgsData;
|
|
154
181
|
|
|
@@ -160,7 +187,7 @@ function createPropagationEvent({
|
|
|
160
187
|
signature,
|
|
161
188
|
tagRanges,
|
|
162
189
|
source: 'P',
|
|
163
|
-
target
|
|
190
|
+
target,
|
|
164
191
|
});
|
|
165
192
|
|
|
166
193
|
event.parents.push(lastEvent);
|
|
@@ -18,7 +18,7 @@ const _ = require('lodash');
|
|
|
18
18
|
const requireHook = require('../../../hooks/require');
|
|
19
19
|
const patcher = require('../../../hooks/patcher');
|
|
20
20
|
const {
|
|
21
|
-
PATCH_TYPES: { ASSESS_PROPAGATOR }
|
|
21
|
+
PATCH_TYPES: { ASSESS_PROPAGATOR },
|
|
22
22
|
} = require('../../../constants');
|
|
23
23
|
const tracker = require('../../../tracker');
|
|
24
24
|
const tagRangeUtil = require('../../models/tag-range/util');
|
|
@@ -41,9 +41,9 @@ function instrumentJoiValues(values) {
|
|
|
41
41
|
name: 'joi.values',
|
|
42
42
|
patchType: ASSESS_PROPAGATOR,
|
|
43
43
|
post(data) {
|
|
44
|
-
|
|
44
|
+
const {
|
|
45
45
|
args: [value],
|
|
46
|
-
result
|
|
46
|
+
result,
|
|
47
47
|
} = data;
|
|
48
48
|
|
|
49
49
|
// value not found during lookup
|
|
@@ -52,12 +52,21 @@ function instrumentJoiValues(values) {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (result.ref) {
|
|
55
|
-
|
|
55
|
+
const resultValue = result.ref.__CONTRAST__
|
|
56
|
+
? result.ref.__CONTRAST__.proxyTaggedString
|
|
57
|
+
: result.value;
|
|
58
|
+
|
|
59
|
+
handler(resultValue, value, data);
|
|
60
|
+
|
|
61
|
+
if (result.ref.__CONTRAST__) {
|
|
62
|
+
delete result.ref.__CONTRAST__;
|
|
63
|
+
}
|
|
64
|
+
|
|
56
65
|
} else if (_.isString(result.value)) {
|
|
57
66
|
// use case is .valid() - safe
|
|
58
67
|
result.value = tracker.untrack(result.value) || result.value;
|
|
59
68
|
}
|
|
60
|
-
}
|
|
69
|
+
},
|
|
61
70
|
});
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -118,7 +127,7 @@ function getRefHandler(resolvedTrackData, refTrackData) {
|
|
|
118
127
|
*/
|
|
119
128
|
function handleTargetOnlyTracked(data, resolvedTrackData, refTrackData) {
|
|
120
129
|
const {
|
|
121
|
-
args: [value]
|
|
130
|
+
args: [value],
|
|
122
131
|
} = data;
|
|
123
132
|
data.result.value = toUntrackedString(value);
|
|
124
133
|
}
|
|
@@ -131,9 +140,10 @@ function handleTargetOnlyTracked(data, resolvedTrackData, refTrackData) {
|
|
|
131
140
|
* @param {object} refTrackData tracking data for reference value
|
|
132
141
|
*/
|
|
133
142
|
function handleBothTracked(data, resolvedTrackData, refTrackData) {
|
|
134
|
-
let
|
|
135
|
-
|
|
136
|
-
|
|
143
|
+
let value = data.args[0];
|
|
144
|
+
const {
|
|
145
|
+
args: [, , prefs],
|
|
146
|
+
result,
|
|
137
147
|
} = data;
|
|
138
148
|
|
|
139
149
|
// We can't reliably validate values that get adjusted
|
|
@@ -160,9 +170,10 @@ function handleBothTracked(data, resolvedTrackData, refTrackData) {
|
|
|
160
170
|
* @param {object} refTrackData tracking data for reference value
|
|
161
171
|
*/
|
|
162
172
|
function handleRefOnlyTracked(data, resolvedTrackData, refTrackData) {
|
|
163
|
-
let
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
let value = data.args[0];
|
|
174
|
+
const {
|
|
175
|
+
args: [, , prefs],
|
|
176
|
+
result,
|
|
166
177
|
} = data;
|
|
167
178
|
|
|
168
179
|
if (prefs.convert) {
|
|
@@ -221,7 +232,7 @@ function copyValidationHistory(targetTrackData, refTrackData) {
|
|
|
221
232
|
*/
|
|
222
233
|
function buildEventsAndTagsToReplay(joiEvents) {
|
|
223
234
|
const hist = [];
|
|
224
|
-
const tagRangesSeen = new WeakSet(_.get(joiEvents,
|
|
235
|
+
const tagRangesSeen = new WeakSet(_.get(joiEvents, '0.parents.0.tagRanges'));
|
|
225
236
|
|
|
226
237
|
for (const event of joiEvents) {
|
|
227
238
|
const newEventRanges = [];
|
|
@@ -239,7 +250,7 @@ function buildEventsAndTagsToReplay(joiEvents) {
|
|
|
239
250
|
if (newEventRanges.length) {
|
|
240
251
|
hist.push({
|
|
241
252
|
event,
|
|
242
|
-
tagRanges: newEventRanges
|
|
253
|
+
tagRanges: newEventRanges,
|
|
243
254
|
});
|
|
244
255
|
}
|
|
245
256
|
}
|
|
@@ -12,6 +12,8 @@ Copyright: 2022 Contrast Security, Inc
|
|
|
12
12
|
engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
13
|
way not consistent with the End User License Agreement.
|
|
14
14
|
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
15
17
|
/**
|
|
16
18
|
* Propagation Utility
|
|
17
19
|
*
|
|
@@ -41,7 +43,7 @@ function deepOrigValue(val, max = 10) {
|
|
|
41
43
|
function walk(item, depth) {
|
|
42
44
|
if (Array.isArray(item) && depth < max) {
|
|
43
45
|
depth++;
|
|
44
|
-
return item.map(function(item) {
|
|
46
|
+
return item.map(function (item) {
|
|
45
47
|
return walk(item, depth);
|
|
46
48
|
});
|
|
47
49
|
}
|
|
@@ -94,18 +96,53 @@ function getArgValue({ arg, inclusive, allowNegatives = true, sourceLength }) {
|
|
|
94
96
|
*/
|
|
95
97
|
function sortParamTypes(params, args, sourceLength) {
|
|
96
98
|
const paramTypes = {};
|
|
97
|
-
params.forEach(function(param) {
|
|
99
|
+
params.forEach(function (param) {
|
|
98
100
|
paramTypes[param.type] = getArgValue({
|
|
99
101
|
arg: args[param.index],
|
|
100
102
|
inclusive: param.inclusive,
|
|
101
103
|
allowNegatives: param.allowNegatives,
|
|
102
|
-
sourceLength
|
|
104
|
+
sourceLength,
|
|
103
105
|
});
|
|
104
106
|
});
|
|
105
107
|
|
|
106
108
|
return paramTypes;
|
|
107
109
|
}
|
|
108
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Checks whether the input is an object
|
|
113
|
+
* @param {*} value
|
|
114
|
+
* @return {boolean}
|
|
115
|
+
*/
|
|
116
|
+
function isObject(value) {
|
|
117
|
+
if (typeof value === 'object' && !Array.isArray(value) && value !== null) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function setProxyTaggedString(contrastData, input, tracker) {
|
|
125
|
+
let proxyTaggedString;
|
|
126
|
+
|
|
127
|
+
if (contrastData.proxyTaggedString) {
|
|
128
|
+
proxyTaggedString = contrastData.proxyTaggedString;
|
|
129
|
+
} else {
|
|
130
|
+
const { str } = tracker.track(input);
|
|
131
|
+
proxyTaggedString = str;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
contrastData.proxyTaggedString = proxyTaggedString;
|
|
135
|
+
|
|
136
|
+
return proxyTaggedString;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function getContrastData(data) {
|
|
140
|
+
return data.args[1].schema && data.args[1].schema.__CONTRAST__;
|
|
141
|
+
}
|
|
142
|
+
|
|
109
143
|
module.exports.origValue = origValue;
|
|
110
144
|
module.exports.deepOrigValue = deepOrigValue;
|
|
111
145
|
module.exports.sortParamTypes = sortParamTypes;
|
|
146
|
+
module.exports.isObject = isObject;
|
|
147
|
+
module.exports.setProxyTaggedString = setProxyTaggedString;
|
|
148
|
+
module.exports.getContrastData = getContrastData;
|
|
@@ -25,10 +25,11 @@ const utils = require('./utils');
|
|
|
25
25
|
* Hooks a method to properly bind to AsyncStorage
|
|
26
26
|
* @param {Object} prototype to hook
|
|
27
27
|
* @param {String} method to hook
|
|
28
|
+
* @param {String} patchName of the patch
|
|
28
29
|
*/
|
|
29
|
-
function hookMethod(
|
|
30
|
-
patcher.patch(
|
|
31
|
-
name:
|
|
30
|
+
function hookMethod(obj, method, patchName) {
|
|
31
|
+
patcher.patch(obj, method, {
|
|
32
|
+
name: patchName,
|
|
32
33
|
patchType: ASYNC_CONTEXT,
|
|
33
34
|
alwaysRun: true,
|
|
34
35
|
pre: (data) => {
|
|
@@ -42,17 +43,18 @@ function hookMethod(prototype, method) {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
|
-
* Registers the hooks for
|
|
46
|
+
* Registers the hooks for mongodb and mongodb-core
|
|
46
47
|
*/
|
|
47
48
|
function init() {
|
|
48
|
-
logger.info('applying non-policy hook: mongodb
|
|
49
|
+
logger.info('applying non-policy hook: mongodb');
|
|
49
50
|
|
|
50
51
|
requireHook.resolve(
|
|
51
52
|
{ name: 'mongodb-core', file: 'lib/topologies/server.js' },
|
|
52
53
|
(server) => {
|
|
53
54
|
const methods = ['command', 'insert', 'update', 'remove', 'logout'];
|
|
54
55
|
for (const method of methods) {
|
|
55
|
-
|
|
56
|
+
const name = `mongodb-core.${server.prototype.constructor.name}.prototype`;
|
|
57
|
+
hookMethod(server.prototype, method, name);
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
);
|
|
@@ -60,9 +62,43 @@ function init() {
|
|
|
60
62
|
requireHook.resolve(
|
|
61
63
|
{ name: 'mongodb-core', file: 'lib/cursor.js' },
|
|
62
64
|
(cursor) => {
|
|
63
|
-
|
|
65
|
+
const name = `mongodb-core.${cursor.prototype.constructor.name}.prototype`;
|
|
66
|
+
hookMethod(cursor.prototype, 'next', name);
|
|
64
67
|
}
|
|
65
68
|
);
|
|
69
|
+
|
|
70
|
+
requireHook.resolve(
|
|
71
|
+
{
|
|
72
|
+
name: 'mongodb',
|
|
73
|
+
file: 'lib/topologies/server.js',
|
|
74
|
+
version: '>=3.3.0 <4.0.0'
|
|
75
|
+
},
|
|
76
|
+
(server) =>
|
|
77
|
+
patcher.patch(server, {
|
|
78
|
+
name: 'mongodb.Server',
|
|
79
|
+
patchType: ASYNC_CONTEXT,
|
|
80
|
+
alwaysRun: true,
|
|
81
|
+
post: (data) => {
|
|
82
|
+
const methods = ['command', 'insert', 'update', 'remove'];
|
|
83
|
+
for (const method of methods) {
|
|
84
|
+
hookMethod(data.result, method, 'mongodb.Server');
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
requireHook.resolve(
|
|
91
|
+
{ name: 'mongodb', file: 'lib/cursor.js', version: '>=3.3.0 <4.0.0' },
|
|
92
|
+
(cursor) =>
|
|
93
|
+
patcher.patch(cursor, {
|
|
94
|
+
name: 'mongodb.Cursor',
|
|
95
|
+
patchType: ASYNC_CONTEXT,
|
|
96
|
+
alwaysRun: true,
|
|
97
|
+
post: (data) => {
|
|
98
|
+
hookMethod(data.result, '_next', 'mongodb.Cursor');
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
);
|
|
66
102
|
}
|
|
67
103
|
|
|
68
104
|
module.exports = init;
|
package/lib/core/config/util.js
CHANGED
|
@@ -323,6 +323,10 @@ function mergePM2Envs() {
|
|
|
323
323
|
.concat(Object.entries(pm2_env))
|
|
324
324
|
.concat(['DEBUG', 'PGHOST', 'PGPORT']);
|
|
325
325
|
|
|
326
|
+
const pm2ConfigPath =
|
|
327
|
+
pm2_env.env.CONTRAST_CONFIG_PATH || pm2_env.CONTRAST_CONFIG_PATH;
|
|
328
|
+
if (pm2ConfigPath) process.env.CONTRAST_CONFIG_PATH = pm2ConfigPath;
|
|
329
|
+
|
|
326
330
|
objectEntries.forEach(([key, value]) => {
|
|
327
331
|
if (
|
|
328
332
|
!process.env[key] &&
|
package/lib/instrumentation.js
CHANGED
|
@@ -129,7 +129,7 @@ function protectModeFeatures({ agent, reporter }) {
|
|
|
129
129
|
// needs the || '.' for testing...
|
|
130
130
|
const logDir = agent.config.agent.node.analysis_log_dir || '.';
|
|
131
131
|
const agentLib = new lib.Agent(
|
|
132
|
-
{ enableLogging: true, logDir, logLevel:
|
|
132
|
+
{ enableLogging: true, logDir, logLevel: 'INFO' }
|
|
133
133
|
);
|
|
134
134
|
// attach the constants so lib.Agent() isn't exposed.
|
|
135
135
|
for (const c in lib.constants) {
|
|
@@ -159,7 +159,7 @@ function protectModeFeatures({ agent, reporter }) {
|
|
|
159
159
|
function nonPolicyHooks(agent) {
|
|
160
160
|
require('./core/async-storage/hooks/bluebird')();
|
|
161
161
|
require('./core/async-storage/hooks/redis')();
|
|
162
|
-
require('./core/async-storage/hooks/mongodb
|
|
162
|
+
require('./core/async-storage/hooks/mongodb')();
|
|
163
163
|
require('./core/async-storage/hooks/mysql')();
|
|
164
164
|
require('./hooks/require');
|
|
165
165
|
require('./hooks/cluster')(agent);
|
|
@@ -102,6 +102,12 @@ class Event {
|
|
|
102
102
|
this.args.push(
|
|
103
103
|
new ObjectDTM(event.context.args[i], event.context.argsTracked[i])
|
|
104
104
|
);
|
|
105
|
+
if (event.tagRanges[i]
|
|
106
|
+
&& event.context.argsDisplayRanges
|
|
107
|
+
&& Object.keys(event.context.argsDisplayRanges[i]).length
|
|
108
|
+
) {
|
|
109
|
+
event.tagRanges[i] = event.context.argsDisplayRanges[i];
|
|
110
|
+
}
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
if (event.code) {
|