@contrast/agentify 1.17.0 → 1.18.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 +1 -1
- package/lib/function-hooks.js +1 -1
- package/lib/heap-snapshots.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -3
- package/lib/initialize.mjs +136 -0
- package/lib/log-diagnostic-files.js +1 -1
- package/lib/rewrite-hooks.js +7 -3
- package/lib/sources.js +1 -1
- package/package.json +6 -5
package/LICENSE
CHANGED
package/lib/function-hooks.js
CHANGED
package/lib/heap-snapshots.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2024 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -42,6 +42,7 @@ export interface Core {
|
|
|
42
42
|
readonly depHooks: RequireHook;
|
|
43
43
|
readonly logger: Logger;
|
|
44
44
|
readonly rewriter: Rewriter;
|
|
45
|
+
readonly threadInfo: any;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
export interface AgentifyOptions {
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2024 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -52,13 +52,13 @@ module.exports = function init(core = {}) {
|
|
|
52
52
|
require('@contrast/core/lib/app-info')(core);
|
|
53
53
|
require('@contrast/core/lib/sensitive-data-masking')(core);
|
|
54
54
|
require('@contrast/core/lib/is-agent-path')(core);
|
|
55
|
+
require('@contrast/dep-hooks')(core);
|
|
56
|
+
require('@contrast/patcher')(core);
|
|
55
57
|
require('@contrast/core/lib/capture-stacktrace')(core);
|
|
56
58
|
|
|
57
|
-
require('@contrast/patcher')(core);
|
|
58
59
|
require('@contrast/rewriter')(core); // merge contrast-methods?
|
|
59
60
|
require('@contrast/core/lib/contrast-methods')(core); // can we remove dependency on patcher?
|
|
60
61
|
|
|
61
|
-
require('@contrast/dep-hooks')(core);
|
|
62
62
|
require('@contrast/scopes')(core);
|
|
63
63
|
require('@contrast/deadzones')(core);
|
|
64
64
|
require('@contrast/reporter').default(core);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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
|
+
import Module from 'node:module';
|
|
17
|
+
// want to only initialize some of the agent if main thread. not sure that's really
|
|
18
|
+
// possible. based on logging, it looks like all of the low-level hooks (rewrite-injection,
|
|
19
|
+
// assess-dataflow-propagators, assess-dataflow-sink ContrastMethods, and function-hooks)
|
|
20
|
+
// are added in both the main thread and the loader thread. But all other modules are loaded
|
|
21
|
+
// in the main thread. presumably, this is because the assess module was loaded in both
|
|
22
|
+
// threads, registered the appropriate patchers in each, so both convert 'import' (statement
|
|
23
|
+
// or function) to 'require'.
|
|
24
|
+
//
|
|
25
|
+
import { isMainThread, threadId } from 'node:worker_threads';
|
|
26
|
+
|
|
27
|
+
const ERROR_MESSAGE = 'A fatal agent installation error has occurred. The application will be run without instrumentation.';
|
|
28
|
+
const DEFAULT_INSTALL_ORDER = [
|
|
29
|
+
'reporter',
|
|
30
|
+
'contrastMethods',
|
|
31
|
+
'deadzones',
|
|
32
|
+
'scopes',
|
|
33
|
+
'sources',
|
|
34
|
+
'architectureComponents',
|
|
35
|
+
'assess',
|
|
36
|
+
'protect',
|
|
37
|
+
'depHooks',
|
|
38
|
+
'esmHooks',
|
|
39
|
+
'routeCoverage',
|
|
40
|
+
'libraryAnalysis',
|
|
41
|
+
'heapSnapshots',
|
|
42
|
+
'rewriteHooks',
|
|
43
|
+
'functionHooks',
|
|
44
|
+
'metrics',
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
const require = Module.createRequire(import.meta.url);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {object} { core = {}, options = {} }
|
|
51
|
+
*/
|
|
52
|
+
async function loadModules({ core = {}, options = {} }) {
|
|
53
|
+
try {
|
|
54
|
+
require('@contrast/core/lib/messages')(core);
|
|
55
|
+
require('@contrast/config')(core);
|
|
56
|
+
require('@contrast/logger').default(core);
|
|
57
|
+
const thread = isMainThread ? 'main' : 'loader';
|
|
58
|
+
core.logger.trace({ tid: threadId }, 'initializing core modules in %s thread', thread);
|
|
59
|
+
|
|
60
|
+
// @contrast/info ?
|
|
61
|
+
require('@contrast/core/lib/agent-info')(core);
|
|
62
|
+
require('@contrast/core/lib/system-info')(core);
|
|
63
|
+
require('@contrast/core/lib/app-info')(core);
|
|
64
|
+
require('@contrast/core/lib/sensitive-data-masking')(core);
|
|
65
|
+
require('@contrast/core/lib/is-agent-path')(core);
|
|
66
|
+
require('@contrast/dep-hooks')(core);
|
|
67
|
+
const { default: install } = await import('@contrast/esm-hooks');
|
|
68
|
+
const esmHooks = await install(core);
|
|
69
|
+
core.esmHooks = esmHooks;
|
|
70
|
+
require('@contrast/patcher')(core);
|
|
71
|
+
require('@contrast/core/lib/capture-stacktrace')(core);
|
|
72
|
+
|
|
73
|
+
require('@contrast/rewriter')(core); // merge contrast-methods?
|
|
74
|
+
require('@contrast/core/lib/contrast-methods')(core); // can we remove dependency on patcher?
|
|
75
|
+
|
|
76
|
+
require('@contrast/scopes')(core);
|
|
77
|
+
require('@contrast/deadzones')(core);
|
|
78
|
+
require('@contrast/reporter').default(core);
|
|
79
|
+
require('@contrast/instrumentation')(core);
|
|
80
|
+
require('@contrast/metrics')(core);
|
|
81
|
+
|
|
82
|
+
require('./heap-snapshots')(core);
|
|
83
|
+
require('./sources')(core);
|
|
84
|
+
require('./function-hooks')(core);
|
|
85
|
+
require('./log-diagnostic-files')(core); // this doesn't really belong in agentify
|
|
86
|
+
require('./rewrite-hooks')(core);
|
|
87
|
+
|
|
88
|
+
} catch (err) {
|
|
89
|
+
// TODO: Consider proper UNINSTALLATION and normal startup w/o agent
|
|
90
|
+
if (core.logger) {
|
|
91
|
+
core.logger.error({ err, threadId }, ERROR_MESSAGE);
|
|
92
|
+
} else {
|
|
93
|
+
console.error(new Error(ERROR_MESSAGE, { cause: err }));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return core;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function startAgent({ core, options = {} }) {
|
|
102
|
+
const { executor, installOrder = DEFAULT_INSTALL_ORDER } = options;
|
|
103
|
+
const { config, logger } = core;
|
|
104
|
+
|
|
105
|
+
// this should be moved into config because errors are handled here now.
|
|
106
|
+
for (const error of config._errors) {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
logger.info({ tid: threadId }, 'Starting %s v%s', core.agentName, core.agentVersion);
|
|
111
|
+
logger.info({ config }, 'Agent configuration');
|
|
112
|
+
|
|
113
|
+
let plugin;
|
|
114
|
+
if (typeof executor === 'function') {
|
|
115
|
+
plugin = await executor(core);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const svcName of installOrder ?? []) {
|
|
119
|
+
const svc = core[svcName];
|
|
120
|
+
if (svc?.install) {
|
|
121
|
+
logger.trace({ tid: threadId }, 'installing service: %s', svcName);
|
|
122
|
+
await svc.install();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (plugin?.install) {
|
|
127
|
+
await plugin.install();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// should this be moved into a separate install side-effect?
|
|
131
|
+
core.logDiagnosticFiles();
|
|
132
|
+
|
|
133
|
+
return core;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { loadModules, startAgent };
|
package/lib/rewrite-hooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright:
|
|
2
|
+
* Copyright: 2024 Contrast Security, Inc
|
|
3
3
|
* Contact: support@contrastsecurity.com
|
|
4
4
|
* License: Commercial
|
|
5
5
|
|
|
@@ -38,12 +38,16 @@ module.exports = function init(core) {
|
|
|
38
38
|
*/
|
|
39
39
|
Module.prototype._compile = function (content, filename) {
|
|
40
40
|
let result;
|
|
41
|
-
const
|
|
41
|
+
const options = {
|
|
42
42
|
filename,
|
|
43
43
|
isModule: false,
|
|
44
44
|
inject: true,
|
|
45
45
|
wrap: true,
|
|
46
|
-
}
|
|
46
|
+
};
|
|
47
|
+
// if threadInfo is present, this is running with --loader or --import
|
|
48
|
+
core.threadInfo?.post('rewrite', options);
|
|
49
|
+
|
|
50
|
+
const { code } = core.rewriter.rewrite(content, options);
|
|
47
51
|
|
|
48
52
|
try {
|
|
49
53
|
result = _compile.call(this, code, filename);
|
package/lib/sources.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/agentify",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
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)",
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@contrast/common": "1.16.0",
|
|
21
|
-
"@contrast/config": "1.
|
|
22
|
-
"@contrast/core": "1.27.
|
|
21
|
+
"@contrast/config": "1.23.0",
|
|
22
|
+
"@contrast/core": "1.27.1",
|
|
23
23
|
"@contrast/deadzones": "1.1.1",
|
|
24
|
-
"@contrast/dep-hooks": "1.3.0",
|
|
25
|
-
"@contrast/
|
|
24
|
+
"@contrast/dep-hooks": "^1.3.0",
|
|
25
|
+
"@contrast/esm-hooks": "2.0.1",
|
|
26
|
+
"@contrast/instrumentation": "^1.3.0",
|
|
26
27
|
"@contrast/logger": "1.7.0",
|
|
27
28
|
"@contrast/metrics": "1.2.0",
|
|
28
29
|
"@contrast/patcher": "1.7.1",
|