@contrast/protect 1.85.1 → 1.86.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.
@@ -25,11 +25,11 @@ const {
25
25
  traverseKeysAndValues,
26
26
  traverseValues,
27
27
  InputType,
28
+ matchAll,
28
29
  primordials: {
29
30
  ArrayPrototypeJoin,
30
31
  ArrayPrototypeSlice,
31
32
  StringPrototypeToLowerCase,
32
- StringPrototypeMatch,
33
33
  }
34
34
  } = require('@contrast/common');
35
35
  const { Core } = require('@contrast/core');
@@ -94,7 +94,6 @@ const acceptedMethods = new Set([
94
94
  'version-control',
95
95
  ]);
96
96
  const componentName = 'protect.inputAnalysis.handlers';
97
- const noInstrumentationStore = { lock: true, name: componentName };
98
97
 
99
98
  module.exports = Core.makeComponent({
100
99
  name: componentName,
@@ -106,7 +105,6 @@ module.exports = Core.makeComponent({
106
105
  agentLib,
107
106
  inputAnalysis,
108
107
  },
109
- scopes,
110
108
  config,
111
109
  } = core;
112
110
 
@@ -955,21 +953,15 @@ module.exports = Core.makeComponent({
955
953
  function ipListAnalysis(reqIp, reqHeaders, list) {
956
954
  const forwardedIps = [];
957
955
 
958
- // RegExp.exec will still get called under the hood even with using primordials
959
- scopes.instrumentation.run(noInstrumentationStore, () => {
960
- for (let i = 0; i < reqHeaders.length; i++) {
961
- if (reqHeaders[i] === 'x-forwarded-for') {
962
- // This matches one or more valid IPv4/IPv6 characters, automatically
963
- // skipping delimiters, whitespace, and invalid characters
964
- const matches = StringPrototypeMatch.call(reqHeaders[i + 1], /[0-9a-fA-F.:]+/g);
965
- if (matches) {
966
- for (const ip of matches) {
967
- forwardedIps.push(ip);
968
- }
969
- }
956
+ for (let i = 0; i < reqHeaders.length; i++) {
957
+ if (reqHeaders[i] === 'x-forwarded-for') {
958
+ // This matches one or more valid IPv4/IPv6 characters, automatically
959
+ // skipping delimiters, whitespace, and invalid characters
960
+ for (const [ip] of matchAll(reqHeaders[i + 1], /[0-9a-fA-F.:]+/g)) {
961
+ forwardedIps.push(ip);
970
962
  }
971
963
  }
972
- });
964
+ }
973
965
 
974
966
  const ipsToCheck = [reqIp, ...forwardedIps];
975
967
  const now = new Date().getTime();
@@ -15,7 +15,7 @@
15
15
 
16
16
  'use strict';
17
17
 
18
- const { Event, primordials: { StringPrototypeToLowerCase, RegExpPrototypeTest } } = require('@contrast/common');
18
+ const { Event, primordials: { StringPrototypeToLowerCase, RegExpPrototypeExec } } = require('@contrast/common');
19
19
 
20
20
  module.exports = (core) => {
21
21
  const {
@@ -135,7 +135,7 @@ function buildCheck(evaluation, matchedValue, logger) {
135
135
  logger?.warn({ err, evaluation }, 'invalid regular expression in virtual patch, it will never match');
136
136
  return () => false;
137
137
  }
138
- const test = (reqValue) => RegExpPrototypeTest.call(regex, reqValue);
138
+ const test = (reqValue) => RegExpPrototypeExec.call(regex, reqValue) !== null;
139
139
  return evaluation === 'MATCHES' ? test : (reqValue) => !test(reqValue);
140
140
  }
141
141
  case 'EQUALS':
package/lib/policy.js CHANGED
@@ -23,7 +23,7 @@ const {
23
23
  ArrayPrototypeJoin,
24
24
  StringPrototypeToLowerCase,
25
25
  StringPrototypeSplit,
26
- RegExpPrototypeTest
26
+ RegExpPrototypeExec
27
27
  },
28
28
  set,
29
29
  } = require('@contrast/common');
@@ -208,7 +208,7 @@ module.exports = function (core) {
208
208
  if (regExpNeeded) {
209
209
  const rx = new RegExp(`^${ArrayPrototypeJoin.call(urls, '|')}$`);
210
210
 
211
- return (uriPath) => rx ? RegExpPrototypeTest.call(rx, uriPath) : false;
211
+ return (uriPath) => rx ? RegExpPrototypeExec.call(rx, uriPath) !== null : false;
212
212
  }
213
213
 
214
214
  return (uriPath) => urls.some((url) => url === uriPath);
@@ -225,7 +225,7 @@ module.exports = function (core) {
225
225
  function createInputNameMatcher(dtmInputName) {
226
226
  if (regExpCheck(dtmInputName)) {
227
227
  const rx = new RegExp(`^${dtmInputName}$`);
228
- return (inputName) => rx ? RegExpPrototypeTest.call(rx, inputName) : false;
228
+ return (inputName) => rx ? RegExpPrototypeExec.call(rx, inputName) !== null : false;
229
229
  }
230
230
 
231
231
  return (inputName) => inputName === dtmInputName;
@@ -24,7 +24,7 @@ const {
24
24
  primordials: {
25
25
  StringPrototypeReplace,
26
26
  ArrayPrototypeSlice,
27
- RegExpPrototypeTest
27
+ RegExpPrototypeExec
28
28
  }
29
29
  } = require('@contrast/common');
30
30
 
@@ -152,7 +152,7 @@ module.exports = function(core) {
152
152
  return (
153
153
  normalizedValue === normalizedCommand ||
154
154
  (normalizedCommand.endsWith(normalizedValue) &&
155
- RegExpPrototypeTest.call(SINK_EXPLOIT_PATTERN_START, normalizedCommand))
155
+ RegExpPrototypeExec.call(SINK_EXPLOIT_PATTERN_START, normalizedCommand) !== null)
156
156
  );
157
157
  }
158
158
 
@@ -14,7 +14,7 @@
14
14
  */
15
15
  'use strict';
16
16
 
17
- const { primordials: { StringPrototypeSubstr, StringPrototypeToLowerCase, RegExpPrototypeTest, RegExpPrototypeExec } } = require('@contrast/common');
17
+ const { primordials: { StringPrototypeSubstr, StringPrototypeToLowerCase, RegExpPrototypeExec } } = require('@contrast/common');
18
18
 
19
19
  const PROTOCOLS = {
20
20
  FTP: 'FTP',
@@ -67,7 +67,7 @@ function isExternalEntity(str) {
67
67
  if (str.startsWith(val)) return true;
68
68
  }
69
69
 
70
- return RegExpPrototypeTest.call(FILE_PATTERN_WINDOWS, str);
70
+ return RegExpPrototypeExec.call(FILE_PATTERN_WINDOWS, str) !== null;
71
71
  }
72
72
 
73
73
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/protect",
3
- "version": "1.85.1",
3
+ "version": "1.86.1",
4
4
  "description": "Runtime application protection (Protect)",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
@@ -21,19 +21,19 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@contrast/agent-lib": "9.2.0",
24
- "@contrast/blocking": "1.2.0",
25
- "@contrast/common": "1.44.0",
26
- "@contrast/config": "1.65.0",
27
- "@contrast/core": "1.70.0",
28
- "@contrast/dep-hooks": "1.40.0",
29
- "@contrast/esm-hooks": "2.46.0",
30
- "@contrast/instrumentation": "1.50.0",
31
- "@contrast/logger": "1.43.0",
32
- "@contrast/patcher": "1.42.0",
33
- "@contrast/rewriter": "1.47.0",
34
- "@contrast/scopes": "1.41.0",
35
- "@contrast/sources": "1.16.0",
36
- "@contrast/stack-trace-factory": "1.12.0",
24
+ "@contrast/blocking": "1.3.1",
25
+ "@contrast/common": "1.45.0",
26
+ "@contrast/config": "1.66.0",
27
+ "@contrast/core": "1.71.0",
28
+ "@contrast/dep-hooks": "1.41.1",
29
+ "@contrast/esm-hooks": "2.47.1",
30
+ "@contrast/instrumentation": "1.51.1",
31
+ "@contrast/logger": "1.44.1",
32
+ "@contrast/patcher": "1.43.1",
33
+ "@contrast/rewriter": "1.48.1",
34
+ "@contrast/scopes": "1.42.1",
35
+ "@contrast/sources": "1.17.0",
36
+ "@contrast/stack-trace-factory": "1.13.1",
37
37
  "async-hook-domain": "4.0.1",
38
38
  "ipaddr.js": "2.5.0",
39
39
  "on-finished": "2.4.1",