@contrast/config 1.4.0 → 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/options.js CHANGED
@@ -177,6 +177,25 @@ const api = [
177
177
  ];
178
178
 
179
179
  const agent = [
180
+ {
181
+ name: 'agent.diagnostics.enable',
182
+ arg: '[false]',
183
+ default: true,
184
+ fn: castBoolean,
185
+ desc: 'If true the agent will try to create both diagnostic files at startup',
186
+ },
187
+ {
188
+ name: 'agent.diagnostics.quiet',
189
+ arg: '[true]',
190
+ default: false,
191
+ fn: castBoolean,
192
+ desc: 'If true the agent will print all diagnostic results to stdout as well',
193
+ },
194
+ {
195
+ name: 'agent.diagnostics.report_path',
196
+ arg: '<path>',
197
+ desc: 'path indicating where to report all diagnostics results',
198
+ },
180
199
  {
181
200
  name: 'agent.reporters.file',
182
201
  arg: '<path>',
@@ -306,6 +325,21 @@ const agent = [
306
325
  desc: "set location to look for the app's package.json",
307
326
  default: process.cwd(),
308
327
  },
328
+ {
329
+ name: 'agent.node.library_usage.reporting.interval',
330
+ arg: '<num>',
331
+ fn: parseNum,
332
+ default: 1,
333
+ desc: 'frequency of collecting code events for library usage in milliseconds, defaults to 1 ms',
334
+ },
335
+ {
336
+ name: 'agent.node.library_usage.reporting.enable',
337
+ arg: '[false]',
338
+ // setting this falsee for now, until feature is complete
339
+ default: true,
340
+ fn: castBoolean,
341
+ desc: 'add enhanced library usage features (i.e. scanning for composition of dependencies, reporting usage)',
342
+ },
309
343
  {
310
344
  name: 'agent.stack_trace_limit',
311
345
  arg: '<limit>',
@@ -382,12 +416,14 @@ const protect = [
382
416
  fn: castBoolean,
383
417
  desc: 'turns on probe analysis and report them to Contrast UI'
384
418
  },
385
- ...Object.values(Rule).map((ruleId) => ({
386
- name: `protect.rules.${ruleId}.mode`,
387
- arg: '<mode>',
388
- enum: ['monitor', 'block', 'block_at_perimeter', 'off'],
389
- desc: `the mode in which to run the ${ruleId} rule`,
390
- })),
419
+ ...Object.values(Rule)
420
+ .filter((ruleId) => ![Rule.BOT_BLOCKER, Rule.IP_DENYLIST, Rule.VIRTUAL_PATCH].includes(ruleId))
421
+ .map((ruleId) => ({
422
+ name: `protect.rules.${ruleId}.mode`,
423
+ arg: '<mode>',
424
+ enum: ['monitor', 'block', 'block_at_perimeter', 'off'],
425
+ desc: `the mode in which to run the ${ruleId} rule`,
426
+ })),
391
427
  ];
392
428
 
393
429
  const assess = [
@@ -397,6 +433,21 @@ const assess = [
397
433
  fn: castBoolean,
398
434
  desc: 'if false, disable assess for this agent'
399
435
  },
436
+ {
437
+ name: 'assess.stactraces',
438
+ arg: '<level>',
439
+ default: 'ALL',
440
+ fn: uppercase,
441
+ enum: ['ALL', 'SOME', 'NONE'],
442
+ desc: 'Select the level of collected stacktraces. ALL - for all asses events, SOME - for Source and Sink events, NONE - no stacktraces collected'
443
+ },
444
+ {
445
+ name: 'assess.max_propagation_events',
446
+ arg: '<limit>',
447
+ default: 250,
448
+ fn: parseNum,
449
+ desc: 'set limit for maximum number of propagation events created per request',
450
+ },
400
451
  ];
401
452
 
402
453
  const server = [
package/lib/util.js CHANGED
@@ -42,9 +42,11 @@ function set(obj, name, value) {
42
42
  * @param {*} value
43
43
  * @param {boolean} def set from default or not
44
44
  */
45
- function setConfig(conf, name, value, def) {
45
+ function setConfig(conf, name, value, def, origin) {
46
46
  set(conf, name, value);
47
47
  conf._default[name] = def;
48
+ conf._flat[name] = value;
49
+ conf._sources[name] = origin;
48
50
  }
49
51
 
50
52
  class ConfigurationError extends Error {
@@ -57,7 +59,8 @@ class Config {
57
59
  constructor() {
58
60
  Object.assign(this, {
59
61
  _default: {},
60
- api: {},
62
+ _flat: {},
63
+ _sources: {},
61
64
  agent: {
62
65
  reporters: {},
63
66
  logger: {},
@@ -69,6 +72,7 @@ class Config {
69
72
  },
70
73
  assess: {},
71
74
  server: {},
75
+ api: {},
72
76
  });
73
77
  }
74
78
 
@@ -244,12 +248,17 @@ function mergeOptions() {
244
248
  .reduce((obj, prop) => obj?.[prop], fileOptions);
245
249
 
246
250
  // For some values, we want to know if we assigned by falling back to default
247
- let isFromDefault;
251
+ let isFromDefault, origin;
252
+
253
+ if (env != null || autoEnv != null) {
254
+ origin = 'ENV';
255
+ } else if (fileFlag != null) {
256
+ origin = 'YAML';
257
+ }
248
258
 
249
259
  // env > file > default
250
260
  let value = [env, autoEnv, fileFlag]
251
- .map((v) => fn(v))
252
- .find((flag) => flag !== undefined);
261
+ .map((v) => fn(v)).find((flag) => flag !== undefined);
253
262
 
254
263
  // if it's an enum, find it in the enum or set the value to default
255
264
  // ineffective if optDefault wasn't in the enum;
@@ -257,6 +266,7 @@ function mergeOptions() {
257
266
  if (optEnum && optEnum.indexOf(value) === -1) {
258
267
  value = fn(optDefault);
259
268
  isFromDefault = true;
269
+ origin = 'DEFAULT';
260
270
  }
261
271
 
262
272
  // set default last and separately, so that we can mark that the option was
@@ -264,9 +274,10 @@ function mergeOptions() {
264
274
  if (value === undefined) {
265
275
  value = fn(optDefault);
266
276
  isFromDefault = true;
277
+ origin = 'DEFAULT';
267
278
  }
268
279
 
269
- setConfig(options, name, value, isFromDefault);
280
+ setConfig(options, name, value, isFromDefault, origin);
270
281
  return options;
271
282
  }, new Config());
272
283
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/config",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "An API for discovering Contrast agent configuration data",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,7 +17,7 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/common": "1.2.0",
20
+ "@contrast/common": "1.3.1",
21
21
  "yaml": "^2.0.1"
22
22
  }
23
- }
23
+ }