@contrast/config 1.34.0 → 1.35.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/common.js CHANGED
@@ -74,8 +74,9 @@ const ConfigSource = {
74
74
 
75
75
  // these should return `undefined` if there is no remote value corresponding to the effective config name.
76
76
  const mappings = {
77
- // application-create
78
- 'application.session_id': (remoteData) => remoteData.settings?.assessment?.session_id,
77
+ // agent startup (v1) or application startup (ng fallback)
78
+ 'application.session_id': (remoteData) =>
79
+ remoteData.identification?.session_id ?? remoteData.settings?.assessment?.session_id,
79
80
  // application settings
80
81
  'protect.enable': (remoteData) => remoteData.protect?.enable,
81
82
  'protect.rules.cmd-injection.mode': protectModeReader(CMD_INJECTION),
package/lib/config.js CHANGED
@@ -20,7 +20,7 @@ const path = require('path');
20
20
  const fs = require('fs');
21
21
  const os = require('os');
22
22
  const yaml = require('yaml');
23
- const { Event, get, set, primordials: { ArrayPrototypeJoin, BufferPrototypeToString, StringPrototypeToUpperCase, JSONParse } } = require('@contrast/common');
23
+ const { Event, get, set, primordials: { ArrayPrototypeJoin, StringPrototypeToUpperCase, JSONParse } } = require('@contrast/common');
24
24
  const options = require('./options');
25
25
  const {
26
26
  ConfigSource: {
@@ -161,11 +161,12 @@ module.exports = class Config {
161
161
 
162
162
  const { _filepath } = this;
163
163
 
164
- if (_filepath) {
164
+ // deliberately ignore /dev/null (linux) and \\.\\nul (windows)
165
+ if (_filepath && _filepath !== os.devNull) {
165
166
  let fileContents;
166
167
 
167
168
  try {
168
- fileContents = BufferPrototypeToString.call(fs.readFileSync(_filepath), 'utf-8');
169
+ fileContents = fs.readFileSync(_filepath, 'utf-8');
169
170
  } catch (e) {
170
171
  const err = new Error(`Unable to read Contrast configuration file: '${_filepath}'`);
171
172
  err.cause = e;
@@ -242,9 +243,8 @@ module.exports = class Config {
242
243
  Array.from(this._effectiveMap.values()).forEach((v) => {
243
244
  let { value } = v;
244
245
  if (redact) value = this._redact(v.name, v.value);
245
- if (value === undefined) value = null;
246
246
 
247
- const redacted = { ...v, value: String(value) };
247
+ const redacted = { ...v, value: value !== null ? String(value) : null };
248
248
  effective_config.push(redacted);
249
249
  if (v.source === ENVIRONMENT_VARIABLE) environment_variable.push(redacted);
250
250
  if (v.source === CONTRAST_UI) contrast_ui.push(redacted);
package/lib/index.d.ts CHANGED
@@ -262,35 +262,24 @@ export interface Config {
262
262
  };
263
263
 
264
264
  application: {
265
- /** override the reported application name. */
265
+ /** Override the reported application name. */
266
266
  name?: string;
267
- /** override the reported application path. Default: `'/'` */
267
+ /** Override the reported application path. Default: `'/'` */
268
268
  path: string;
269
- /** override the reported application version */
269
+ /** Add the name of the application group with which this application should be associated in the Contrast UI. */
270
+ group?: string;
271
+ /** Add the application code this application should use in the Contrast UI. */
272
+ code?: string;
273
+ /** Override the reported application version. */
270
274
  version?: string;
271
-
272
- /**
273
- * Provide the ID of a session existing within Contrast UI.
274
- * Default: `null`
275
- */
276
- session_id: string | null;
277
-
278
- /**
279
- * How to report the application's group for auto-grouping
280
- */
281
- group: string | null;
282
-
283
- /**
284
- * Comma-separated list of key=value pairs that are applied to each application reported by the agent.
285
- */
286
- metadata: string | null;
287
-
288
- /**
289
- * Provide metadata used to create a new session within Contrast UI.
290
- * Default: `null`
291
- */
292
- session_metadata: string | null;
293
-
275
+ /** Apply labels to an application. Labels must be formatted as a comma-delimited list. Example - `label1,label2,label3` */
276
+ tags?: string;
277
+ /** Comma-separated list of key=value pairs that are applied to each application reported by the agent. */
278
+ metadata?: string;
279
+ /** Provide the ID of a session existing within Contrast UI. Exclusive with `session_metadata` */
280
+ session_id?: string;
281
+ /** Provide metadata used to create a new session within Contrast UI. Exclusive with `session_id` */
282
+ session_metadata?: string;
294
283
  };
295
284
 
296
285
  /** Reported server information overrides */
package/lib/options.js CHANGED
@@ -634,7 +634,7 @@ Example - \`label1, label2, label3\``,
634
634
  {
635
635
  name: 'application.name',
636
636
  arg: '<name>',
637
- desc: "Override the reported application name. Defaults to the `name` field from an application's `package.json`",
637
+ desc: 'Override the reported application name.',
638
638
  },
639
639
  {
640
640
  name: 'application.path',
@@ -642,33 +642,41 @@ Example - \`label1, label2, label3\``,
642
642
  default: '/',
643
643
  desc: 'Override the reported application path.',
644
644
  },
645
+ {
646
+ name: 'application.group',
647
+ arg: '<group>',
648
+ desc: 'Add the name of the application group with which this application should be associated in the Contrast UI.',
649
+ },
650
+ {
651
+ name: 'application.code',
652
+ arg: '<code>',
653
+ desc: 'Add the application code this application should use in the Contrast UI.'
654
+ },
645
655
  {
646
656
  name: 'application.version',
647
657
  arg: '<version>',
648
- desc: "Override the reported application version. Defaults to the `version` field from an application's `package.json`",
658
+ desc: 'Override the reported application version.',
659
+ },
660
+ {
661
+ name: 'application.tags',
662
+ arg: '<tags>',
663
+ desc: 'Apply labels to an application. Labels must be formatted as a comma-delimited list. Example - `label1,label2,label3`'
664
+ },
665
+ {
666
+ name: 'application.metadata',
667
+ arg: '<metadata>',
668
+ desc: 'Define a set of `key=value` pairs (which conforms to RFC 2253) for specifying user-defined metadata associated with the application. The set must be formatted as a comma-delimited list of `key=value` pairs. Example - `business-unit=accounting, office=Baltimore`',
649
669
  },
650
670
  {
651
671
  name: 'application.session_id',
652
672
  arg: '<session_id>',
653
- default: null,
654
673
  desc: 'Provide the ID of a session which already exists in the Contrast UI. Vulnerabilities discovered by the agent are associated with this session. If an invalid ID is supplied, the agent will be disabled. This option and `application.session_metadata` are mutually exclusive; if both are set, the agent will be disabled.',
655
674
  },
656
675
  {
657
676
  name: 'application.session_metadata',
658
677
  arg: '<session_metadata>',
659
- default: null,
660
678
  desc: 'Provide metadata which is used to create a new session ID in the Contrast UI. Vulnerabilities discovered by the agent are associated with this new session. This value should be formatted as `key=value` pairs (conforming to RFC 2253). Available key names for this configuration are branchName, buildNumber, commitHash, committer, gitTag, repository, testRun, and version. This option and `application.session_id` are mutually exclusive; if both are set the agent will be disabled.',
661
679
  },
662
- {
663
- name: 'application.group',
664
- arg: '<tags>',
665
- desc: "how to report the application's group for auto-grouping",
666
- },
667
- {
668
- name: 'application.metadata',
669
- arg: '<metadata>',
670
- desc: 'comma-separated list of key=value pairs that are applied to each application reported by the agent.',
671
- },
672
680
  // server
673
681
  {
674
682
  name: 'server.name',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/config",
3
- "version": "1.34.0",
3
+ "version": "1.35.0",
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)",