@contrast/agent 4.17.1 → 4.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/lib/assess/sources/index.js +26 -5
- package/lib/core/config/options.js +14 -1
- package/lib/core/config/util.js +39 -11
- package/package.json +2 -1
|
@@ -55,6 +55,25 @@ sources.track = function(type, parent, key, membrane) {
|
|
|
55
55
|
parent[key] = membrane.wrap(object, metadata);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Chooses a strategy for tracking the source events
|
|
60
|
+
* @param {any} config Current configuration for the agent
|
|
61
|
+
* @param {Logger} logger A logger instance
|
|
62
|
+
* @returns {Boolean} whether lazy tracking is enabled or not
|
|
63
|
+
*/
|
|
64
|
+
sources.getLazyTrackingConfig = function(config, logger) {
|
|
65
|
+
if (config._default['agent.traverse_and_track']) {
|
|
66
|
+
return config.assess.enable_lazy_tracking;
|
|
67
|
+
}
|
|
68
|
+
if (config._default['assess.enable_lazy_tracking']) {
|
|
69
|
+
logger.error('agent.traverse_and_track option is deprecated. Please use assess.enable_lazy_tracking from now on. It\'s value should be the opposite of this one');
|
|
70
|
+
return !config.agent.traverse_and_track;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
logger.error('Conflicting options set: `agent.traverse_and_track` and `assess.enable_lazy_tracking`. `agent.traverse_and_track` is deprecated, so `assess.enable_lazy_tracking` takes precedence');
|
|
74
|
+
return config.assess.enable_lazy_tracking;
|
|
75
|
+
};
|
|
76
|
+
|
|
58
77
|
/**
|
|
59
78
|
* Registers an event to add URL and input exclusions to async storage if they
|
|
60
79
|
* pertain to the current request path. Also registers all the source events
|
|
@@ -62,8 +81,10 @@ sources.track = function(type, parent, key, membrane) {
|
|
|
62
81
|
* object in a membrane
|
|
63
82
|
*/
|
|
64
83
|
sources.registerListeners = function({ config, exclusions }) {
|
|
84
|
+
const isLazyTrackingEnabled = sources.getLazyTrackingConfig(config, logger);
|
|
85
|
+
|
|
65
86
|
agentEmitter.on('assess.body', (obj, prop) => {
|
|
66
|
-
if (
|
|
87
|
+
if (isLazyTrackingEnabled) {
|
|
67
88
|
return sources.handleSourceEvent(config, exclusions, BODY, obj, prop);
|
|
68
89
|
}
|
|
69
90
|
|
|
@@ -77,7 +98,7 @@ sources.registerListeners = function({ config, exclusions }) {
|
|
|
77
98
|
});
|
|
78
99
|
});
|
|
79
100
|
agentEmitter.on('assess.headers', (obj, prop) => {
|
|
80
|
-
if (
|
|
101
|
+
if (isLazyTrackingEnabled) {
|
|
81
102
|
return sources.handleSourceEvent(config, exclusions, HEADER, obj, prop);
|
|
82
103
|
}
|
|
83
104
|
|
|
@@ -89,7 +110,7 @@ sources.registerListeners = function({ config, exclusions }) {
|
|
|
89
110
|
});
|
|
90
111
|
});
|
|
91
112
|
agentEmitter.on('assess.params', (obj, prop) => {
|
|
92
|
-
if (
|
|
113
|
+
if (isLazyTrackingEnabled) {
|
|
93
114
|
return sources.handleSourceEvent(
|
|
94
115
|
config,
|
|
95
116
|
exclusions,
|
|
@@ -107,7 +128,7 @@ sources.registerListeners = function({ config, exclusions }) {
|
|
|
107
128
|
});
|
|
108
129
|
});
|
|
109
130
|
agentEmitter.on('assess.query', (obj, prop) => {
|
|
110
|
-
if (
|
|
131
|
+
if (isLazyTrackingEnabled) {
|
|
111
132
|
return sources.handleSourceEvent(
|
|
112
133
|
config,
|
|
113
134
|
exclusions,
|
|
@@ -126,7 +147,7 @@ sources.registerListeners = function({ config, exclusions }) {
|
|
|
126
147
|
});
|
|
127
148
|
|
|
128
149
|
agentEmitter.on('assess.cookies', (obj, prop) => {
|
|
129
|
-
if (
|
|
150
|
+
if (isLazyTrackingEnabled) {
|
|
130
151
|
return sources.handleSourceEvent(config, exclusions, COOKIE, obj, prop);
|
|
131
152
|
}
|
|
132
153
|
|
|
@@ -476,7 +476,13 @@ const agent = [
|
|
|
476
476
|
name: 'agent.traverse_and_track',
|
|
477
477
|
arg: '<traverse-and-track>',
|
|
478
478
|
default: false,
|
|
479
|
-
|
|
479
|
+
fn: (val, logger) => {
|
|
480
|
+
if (val) {
|
|
481
|
+
logger.error('agent.traverse_and_track option is deprecated. Please use assess.enable_lazy_tracking from now on. It\'s value should be the opposite of this one');
|
|
482
|
+
}
|
|
483
|
+
return val;
|
|
484
|
+
},
|
|
485
|
+
desc: 'source membrane alternative (DEPRECATED)',
|
|
480
486
|
},
|
|
481
487
|
{
|
|
482
488
|
name: 'agent.polling.app_activity_ms',
|
|
@@ -747,6 +753,13 @@ const assess = [
|
|
|
747
753
|
arg: '<tags>',
|
|
748
754
|
desc: 'comma-separated list of tags to apply to each application vulnerability reported by the agent',
|
|
749
755
|
},
|
|
756
|
+
{
|
|
757
|
+
name: 'assess.enable_lazy_tracking',
|
|
758
|
+
arg: '[true]',
|
|
759
|
+
default: true,
|
|
760
|
+
fn: castBoolean,
|
|
761
|
+
desc: 'When set to `false` won\'t track the source events lazily but will track the first up to 250 source events',
|
|
762
|
+
},
|
|
750
763
|
];
|
|
751
764
|
|
|
752
765
|
const protect = [
|
package/lib/core/config/util.js
CHANGED
|
@@ -72,8 +72,8 @@ class Config {
|
|
|
72
72
|
assess: {},
|
|
73
73
|
protect: {},
|
|
74
74
|
server: {},
|
|
75
|
-
dev: {}
|
|
76
|
-
}
|
|
75
|
+
dev: {},
|
|
76
|
+
},
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -146,9 +146,10 @@ class Config {
|
|
|
146
146
|
* @return {string|void} path, if valid
|
|
147
147
|
*/
|
|
148
148
|
function checkConfigPath() {
|
|
149
|
-
const configDir =
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
const configDir =
|
|
150
|
+
os.platform() === 'win32'
|
|
151
|
+
? `${process.env['ProgramData']}\\contrast`
|
|
152
|
+
: '/etc/contrast';
|
|
152
153
|
|
|
153
154
|
for (const dir of [process.cwd(), configDir]) {
|
|
154
155
|
const checkPath = path.resolve(dir, 'contrast_security.yaml');
|
|
@@ -159,7 +160,6 @@ function checkConfigPath() {
|
|
|
159
160
|
return;
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
|
|
163
163
|
/**
|
|
164
164
|
* @param {Object} cliOptions
|
|
165
165
|
* @param {string} cliOptions.script
|
|
@@ -202,7 +202,7 @@ function readConfig(cliOptions, logger) {
|
|
|
202
202
|
// parse yaml and JSON separately.
|
|
203
203
|
try {
|
|
204
204
|
config = yaml.parse(fileContents, {
|
|
205
|
-
prettyErrors: true
|
|
205
|
+
prettyErrors: true,
|
|
206
206
|
});
|
|
207
207
|
} catch (e) {
|
|
208
208
|
logger.error(
|
|
@@ -264,7 +264,7 @@ function mergeCliOptions(cliOptions, logger) {
|
|
|
264
264
|
enum: optEnum,
|
|
265
265
|
fn = _.identity,
|
|
266
266
|
name,
|
|
267
|
-
required
|
|
267
|
+
required,
|
|
268
268
|
} = option;
|
|
269
269
|
|
|
270
270
|
const env = process.env[option.env];
|
|
@@ -294,7 +294,7 @@ function mergeCliOptions(cliOptions, logger) {
|
|
|
294
294
|
// set from default
|
|
295
295
|
if (value === undefined) {
|
|
296
296
|
if (required) {
|
|
297
|
-
logger.error(
|
|
297
|
+
logger.error("Missing required option '%s'", name);
|
|
298
298
|
return options;
|
|
299
299
|
}
|
|
300
300
|
|
|
@@ -307,10 +307,38 @@ function mergeCliOptions(cliOptions, logger) {
|
|
|
307
307
|
}, new Config());
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
+
/**
|
|
311
|
+
* When you run an appliaction with pm2 on cluster mode, pm2 attaches the
|
|
312
|
+
* process.env to a property pm2_env(only for the agent since we start it with -r flag), so
|
|
313
|
+
* the function checks if there is pm2_env property and merge contrast
|
|
314
|
+
* related properties to process.env
|
|
315
|
+
*/
|
|
316
|
+
function mergePM2Envs() {
|
|
317
|
+
if (!process.env.pm2_env) return;
|
|
318
|
+
|
|
319
|
+
const pm2_env = JSON.parse(process.env.pm2_env);
|
|
320
|
+
|
|
321
|
+
const contrastEnvs = ['DEBUG', 'PGHOST', 'PGPORT'];
|
|
322
|
+
const objectEntries = Object.entries(pm2_env.env)
|
|
323
|
+
.concat(Object.entries(pm2_env))
|
|
324
|
+
.concat(['DEBUG', 'PGHOST', 'PGPORT']);
|
|
325
|
+
|
|
326
|
+
objectEntries.forEach(([key, value]) => {
|
|
327
|
+
if (
|
|
328
|
+
!process.env[key] &&
|
|
329
|
+
(key.toLocaleLowerCase().includes('contrast') ||
|
|
330
|
+
contrastEnvs.includes(key))
|
|
331
|
+
) {
|
|
332
|
+
process.env[key] = value;
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
310
337
|
util.Config = Config;
|
|
311
338
|
util.setup = function setup(cliOptions, logger) {
|
|
312
|
-
|
|
339
|
+
mergePM2Envs();
|
|
313
340
|
|
|
341
|
+
const mergedCliOptions = mergeCliOptions(cliOptions, logger);
|
|
314
342
|
mergedCliOptions.script = cliOptions.script;
|
|
315
343
|
mergedCliOptions.configFile = cliOptions.configFile;
|
|
316
344
|
mergedCliOptions.validate();
|
|
@@ -323,7 +351,7 @@ util.logConfig = function logConfig(mergedConfig, logger) {
|
|
|
323
351
|
'Current Configuration: %s',
|
|
324
352
|
stringify(mergedConfig._flat, {
|
|
325
353
|
replacer: (k, v) => (v == undefined ? null : v),
|
|
326
|
-
space: 2
|
|
354
|
+
space: 2,
|
|
327
355
|
})
|
|
328
356
|
);
|
|
329
357
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/agent",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.18.0",
|
|
4
4
|
"description": "Node.js security instrumentation by Contrast Security",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"security",
|
|
@@ -152,6 +152,7 @@
|
|
|
152
152
|
"handlebars": "^4.7.7",
|
|
153
153
|
"husky": "^6.0.0",
|
|
154
154
|
"inquirer": "^8.1.2",
|
|
155
|
+
"jira-client": "^8.1.0",
|
|
155
156
|
"joi": "^17.4.0",
|
|
156
157
|
"jsdoc": "^3.6.10",
|
|
157
158
|
"libxmljs": "file:test/mock/libxmljs",
|