@contrast/config 1.34.0 → 1.36.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 +3 -2
- package/lib/config.js +10 -6
- package/lib/index.d.ts +26 -27
- package/lib/options.js +39 -16
- package/package.json +1 -1
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
|
|
78
|
-
'application.session_id': (remoteData) =>
|
|
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,
|
|
23
|
+
const { Event, get, set, primordials: { ArrayPrototypeJoin, StringPrototypeToUpperCase, JSONParse } } = require('@contrast/common');
|
|
24
24
|
const options = require('./options');
|
|
25
25
|
const {
|
|
26
26
|
ConfigSource: {
|
|
@@ -60,7 +60,11 @@ module.exports = class Config {
|
|
|
60
60
|
node: {},
|
|
61
61
|
};
|
|
62
62
|
this.application = {};
|
|
63
|
-
this.assess = {
|
|
63
|
+
this.assess = {
|
|
64
|
+
probabilistic_sampling: {
|
|
65
|
+
route_monitor: {}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
64
68
|
this.inventory = {};
|
|
65
69
|
this.protect = {
|
|
66
70
|
rules: {},
|
|
@@ -161,11 +165,12 @@ module.exports = class Config {
|
|
|
161
165
|
|
|
162
166
|
const { _filepath } = this;
|
|
163
167
|
|
|
164
|
-
|
|
168
|
+
// deliberately ignore /dev/null (linux) and \\.\\nul (windows)
|
|
169
|
+
if (_filepath && _filepath !== os.devNull) {
|
|
165
170
|
let fileContents;
|
|
166
171
|
|
|
167
172
|
try {
|
|
168
|
-
fileContents =
|
|
173
|
+
fileContents = fs.readFileSync(_filepath, 'utf-8');
|
|
169
174
|
} catch (e) {
|
|
170
175
|
const err = new Error(`Unable to read Contrast configuration file: '${_filepath}'`);
|
|
171
176
|
err.cause = e;
|
|
@@ -242,9 +247,8 @@ module.exports = class Config {
|
|
|
242
247
|
Array.from(this._effectiveMap.values()).forEach((v) => {
|
|
243
248
|
let { value } = v;
|
|
244
249
|
if (redact) value = this._redact(v.name, v.value);
|
|
245
|
-
if (value === undefined) value = null;
|
|
246
250
|
|
|
247
|
-
const redacted = { ...v, value: String(value) };
|
|
251
|
+
const redacted = { ...v, value: value !== null ? String(value) : null };
|
|
248
252
|
effective_config.push(redacted);
|
|
249
253
|
if (v.source === ENVIRONMENT_VARIABLE) environment_variable.push(redacted);
|
|
250
254
|
if (v.source === CONTRAST_UI) contrast_ui.push(redacted);
|
package/lib/index.d.ts
CHANGED
|
@@ -241,6 +241,16 @@ export interface Config {
|
|
|
241
241
|
|
|
242
242
|
/** Defualt: `false` */
|
|
243
243
|
trust_custom_validators: boolean;
|
|
244
|
+
|
|
245
|
+
// effective based on local config and 'assess.sampling' TS DTM
|
|
246
|
+
probabilistic_sampling: {
|
|
247
|
+
/** Defualt: `false` */
|
|
248
|
+
enable: boolean,
|
|
249
|
+
route_monitor: {
|
|
250
|
+
/** Defualt: `3600000` */
|
|
251
|
+
ttl_ms: number,
|
|
252
|
+
}
|
|
253
|
+
}
|
|
244
254
|
};
|
|
245
255
|
|
|
246
256
|
protect: {
|
|
@@ -256,41 +266,30 @@ export interface Config {
|
|
|
256
266
|
/**
|
|
257
267
|
* List of rule ids to disable.
|
|
258
268
|
* Default: `[]`
|
|
259
|
-
|
|
269
|
+
*/
|
|
260
270
|
disabled_rules: string[];
|
|
261
271
|
} & Record<Omit<Rule, Rule.BOT_BLOCKER | Rule.IP_DENYLIST | Rule.VIRTUAL_PATCH>, { mode: ProtectRuleMode }>;
|
|
262
272
|
};
|
|
263
273
|
|
|
264
274
|
application: {
|
|
265
|
-
/**
|
|
275
|
+
/** Override the reported application name. */
|
|
266
276
|
name?: string;
|
|
267
|
-
/**
|
|
277
|
+
/** Override the reported application path. Default: `'/'` */
|
|
268
278
|
path: string;
|
|
269
|
-
/**
|
|
279
|
+
/** Add the name of the application group with which this application should be associated in the Contrast UI. */
|
|
280
|
+
group?: string;
|
|
281
|
+
/** Add the application code this application should use in the Contrast UI. */
|
|
282
|
+
code?: string;
|
|
283
|
+
/** Override the reported application version. */
|
|
270
284
|
version?: string;
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
session_id
|
|
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
|
-
|
|
285
|
+
/** Apply labels to an application. Labels must be formatted as a comma-delimited list. Example - `label1,label2,label3` */
|
|
286
|
+
tags?: string;
|
|
287
|
+
/** Comma-separated list of key=value pairs that are applied to each application reported by the agent. */
|
|
288
|
+
metadata?: string;
|
|
289
|
+
/** Provide the ID of a session existing within Contrast UI. Exclusive with `session_metadata` */
|
|
290
|
+
session_id?: string;
|
|
291
|
+
/** Provide metadata used to create a new session within Contrast UI. Exclusive with `session_id` */
|
|
292
|
+
session_metadata?: string;
|
|
294
293
|
};
|
|
295
294
|
|
|
296
295
|
/** Reported server information overrides */
|
package/lib/options.js
CHANGED
|
@@ -541,6 +541,7 @@ Example - \`/opt/Contrast/contrast.log\` creates a log in the \`/opt/Contrast\`
|
|
|
541
541
|
desc: 'Set to true to enable sampling of requests for dataflow and other Assess features',
|
|
542
542
|
},
|
|
543
543
|
{
|
|
544
|
+
// effective based on local config and 'assess.sampling' TeamServer DTM
|
|
544
545
|
name: 'assess.probabilistic_sampling.base_probability',
|
|
545
546
|
arg: '<probability>',
|
|
546
547
|
fn: (val) => {
|
|
@@ -553,8 +554,22 @@ Example - \`/opt/Contrast/contrast.log\` creates a log in the \`/opt/Contrast\`
|
|
|
553
554
|
});
|
|
554
555
|
}
|
|
555
556
|
},
|
|
556
|
-
default: 0.
|
|
557
|
-
desc: 'A value p within the
|
|
557
|
+
default: 0.10,
|
|
558
|
+
desc: 'A value p within the range [0, 1]. Each request will share same probability p of being sampled.',
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
name: 'assess.probabilistic_sampling.route_monitor.enable',
|
|
562
|
+
arg: '[true]',
|
|
563
|
+
default: true,
|
|
564
|
+
fn: castBoolean,
|
|
565
|
+
desc: 'The agent will keep track of which routes have been analyzed and skip analysis if the route was recently sampled.',
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
name: 'assess.probabilistic_sampling.route_monitor.ttl_ms',
|
|
569
|
+
arg: '<number>',
|
|
570
|
+
default: 1_800_000,
|
|
571
|
+
fn: parseNum,
|
|
572
|
+
desc: 'Limits individual route analysis to once per this value. Defaults to 1_800_000ms (30 minutes).',
|
|
558
573
|
},
|
|
559
574
|
{
|
|
560
575
|
name: 'assess.tags',
|
|
@@ -634,7 +649,7 @@ Example - \`label1, label2, label3\``,
|
|
|
634
649
|
{
|
|
635
650
|
name: 'application.name',
|
|
636
651
|
arg: '<name>',
|
|
637
|
-
desc:
|
|
652
|
+
desc: 'Override the reported application name.',
|
|
638
653
|
},
|
|
639
654
|
{
|
|
640
655
|
name: 'application.path',
|
|
@@ -642,33 +657,41 @@ Example - \`label1, label2, label3\``,
|
|
|
642
657
|
default: '/',
|
|
643
658
|
desc: 'Override the reported application path.',
|
|
644
659
|
},
|
|
660
|
+
{
|
|
661
|
+
name: 'application.group',
|
|
662
|
+
arg: '<group>',
|
|
663
|
+
desc: 'Add the name of the application group with which this application should be associated in the Contrast UI.',
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
name: 'application.code',
|
|
667
|
+
arg: '<code>',
|
|
668
|
+
desc: 'Add the application code this application should use in the Contrast UI.'
|
|
669
|
+
},
|
|
645
670
|
{
|
|
646
671
|
name: 'application.version',
|
|
647
672
|
arg: '<version>',
|
|
648
|
-
desc:
|
|
673
|
+
desc: 'Override the reported application version.',
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
name: 'application.tags',
|
|
677
|
+
arg: '<tags>',
|
|
678
|
+
desc: 'Apply labels to an application. Labels must be formatted as a comma-delimited list. Example - `label1,label2,label3`'
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
name: 'application.metadata',
|
|
682
|
+
arg: '<metadata>',
|
|
683
|
+
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
684
|
},
|
|
650
685
|
{
|
|
651
686
|
name: 'application.session_id',
|
|
652
687
|
arg: '<session_id>',
|
|
653
|
-
default: null,
|
|
654
688
|
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
689
|
},
|
|
656
690
|
{
|
|
657
691
|
name: 'application.session_metadata',
|
|
658
692
|
arg: '<session_metadata>',
|
|
659
|
-
default: null,
|
|
660
693
|
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
694
|
},
|
|
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
695
|
// server
|
|
673
696
|
{
|
|
674
697
|
name: 'server.name',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/config",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.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)",
|