@contrast/agent 5.6.0 → 5.6.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/lib/esm-loader.mjs +6 -5
- package/lib/index.js +4 -5
- package/lib/start-agent.js +51 -97
- package/package.json +9 -10
package/lib/esm-loader.mjs
CHANGED
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
import Module from 'node:module';
|
|
17
17
|
const require = Module.createRequire(import.meta.url);
|
|
18
18
|
const { startAgent } = require('./start-agent');
|
|
19
|
+
|
|
19
20
|
let load, resolve;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
({ load, resolve } = core.esmHooks.hooks);
|
|
24
|
-
}
|
|
22
|
+
const core = await startAgent({ type: 'esm' });
|
|
23
|
+
if (core?.esmHooks?.hooks) {
|
|
24
|
+
({ load, resolve } = core.esmHooks.hooks);
|
|
25
|
+
}
|
|
25
26
|
|
|
26
|
-
export { load, resolve }; // remove when all LTS versions support register
|
|
27
|
+
export { load, resolve }; // can remove when all LTS versions support register
|
package/lib/index.js
CHANGED
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} catch (err) {} // eslint-disable-line no-empty
|
|
18
|
+
(async () => {
|
|
19
|
+
const { startAgent } = require('./start-agent');
|
|
20
|
+
await startAgent({ type: 'cjs' });
|
|
21
|
+
})();
|
package/lib/start-agent.js
CHANGED
|
@@ -17,49 +17,37 @@
|
|
|
17
17
|
|
|
18
18
|
const process = require('process');
|
|
19
19
|
const { isMainThread } = require('node:worker_threads');
|
|
20
|
-
const semver = require('semver');
|
|
21
20
|
const _agentify = require('@contrast/agentify');
|
|
22
21
|
const {
|
|
23
22
|
name: agentName,
|
|
24
23
|
version: agentVersion,
|
|
25
24
|
engines: {
|
|
26
|
-
node:
|
|
27
|
-
npm:
|
|
25
|
+
node: nodeEngines,
|
|
26
|
+
npm: npmVersionRange
|
|
28
27
|
}
|
|
29
28
|
} = require('../package.json');
|
|
30
29
|
|
|
31
30
|
function initCore() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* This will run after we onboard to the UI and pick up any remote settings.
|
|
50
|
-
*/
|
|
51
|
-
install() {
|
|
52
|
-
if (
|
|
53
|
-
!core.config.getEffectiveValue('assess.enable') &&
|
|
54
|
-
!core.config.getEffectiveValue('protect.enable')
|
|
55
|
-
) {
|
|
56
|
-
throw new Error('Neither Assess nor Protect are enabled. Check local configuration and UI settings');
|
|
31
|
+
const core = {
|
|
32
|
+
agentName,
|
|
33
|
+
agentVersion,
|
|
34
|
+
nodeEngines,
|
|
35
|
+
npmVersionRange,
|
|
36
|
+
startupValidation: {
|
|
37
|
+
/**
|
|
38
|
+
* This will run after we onboard to the UI and pick up any remote settings. See install order below.
|
|
39
|
+
*/
|
|
40
|
+
install() {
|
|
41
|
+
if (
|
|
42
|
+
!core.config.getEffectiveValue('assess.enable') &&
|
|
43
|
+
!core.config.getEffectiveValue('protect.enable')
|
|
44
|
+
) {
|
|
45
|
+
throw new Error('Neither Assess nor Protect are enabled. Check local configuration and UI settings');
|
|
46
|
+
}
|
|
57
47
|
}
|
|
58
48
|
}
|
|
59
49
|
};
|
|
60
50
|
|
|
61
|
-
core.npmVersionRange = npmEngine;
|
|
62
|
-
|
|
63
51
|
if (process.env.CSI_EXPOSE_CORE) {
|
|
64
52
|
global[Symbol.for('contrast:core')] = core;
|
|
65
53
|
}
|
|
@@ -75,74 +63,40 @@ function loadFeatures(core) {
|
|
|
75
63
|
require('@contrast/protect')(core);
|
|
76
64
|
}
|
|
77
65
|
|
|
78
|
-
|
|
79
|
-
* check to see if we're running with the correct flag (--loader or --import)
|
|
80
|
-
* for the right version of node. we do not function correctly when --loader
|
|
81
|
-
* is used for node >= 18 or when --import is used for node < 18.
|
|
82
|
-
*/
|
|
83
|
-
function checkImportVsLoaderVsNodeVersion() {
|
|
84
|
-
// allow testing to ignore these restrictions
|
|
85
|
-
const noValidate = process.env.CSI_EXPOSE_CORE === 'no-validate';
|
|
86
|
-
let msg;
|
|
87
|
-
|
|
88
|
-
const { execArgv, version } = process;
|
|
89
|
-
// eslint-disable-next-line newline-per-chained-call
|
|
90
|
-
const [major, minor] = version.slice(1).split('.').map(Number);
|
|
91
|
-
for (let i = 0; i < execArgv.length; i++) {
|
|
92
|
-
const loader = execArgv[i];
|
|
93
|
-
const agent = execArgv[i + 1];
|
|
94
|
-
if (['--import', '--loader', '--experimental-loader'].includes(loader) && agent?.startsWith('@contrast/agent')) {
|
|
95
|
-
if (noValidate) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (loader === '--import') {
|
|
99
|
-
// loader is --import
|
|
100
|
-
if (major === 18 && minor >= 19 || major >= 20) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (major <= 18 && minor < 19) {
|
|
104
|
-
msg = 'Contrast requires node versions less than 18.19.0 use the --loader flag for ESM support';
|
|
105
|
-
}
|
|
106
|
-
} else {
|
|
107
|
-
// loader is either --loader or --experimental-loader (same thing)
|
|
108
|
-
if (major >= 20 || major === 18 && minor >= 19) {
|
|
109
|
-
msg = 'Contrast requires node versions >= 18.19.0 use the --import flag for ESM support';
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (msg) throw new Error(msg);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
async function startAgent({ type = 'cjs' } = {}) {
|
|
66
|
+
function startAgent({ type = 'cjs' } = {}) {
|
|
120
67
|
if (isMainThread) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
68
|
+
try {
|
|
69
|
+
const core = initCore();
|
|
70
|
+
const agentify = _agentify(core);
|
|
71
|
+
|
|
72
|
+
return agentify(loadFeatures, {
|
|
73
|
+
installOrder: [
|
|
74
|
+
'reporter',
|
|
75
|
+
'startupValidation',
|
|
76
|
+
'contrastMethods',
|
|
77
|
+
'deadzones',
|
|
78
|
+
'scopes',
|
|
79
|
+
'sources',
|
|
80
|
+
'architectureComponents',
|
|
81
|
+
'assess',
|
|
82
|
+
'protect',
|
|
83
|
+
'depHooks',
|
|
84
|
+
'routeCoverage',
|
|
85
|
+
'libraryAnalysis',
|
|
86
|
+
'heapSnapshots',
|
|
87
|
+
'metrics',
|
|
88
|
+
'rewriteHooks',
|
|
89
|
+
'functionHooks',
|
|
90
|
+
'esmHooks',
|
|
91
|
+
],
|
|
92
|
+
type
|
|
93
|
+
});
|
|
94
|
+
} catch (err) {
|
|
95
|
+
// agentify should catch any startup errors and handle necessary logging,
|
|
96
|
+
// but this is just in case a fatal error occurs during composition.
|
|
97
|
+
console.error('Startup error was not handled by agentify. Application Will be run without instrumentation.');
|
|
98
|
+
console.error(err);
|
|
99
|
+
}
|
|
146
100
|
} else {
|
|
147
101
|
console.warn('Not in main thread. Thread continuing without instrumentation.');
|
|
148
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/agent",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.2",
|
|
4
4
|
"description": "Assess and Protect agents for Node.js",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -15,19 +15,18 @@
|
|
|
15
15
|
"types": "lib/index.d.ts",
|
|
16
16
|
"engines": {
|
|
17
17
|
"npm": ">=6.13.7 <7 || >= 8.3.1",
|
|
18
|
-
"node": ">=14.
|
|
18
|
+
"node": ">=14.18.0 <15 || >=16.9.1 <17 || >=18.7.0 <19 || >=20.6.0 <21"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "../scripts/test.sh"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@contrast/agentify": "1.24.
|
|
25
|
-
"@contrast/architecture-components": "1.18.
|
|
26
|
-
"@contrast/assess": "1.27.
|
|
27
|
-
"@contrast/library-analysis": "1.19.
|
|
28
|
-
"@contrast/protect": "1.35.
|
|
29
|
-
"@contrast/route-coverage": "1.
|
|
30
|
-
"@contrast/telemetry": "1.6.
|
|
31
|
-
"semver": "^7.3.7"
|
|
24
|
+
"@contrast/agentify": "1.24.2",
|
|
25
|
+
"@contrast/architecture-components": "1.18.1",
|
|
26
|
+
"@contrast/assess": "1.27.2",
|
|
27
|
+
"@contrast/library-analysis": "1.19.1",
|
|
28
|
+
"@contrast/protect": "1.35.2",
|
|
29
|
+
"@contrast/route-coverage": "1.19.0",
|
|
30
|
+
"@contrast/telemetry": "1.6.2"
|
|
32
31
|
}
|
|
33
32
|
}
|