@contrast/protect 1.80.0 → 1.82.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.
@@ -48,7 +48,10 @@ module.exports = function(core) {
48
48
  getResults(sourceContext, ruleId).push(result);
49
49
 
50
50
  let blockInfo;
51
- if (BLOCKING_MODES.includes(mode)) {
51
+ if (
52
+ sourceContext.policy.allowBlock &&
53
+ BLOCKING_MODES.includes(mode)
54
+ ) {
52
55
  result.blocked = true;
53
56
  blockInfo = [mode, ruleId];
54
57
  sourceContext.securityException = blockInfo;
package/lib/index.js CHANGED
@@ -20,7 +20,7 @@ const { callChildComponentMethodsSync, Event } = require('@contrast/common');
20
20
  const { ConfigSource } = require('@contrast/config');
21
21
 
22
22
  module.exports = function(core) {
23
- const { config, sources } = core;
23
+ const { config, logger, sources } = core;
24
24
 
25
25
  const protect = core.protect = {
26
26
  agentLib: module.exports.instantiateAgentLib(),
@@ -38,6 +38,11 @@ module.exports = function(core) {
38
38
  require('./semantic-analysis')(core);
39
39
 
40
40
  protect.install = function install() {
41
+ if (!config.getEffectiveValue('entitlements.protect.allow')) {
42
+ logger.debug('Protect is disabled: not allowed from entitlements');
43
+ return;
44
+ }
45
+
41
46
  // only force instrumentation if assess is explicitly enabled in local config
42
47
  const forceInstrumentation =
43
48
  config.preinstrument &&
@@ -47,11 +52,11 @@ module.exports = function(core) {
47
52
  !forceInstrumentation &&
48
53
  !core.config.getEffectiveValue('protect.enable')
49
54
  ) {
50
- core.logger.debug('protect is disabled, skipping installation');
55
+ logger.debug('Protect is disabled and will not be installed');
51
56
  return;
52
57
  }
53
58
 
54
- core.rewriter.install('protect');
59
+ core.rewriter.modes.add('protect');
55
60
  callChildComponentMethodsSync(protect, 'install');
56
61
  };
57
62
 
@@ -32,7 +32,7 @@ const {
32
32
  StringPrototypeMatch,
33
33
  }
34
34
  } = require('@contrast/common');
35
- const { Core } = require('@contrast/core/lib/ioc/core');
35
+ const { Core } = require('@contrast/core');
36
36
 
37
37
  //
38
38
  // these rules are not implemented by agent-lib, but are being considered for
@@ -199,7 +199,11 @@ module.exports = Core.makeComponent({
199
199
  // block.
200
200
  const mode = policy.getRuleMode(r.ruleId);
201
201
 
202
- if (r.score >= 90 && BLOCKING_MODES.includes(mode)) {
202
+ if (
203
+ r.score >= 90 &&
204
+ BLOCKING_MODES.includes(mode) &&
205
+ policy.allowBlock
206
+ ) {
203
207
  r.blocked = true;
204
208
  findings.securityException = [mode, r.ruleId, { result: r }];
205
209
  }
@@ -337,7 +341,7 @@ module.exports = Core.makeComponent({
337
341
  inputAnalysis.handleVirtualPatches(sourceContext, { PARAMETERS: queryParams });
338
342
 
339
343
  const block = commonObjectAnalyzer(sourceContext, queryParams, parameterInputTypes);
340
- if (block) {
344
+ if (sourceContext.policy.allowBlock && block) {
341
345
  core.protect.reportFinding(block[2]);
342
346
  core.protect.throwSecurityException(sourceContext);
343
347
  }
@@ -406,8 +410,7 @@ module.exports = Core.makeComponent({
406
410
  };
407
411
 
408
412
  const block = mergeFindings(sourceContext, urlParamsFindings);
409
-
410
- if (block) {
413
+ if (sourceContext.policy.allowBlock && block) {
411
414
  if (block[2]) {
412
415
  core.protect.reportFinding(block[2]);
413
416
  }
@@ -441,8 +444,7 @@ module.exports = Core.makeComponent({
441
444
  const cookieFindings = agentLib.scoreRequestConnect(rulesMask, { cookies: cookiesArr }, preferWW);
442
445
 
443
446
  const block = mergeFindings(sourceContext, cookieFindings);
444
-
445
- if (block) {
447
+ if (sourceContext.policy.allowBlock && block) {
446
448
  protect.reportFinding(block[2]);
447
449
  core.protect.throwSecurityException(sourceContext);
448
450
  }
@@ -481,10 +483,8 @@ module.exports = Core.makeComponent({
481
483
  }
482
484
 
483
485
  const block = commonObjectAnalyzer(sourceContext, parsedBody, inputTypes);
484
-
485
486
  sourceContext.bodyType = bodyType;
486
-
487
- if (block) {
487
+ if (sourceContext.policy.allowBlock && block) {
488
488
  protect.reportFinding(block[2]);
489
489
  core.protect.throwSecurityException(sourceContext);
490
490
  }
@@ -530,14 +530,16 @@ module.exports = Core.makeComponent({
530
530
  };
531
531
 
532
532
  const block = mergeFindings(sourceContext, unsafeFilenameFindings);
533
-
534
- if (block) {
533
+ if (sourceContext.policy.allowBlock && block) {
535
534
  core.protect.reportFinding(block[2]);
536
535
  core.protect.throwSecurityException(sourceContext);
537
536
  }
538
537
  };
539
538
 
540
539
  inputAnalysis.handleVirtualPatches = function(sourceContext, requestInput) {
540
+ // should get rules in this case but check anyway
541
+ if (!sourceContext?.policy?.allowBlock) return;
542
+
541
543
  const ruleId = Rule.VIRTUAL_PATCH;
542
544
 
543
545
  if (!Object.keys(requestInput).filter(Boolean).length || !sourceContext?.virtualPatchesEvaluators.length) return;
@@ -589,7 +591,11 @@ module.exports = Core.makeComponent({
589
591
  inputAnalysis.handleIpDenylist = function(sourceContext, ipDenylist) {
590
592
  const ruleId = Rule.IP_DENYLIST;
591
593
 
592
- if (!sourceContext || !ipDenylist.length) return;
594
+ if (
595
+ !sourceContext ||
596
+ !ipDenylist.length ||
597
+ !sourceContext.policy.allowBlock // shouldn't get rules in this case but check anyway
598
+ ) return;
593
599
 
594
600
  const { sourceInfo } = core.scopes.sources.getStore();
595
601
  const match = ipListAnalysis(sourceInfo.ip, sourceInfo.rawHeaders, ipDenylist);
@@ -631,12 +637,15 @@ module.exports = Core.makeComponent({
631
637
  key: 'method',
632
638
  value: method,
633
639
  blocked: false,
640
+ exploited: true,
634
641
  };
635
642
 
636
643
  sourceContext.resultsMap[ruleId] = [result];
637
644
 
638
- if (BLOCKING_MODES.includes(mode)) {
639
- result.exploited = true;
645
+ if (
646
+ sourceContext.policy.allowBlock &&
647
+ BLOCKING_MODES.includes(mode)
648
+ ) {
640
649
  result.blocked = true;
641
650
  return sourceContext.securityException = ['block', ruleId, { result }];
642
651
  }
@@ -40,6 +40,9 @@ module.exports = function(core) {
40
40
  sourceContext.parsedCdsKeyParams = true;
41
41
 
42
42
  const params = req?.params?.length ? req.params : [];
43
+
44
+ if (req?.data) params.push(req.data);
45
+
43
46
  const queries = Array.isArray(req?.query)
44
47
  ? req.query
45
48
  : req?.query ? [req.query] : [];
@@ -47,7 +47,10 @@ module.exports = function(core) {
47
47
  const eventArg = { findings, result, sinkContext };
48
48
 
49
49
  let blockInfo;
50
- if (BLOCKING_MODES.includes(mode)) {
50
+ if (
51
+ sourceContext.policy.allowBlock &&
52
+ BLOCKING_MODES.includes(mode)
53
+ ) {
51
54
  result.blocked = true;
52
55
  blockInfo = [mode, ruleId, eventArg];
53
56
  sourceContext.securityException = blockInfo;
package/lib/policy.js CHANGED
@@ -79,11 +79,17 @@ module.exports = function (core) {
79
79
  const { uriPath } = this.sourceInfo;
80
80
  this.version = core.protect.policy.version;
81
81
 
82
- if (!this.core.config.getEffectiveValue('protect.enable')) {
82
+ if (
83
+ !this.core.config.getEffectiveValue('protect.enable') ||
84
+ !this.core.config.getEffectiveValue('entitlements.protect.allow')
85
+ ) {
86
+ // allowed in this sense means don't analyze
83
87
  this.allowed = true;
84
88
  return;
85
89
  }
86
90
 
91
+ this.allowBlock = this.core.config.getEffectiveValue('entitlements.protect.allow_block');
92
+
87
93
  // todo build exclusions
88
94
  for (const [inputType, exclusions] of Object.entries(processedExclusions)) {
89
95
  for (const e of exclusions) {
@@ -70,7 +70,10 @@ module.exports = function(core) {
70
70
  getRuleResults(sourceContext.resultsMap, ruleId).push(result);
71
71
 
72
72
  let blockInfo;
73
- if (BLOCKING_MODES.includes(mode)) {
73
+ if (
74
+ sourceContext.policy.allowBlock &&
75
+ BLOCKING_MODES.includes(mode)
76
+ ) {
74
77
  result.blocked = true;
75
78
  blockInfo = [mode, ruleId];
76
79
  sourceContext.securityException = blockInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/protect",
3
- "version": "1.80.0",
3
+ "version": "1.82.0",
4
4
  "description": "Contrast service providing framework-agnostic Protect support",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -22,16 +22,16 @@
22
22
  "dependencies": {
23
23
  "@contrast/agent-lib": "9.2.0",
24
24
  "@contrast/common": "1.42.0",
25
- "@contrast/config": "1.61.0",
26
- "@contrast/core": "1.66.0",
27
- "@contrast/dep-hooks": "1.35.0",
28
- "@contrast/esm-hooks": "2.41.0",
29
- "@contrast/instrumentation": "1.45.0",
30
- "@contrast/logger": "1.39.0",
31
- "@contrast/patcher": "1.38.0",
32
- "@contrast/rewriter": "1.43.0",
33
- "@contrast/scopes": "1.36.0",
34
- "@contrast/stack-trace-factory": "1.7.0",
25
+ "@contrast/config": "1.63.0",
26
+ "@contrast/core": "1.68.0",
27
+ "@contrast/dep-hooks": "1.37.0",
28
+ "@contrast/esm-hooks": "2.43.0",
29
+ "@contrast/instrumentation": "1.47.0",
30
+ "@contrast/logger": "1.41.0",
31
+ "@contrast/patcher": "1.40.0",
32
+ "@contrast/rewriter": "1.45.0",
33
+ "@contrast/scopes": "1.38.0",
34
+ "@contrast/stack-trace-factory": "1.9.0",
35
35
  "async-hook-domain": "4.0.1",
36
36
  "ipaddr.js": "2.4.0",
37
37
  "on-finished": "2.4.1",