@contrast/agentify 1.4.1 → 1.5.1
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/lib/index.js +3 -10
- package/lib/sources.js +5 -33
- package/package.json +1 -1
- package/lib/contrast-methods.js +0 -169
package/lib/index.js
CHANGED
|
@@ -41,7 +41,6 @@ const defaultOpts = {
|
|
|
41
41
|
module.exports = function(core) {
|
|
42
42
|
// compose add'l local services
|
|
43
43
|
require('./sources')(core);
|
|
44
|
-
require('./contrast-methods')(core);
|
|
45
44
|
require('./function-hooks')(core);
|
|
46
45
|
require('./rewrite-hooks')(core);
|
|
47
46
|
|
|
@@ -137,18 +136,12 @@ class Agent {
|
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
logDiagnosticFiles() {
|
|
140
|
-
const {
|
|
139
|
+
const { config, getEffectiveConfig, getSystemInfo } = this.core;
|
|
141
140
|
|
|
142
141
|
if (config.agent.diagnostics.enable !== false) {
|
|
143
|
-
const effectiveConfig = JSON.stringify(getEffectiveConfig(), null, 2)
|
|
142
|
+
const effectiveConfig = JSON.stringify(getEffectiveConfig(), null, 2);
|
|
143
|
+
const systemInfo = JSON.stringify(getSystemInfo(), null, 2);
|
|
144
144
|
|
|
145
|
-
let systemInfo = getSystemInfo();
|
|
146
|
-
systemInfo.Contrast.Agent = {
|
|
147
|
-
Name: agentName,
|
|
148
|
-
Version: agentVersion,
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
systemInfo = JSON.stringify(systemInfo, null, 2).concat('\n\n');
|
|
152
145
|
if (!config.agent.diagnostics.quiet) {
|
|
153
146
|
fs.writeFileSync(1, effectiveConfig, 'utf8');
|
|
154
147
|
fs.writeFileSync(1, systemInfo, 'utf8');
|
package/lib/sources.js
CHANGED
|
@@ -32,43 +32,15 @@ module.exports = function(core) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function install() {
|
|
35
|
-
[{
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
moduleName: 'https'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
moduleName: 'spdy'
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
moduleName: 'http2',
|
|
46
|
-
patchObjectsProps: [
|
|
47
|
-
{
|
|
48
|
-
methods: ['createServer', 'createSecureServer'],
|
|
49
|
-
patchType,
|
|
50
|
-
patchObjects: [
|
|
51
|
-
{
|
|
52
|
-
name: 'Server.prototype',
|
|
53
|
-
methods: ['emit'],
|
|
54
|
-
patchType,
|
|
55
|
-
around: aroundHook('http2')
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
}
|
|
59
|
-
]
|
|
60
|
-
}].forEach(({ moduleName, patchObjectsProps }) => {
|
|
61
|
-
const patchObjects = patchObjectsProps || [
|
|
62
|
-
{
|
|
35
|
+
['http', 'https', 'spdy', 'http2'].forEach((moduleName) => {
|
|
36
|
+
instrument({
|
|
37
|
+
moduleName,
|
|
38
|
+
patchObjects: [{
|
|
63
39
|
name: 'Server.prototype',
|
|
64
40
|
methods: ['emit'],
|
|
65
41
|
patchType,
|
|
66
42
|
around: aroundHook(moduleName)
|
|
67
|
-
}
|
|
68
|
-
];
|
|
69
|
-
instrument({
|
|
70
|
-
moduleName,
|
|
71
|
-
patchObjects
|
|
43
|
+
}]
|
|
72
44
|
});
|
|
73
45
|
});
|
|
74
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/agentify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Configures Contrast agent services and instrumentation within an application",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
package/lib/contrast-methods.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
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 = function (core) {
|
|
19
|
-
const { logger, patcher } = core;
|
|
20
|
-
|
|
21
|
-
const getOrig = (v) => patcher.unwrap(v);
|
|
22
|
-
const slice = patcher.unwrap(String.prototype.slice);
|
|
23
|
-
const toUntrackedString = (v) => slice.call(` ${v}`, 1);
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Components e.g. Assess, Protect, can
|
|
27
|
-
* 1) configure rewriter to add desired ContrastMethod functions to source code
|
|
28
|
-
* 2) patch those functions on `contrastMethods.api` in order to add instrumentation
|
|
29
|
-
*/
|
|
30
|
-
const contrastMethods = {
|
|
31
|
-
api: {
|
|
32
|
-
eval(v) {
|
|
33
|
-
return v;
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
// Binary Operators
|
|
37
|
-
add(left, right) {
|
|
38
|
-
const ret = getOrig(left) + getOrig(right);
|
|
39
|
-
return ret;
|
|
40
|
-
},
|
|
41
|
-
eqEq(left, right) {
|
|
42
|
-
left = getOrig(left);
|
|
43
|
-
right = getOrig(right);
|
|
44
|
-
|
|
45
|
-
return left == right;
|
|
46
|
-
},
|
|
47
|
-
eqEqEq(left, right) {
|
|
48
|
-
left = getOrig(left);
|
|
49
|
-
right = getOrig(right);
|
|
50
|
-
|
|
51
|
-
return left === right;
|
|
52
|
-
},
|
|
53
|
-
notEqEq(left, right) {
|
|
54
|
-
left = getOrig(left);
|
|
55
|
-
right = getOrig(right);
|
|
56
|
-
|
|
57
|
-
return left !== right;
|
|
58
|
-
},
|
|
59
|
-
notEq(left, right) {
|
|
60
|
-
left = getOrig(left);
|
|
61
|
-
right = getOrig(right);
|
|
62
|
-
|
|
63
|
-
return left != right;
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
// Computed Properties
|
|
67
|
-
// Used to force a copy of handle:
|
|
68
|
-
// https://stackoverflow.com/a/31733628
|
|
69
|
-
// This is a workaround for CONTRAST-30333, in which something we
|
|
70
|
-
// suspect is a v8 bug means that handle will otherwise be clobbered
|
|
71
|
-
// and if it was externalized, we will lose the data associated with it
|
|
72
|
-
forceCopy(handle) {
|
|
73
|
-
if (typeof handle === 'string') {
|
|
74
|
-
handle = toUntrackedString(handle);
|
|
75
|
-
}
|
|
76
|
-
return handle;
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
// Switch Case
|
|
80
|
-
cast(val) {
|
|
81
|
-
return getOrig(val);
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Tagged Templates
|
|
86
|
-
* The first argument received by the tag function is an array of strings.
|
|
87
|
-
* For any template literal, its length is equal to the number of
|
|
88
|
-
* substitutions (occurrences of ${...}) plus one, and is therefore always
|
|
89
|
-
* non-empty.
|
|
90
|
-
* see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
|
|
91
|
-
* @param {string[]} strings length n+1
|
|
92
|
-
* @param {string[]} args length n
|
|
93
|
-
* @returns {string}
|
|
94
|
-
*/
|
|
95
|
-
tag(strings, ...args) {
|
|
96
|
-
const [first, ...rest] = strings;
|
|
97
|
-
|
|
98
|
-
return rest.reduce(
|
|
99
|
-
(result, str, i) => result.concat(args[i], str),
|
|
100
|
-
first,
|
|
101
|
-
);
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
// Import Statements
|
|
105
|
-
importDefault(...args) {
|
|
106
|
-
// noop
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
importStarAs(...args) {
|
|
110
|
-
// noop
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
importNamed(...args) {
|
|
114
|
-
// noop
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
// Injections
|
|
118
|
-
Function: core.patcher.patch(global.Function, {
|
|
119
|
-
name: 'global.Function',
|
|
120
|
-
patchType: 'rewrite-injection',
|
|
121
|
-
}),
|
|
122
|
-
JSON: core.patcher.patch(global.JSON, {
|
|
123
|
-
name: 'global.JSON',
|
|
124
|
-
patchType: 'rewrite-injection',
|
|
125
|
-
}),
|
|
126
|
-
Number: core.patcher.patch(global.Number, {
|
|
127
|
-
name: 'global.Number',
|
|
128
|
-
patchType: 'rewrite-injection',
|
|
129
|
-
}),
|
|
130
|
-
Object: core.patcher.patch(global.Object, {
|
|
131
|
-
name: 'global.Object',
|
|
132
|
-
patchType: 'rewrite-injection',
|
|
133
|
-
}),
|
|
134
|
-
String: core.patcher.patch(global.String, {
|
|
135
|
-
name: 'global.String',
|
|
136
|
-
patchType: 'rewrite-injection',
|
|
137
|
-
}),
|
|
138
|
-
},
|
|
139
|
-
|
|
140
|
-
installed: false,
|
|
141
|
-
|
|
142
|
-
getGlobal() {
|
|
143
|
-
return global;
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
contrastMethods.install = function () {
|
|
148
|
-
if (contrastMethods.installed) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const global = contrastMethods.getGlobal();
|
|
153
|
-
|
|
154
|
-
try {
|
|
155
|
-
Object.defineProperty(global, 'ContrastMethods', {
|
|
156
|
-
enumerable: true,
|
|
157
|
-
configurable: false,
|
|
158
|
-
value: contrastMethods.api,
|
|
159
|
-
});
|
|
160
|
-
contrastMethods.installed = true;
|
|
161
|
-
} catch (err) {
|
|
162
|
-
// We should never expect this since the installation process is well
|
|
163
|
-
// controlled, but still we should have the defensive code.
|
|
164
|
-
logger.error({ err }, 'Unable to inject global.ContrastMethods');
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
return (core.contrastMethods = contrastMethods);
|
|
169
|
-
};
|