@contrast/agent 4.31.2 → 4.32.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/contrast.js CHANGED
@@ -191,6 +191,18 @@ function getAgentArgs(options) {
191
191
  return agentArgs;
192
192
  }
193
193
 
194
+ function parseArgv(argv) {
195
+ const parsed = [];
196
+ const cwd = process.cwd();
197
+ for (let i = 0; i < argv.length; i++) {
198
+ if (argv[i].includes(cwd)) {
199
+ parsed.push(path.relative(cwd, argv[i]).toLowerCase());
200
+ } else {
201
+ parsed.push(path.basename(argv[i]).toLowerCase());
202
+ }
203
+ }
204
+ return parsed;
205
+ }
194
206
  /**
195
207
  * Initializes config, logger and other non-instrumentation code.
196
208
  *
@@ -210,6 +222,26 @@ contrastAgent.prepare = function(...args) {
210
222
  const configUtil = require('./core/config/util');
211
223
  const config = configUtil.setup(options, logger);
212
224
 
225
+ if (config.agent.node.exclusive_entrypoint) {
226
+ const parsed = parseArgv(process.argv);
227
+ if (!parsed.includes(config.agent.node.exclusive_entrypoint)) {
228
+ return false;
229
+ }
230
+ }
231
+
232
+ if (config.agent.node.cmd_ignore_list) {
233
+ const parsed = parseArgv(process.argv);
234
+ const cmdIgnoreList = config.agent.node.cmd_ignore_list.split(',');
235
+ if (parsed.includes('npm')) {
236
+ if (cmdIgnoreList.includes('npm*')) return false;
237
+ parsed.shift();
238
+ }
239
+ const cmd = parsed.join(' ');
240
+ if (cmdIgnoreList.includes(cmd)) {
241
+ return false;
242
+ }
243
+ }
244
+
213
245
  loggerFactory.init(config);
214
246
 
215
247
  contrastAgent.doImports();
@@ -454,6 +454,18 @@ const agent = [
454
454
  default: 16,
455
455
  desc: 'set the maximum body size that will be sent to speedracer for input analysis',
456
456
  },
457
+ {
458
+ // SEE NODE-2886
459
+ name: 'agent.node.cmd_ignore_list',
460
+ arg: '<commands>',
461
+ desc: 'comma-separated list of commands that will not startup the agent if agent is required; npm* will ignore all npm executables but not your application\'s scripts'
462
+ },
463
+ {
464
+ // SEE NODE-2886
465
+ name: 'agent.node.exclusive_entrypoint',
466
+ arg: '<entrypoint.js>',
467
+ desc: 'an entrypoint for an application that, when specified, will prevent the agent instrumenting on anything else'
468
+ },
457
469
  {
458
470
  name: 'agent.heap_dump.enable',
459
471
  arg: '[true]',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/agent",
3
- "version": "4.31.2",
3
+ "version": "4.32.0",
4
4
  "description": "Node.js security instrumentation by Contrast Security",
5
5
  "keywords": [
6
6
  "security",