@contrast/core 1.7.1 → 1.8.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/app-info.js CHANGED
@@ -22,10 +22,10 @@ const process = require('process');
22
22
 
23
23
  const MAX_ATTEMPTS = 5;
24
24
 
25
- module.exports = function (deps) {
26
- const { logger, config } = deps;
25
+ module.exports = function (core) {
26
+ const { logger, config } = core;
27
27
 
28
- const appInfo = (deps.appInfo = {
28
+ const appInfo = (core.appInfo = {
29
29
  os: {
30
30
  type: os.type(),
31
31
  platform: os.platform(),
@@ -83,7 +83,7 @@ module.exports = function (deps) {
83
83
  }
84
84
 
85
85
  if (packageLocation) {
86
- deps.logger.info('using package.json at %s', packageLocation);
86
+ core.logger.info('using package.json at %s', packageLocation);
87
87
  }
88
88
 
89
89
  return packageLocation;
@@ -32,6 +32,10 @@ module.exports = function(core) {
32
32
  return stacktraceFactory.captureStacktrace(...args);
33
33
  };
34
34
 
35
+ core.createSnapshot = function(...args) {
36
+ return stacktraceFactory.createSnapshot(...args);
37
+ };
38
+
35
39
  return core.captureStacktrace;
36
40
  };
37
41
 
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright: 2022 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const featureReaders = {
19
+ 'agent.logger.level': (remoteData) => remoteData.features?.logLevel,
20
+ 'agent.logger.path': (remoteData) => remoteData.features?.logFile,
21
+ 'agent.security_logger.syslog.enable': (remoteData) => remoteData.features?.defend?.syslog?.syslogEnabled,
22
+ 'agent.security_logger.syslog.ip': (remoteData) => remoteData.features?.defend?.syslog?.syslogIpAddress,
23
+ 'agent.security_logger.syslog.port': (remoteData) => remoteData.features?.defend?.syslog?.syslogPortNumber,
24
+ 'agent.security_logger.syslog.facility': (remoteData) => remoteData.features?.defend?.syslog?.syslogFacilityCode,
25
+ 'agent.security_logger.syslog.severity_exploited': (remoteData) => remoteData.features?.defend?.syslog?.syslogSeverityExploit,
26
+ 'agent.security_logger.syslog.severity_blocked': (remoteData) => remoteData.features?.defend?.syslog?.syslogSeverityBlocke,
27
+ 'agent.security_logger.syslog.severity_probed': (remoteData) => remoteData.features?.defend?.syslog?.syslogSeverityProbed,
28
+ };
29
+
30
+ module.exports = featureReaders;
@@ -0,0 +1,89 @@
1
+ /*
2
+ * Copyright: 2022 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const { Event } = require('@contrast/common');
19
+ const { configOptions } = require('@contrast/config/lib/options');
20
+
21
+ const settingsReaders = require('./settings-readers');
22
+ const featureReaders = require('./feature-readers');
23
+
24
+ module.exports = function(core) {
25
+ const { config, messages } = core;
26
+ const effectiveConfig = createEffectiveConfig({ config, remoteData: {} });
27
+
28
+ if (core.config?.protect?.enable === true) {
29
+ messages.on(Event.SERVER_SETTINGS_UPDATE, (msg) => {
30
+ msg.features && mergeRemoteData(msg, featureReaders);
31
+ msg.settings && mergeRemoteData(msg, settingsReaders);
32
+ });
33
+ }
34
+
35
+ core.getEffectiveConfig = function () {
36
+ return formatEffectiveConfig(effectiveConfig);
37
+ };
38
+ return;
39
+
40
+ function createEffectiveConfig({ config, remoteData }) {
41
+ const list = configOptions.map(({ name }) => ({
42
+ CanonicalName: name,
43
+ Name: name,
44
+ Value: config._flat[name],
45
+ Source: config._sources[name]
46
+ }));
47
+
48
+ return new Map(list.map((entry) => [entry.CanonicalName, entry]));
49
+ }
50
+
51
+ function formatEffectiveConfig(configMap) {
52
+ const values = Array.from(configMap.values()).filter(s => s.Value != undefined);
53
+
54
+ const content = {
55
+ report_create: new Date(),
56
+ status: undefined,
57
+ config: {
58
+ effective_config: values,
59
+ environment: values.filter(v => v.Source === 'ENV'),
60
+ contrast_ui: values.filter(v => v.Source === 'ContrastUI'),
61
+ file: values.filter(v => v.Source === 'YAML'),
62
+ }
63
+ };
64
+
65
+ const api = values.filter(v => v.CanonicalName == 'api.enable')[0];
66
+ const apiEnabled = api && api.Value;
67
+ if (apiEnabled) {
68
+ content.status = 'Success!';
69
+ } else {
70
+ content.status = 'Success! Couldn\'t connect to Teamserver, so no Teamserver data will be included!';
71
+ }
72
+
73
+ return content;
74
+ }
75
+
76
+ function mergeRemoteData(remoteData, readers) {
77
+ for (const [name, readerFn] of Object.entries(readers)) {
78
+ const remoteValue = readerFn(remoteData);
79
+ if (config._sources[name] === 'DEFAULT' && remoteValue != null) {
80
+ effectiveConfig.set(name, {
81
+ CanonicalName: name,
82
+ Name: name,
83
+ Value: remoteValue,
84
+ Source: 'ContrastUI',
85
+ });
86
+ }
87
+ }
88
+ }
89
+ };
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Copyright: 2022 Contrast Security, Inc
3
+ * Contact: support@contrastsecurity.com
4
+ * License: Commercial
5
+
6
+ * NOTICE: This Software and the patented inventions embodied within may only be
7
+ * used as part of Contrast Security’s commercial offerings. Even though it is
8
+ * made available through public repositories, use of this Software is subject to
9
+ * the applicable End User Licensing Agreement found at
10
+ * https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
11
+ * between Contrast Security and the End User. The Software may not be reverse
12
+ * engineered, modified, repackaged, sold, redistributed or otherwise used in a
13
+ * way not consistent with the End User License Agreement.
14
+ */
15
+
16
+ 'use strict';
17
+
18
+ const {
19
+ ProtectRuleMode: {
20
+ OFF,
21
+ BLOCK,
22
+ MONITOR,
23
+ BLOCK_AT_PERIMETER
24
+ }
25
+ } = require('@contrast/common');
26
+
27
+ const settingsReaders = [
28
+ 'protect.rules.cmd-injection.mode',
29
+ 'protect.rules.cmd-injection-command-backdoors.mode',
30
+ 'protect.rules.cmd-injection-semantic-chained-commands.mode',
31
+ 'protect.rules.cmd-injection-semantic-dangerous-paths.mode',
32
+ 'protect.rules.method-tampering.mode',
33
+ 'protect.rules.nosql-injection.mode',
34
+ 'protect.rules.nosql-injection-mongo.mode',
35
+ 'protect.rules.path-traversal.mode',
36
+ 'protect.rules.path-traversal-semantic-file-security-bypass.mode',
37
+ 'protect.rules.reflected-xss.mode',
38
+ 'protect.rules.sql-injection.mode',
39
+ 'protect.rules.ssjs-injection.mode',
40
+ 'protect.rules.unsafe-file-upload.mode',
41
+ 'protect.rules.untrusted-deserialization.mode',
42
+ 'protect.rules.xxe.mode',
43
+ ].reduce((acc, name) => {
44
+ const ruleId = name.split('.')[2];
45
+ return Object.assign(acc, {
46
+ [name]: (remoteData) => {
47
+ const remoteSetting = remoteData.settings?.defend?.protectionRules?.find(r => r.id == ruleId);
48
+ switch (remoteSetting?.mode) {
49
+ case 'OFF': return OFF;
50
+ case 'MONITORING': return MONITOR;
51
+ case 'BLOCKING': return remoteSetting.blockAtEntry ? BLOCK_AT_PERIMETER : BLOCK;
52
+ }
53
+ }
54
+ });
55
+ }, {});
56
+
57
+ module.exports = settingsReaders;
package/lib/index.d.ts CHANGED
@@ -23,6 +23,7 @@ import { Protect } from '@contrast/protect';
23
23
  import { Rewriter } from '@contrast/rewriter';
24
24
  import RequireHook from '@contrast/require-hook';
25
25
  import { Scopes } from '@contrast/scopes';
26
+ import { Deadzones } from '@contrast/deadzones';
26
27
 
27
28
  export interface Core {
28
29
  agentify: Agentify<Core>;
@@ -36,6 +37,7 @@ export interface Core {
36
37
  protect: Protect;
37
38
  rewriter: Rewriter;
38
39
  scopes: Scopes;
40
+ deadzones: Deadzones;
39
41
  }
40
42
 
41
43
  declare function init(): Core;
package/lib/index.js CHANGED
@@ -22,6 +22,7 @@ module.exports = function init(core = {}) {
22
22
 
23
23
  require('@contrast/config')(core);
24
24
  require('./logger-factory')(core);
25
+ require('./effective-config')(core);
25
26
  require('./sensitive-data-masking')(core);
26
27
  require('./app-info')(core);
27
28
  require('./is-agent-path')(core);
@@ -30,8 +31,10 @@ module.exports = function init(core = {}) {
30
31
  require('@contrast/rewriter')(core);
31
32
  require('@contrast/dep-hooks')(core);
32
33
  require('@contrast/scopes')(core);
34
+ require('@contrast/deadzones')(core);
33
35
  require('@contrast/reporter').default(core);
34
36
  require('@contrast/agentify')(core);
37
+ require('@contrast/instrumentation')(core);
35
38
 
36
39
  return core;
37
40
  };
@@ -15,7 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { simpleTraverse } = require('@contrast/common');
18
+ const { traverseKeys } = require('@contrast/common');
19
19
  const { CONTRAST_REDACTED } = require('./constants');
20
20
 
21
21
  module.exports = function(core) {
@@ -35,13 +35,11 @@ module.exports = function(core) {
35
35
  let redactedText;
36
36
  if (!target) return;
37
37
 
38
- simpleTraverse(target, (path, type, value, obj) => {
39
- if (type === 'Key') {
40
- redactedText = getRedactedText(value);
41
- if (redactedText) {
42
- obj[value] = redactedText;
43
- redactedText = undefined;
44
- }
38
+ traverseKeys(target, (path, type, value, obj) => {
39
+ redactedText = getRedactedText(value);
40
+ if (redactedText) {
41
+ obj[value] = redactedText;
42
+ redactedText = undefined;
45
43
  }
46
44
  });
47
45
  }
@@ -84,7 +84,7 @@ module.exports = function (core) {
84
84
 
85
85
  if (policy.maskAttackVector) {
86
86
  // attack values
87
- const inputAnalysis = Object.entries(msg.protect?.findings.resultsMap);
87
+ const inputAnalysis = Object.entries(msg.protect?.resultsMap);
88
88
  for (const [, results] of inputAnalysis) {
89
89
  for (const result of results) {
90
90
  const redactedText = getRedactedText(result.key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/core",
3
- "version": "1.7.1",
3
+ "version": "1.8.1",
4
4
  "description": "Preconfigured Contrast agent core services and models",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -17,15 +17,17 @@
17
17
  "test": "../scripts/test.sh"
18
18
  },
19
19
  "dependencies": {
20
- "@contrast/agentify": "1.1.2",
21
- "@contrast/common": "^1.1.5",
22
- "@contrast/config": "1.3.3",
20
+ "@contrast/agentify": "1.2.0",
21
+ "@contrast/common": "1.2.0",
22
+ "@contrast/config": "1.4.0",
23
+ "@contrast/deadzones": "1.0.0",
23
24
  "@contrast/dep-hooks": "1.0.5",
24
25
  "@contrast/fn-inspect": "^3.2.0",
26
+ "@contrast/instrumentation": "1.0.0",
25
27
  "@contrast/logger": "1.1.1",
26
- "@contrast/patcher": "1.0.6",
27
- "@contrast/reporter": "1.6.2",
28
- "@contrast/rewriter": "1.2.0",
28
+ "@contrast/patcher": "1.1.0",
29
+ "@contrast/reporter": "1.7.0",
30
+ "@contrast/rewriter": "1.3.0",
29
31
  "@contrast/scopes": "1.2.0"
30
32
  }
31
33
  }