perimeterx-js-core 0.20.0 → 0.21.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.
Files changed (62) hide show
  1. package/lib/cjs/config/ConfigurationBase.js +6 -4
  2. package/lib/cjs/config/ConfigurationBuilderBase.js +7 -2
  3. package/lib/cjs/config/defaults/DefaultConfigurationParams.js +133 -15
  4. package/lib/cjs/config/defaults/index.js +0 -3
  5. package/lib/cjs/config/params/StaticConfigurationParamsOnly.js +2 -0
  6. package/lib/cjs/config/params/index.js +3 -2
  7. package/lib/cjs/config/remote_config/RemoteConfigUtils.js +25 -0
  8. package/lib/cjs/config/remote_config/constants.js +9 -1
  9. package/lib/cjs/graphql/DefaultGraphQLParser.js +6 -2
  10. package/lib/cjs/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +3 -2
  11. package/lib/cjs/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +1 -1
  12. package/lib/cjs/telemetry/DefaultTelemetry.js +3 -3
  13. package/lib/cjs/utils/constants.js +3 -2
  14. package/lib/cjs/utils/utils.js +34 -5
  15. package/lib/esm/config/ConfigurationBase.js +9 -4
  16. package/lib/esm/config/ConfigurationBuilderBase.js +7 -2
  17. package/lib/esm/config/defaults/DefaultConfigurationParams.js +131 -6
  18. package/lib/esm/config/defaults/index.js +0 -3
  19. package/lib/esm/config/params/StaticConfigurationParamsOnly.js +1 -0
  20. package/lib/esm/config/params/index.js +3 -2
  21. package/lib/esm/config/remote_config/RemoteConfigUtils.js +21 -2
  22. package/lib/esm/config/remote_config/constants.js +8 -0
  23. package/lib/esm/graphql/DefaultGraphQLParser.js +5 -2
  24. package/lib/esm/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
  25. package/lib/esm/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +1 -1
  26. package/lib/esm/telemetry/DefaultTelemetry.js +4 -4
  27. package/lib/esm/utils/constants.js +2 -1
  28. package/lib/esm/utils/utils.js +32 -4
  29. package/lib/types/config/ConfigurationBase.d.ts +10 -10
  30. package/lib/types/config/ConfigurationBuilderBase.d.ts +4 -4
  31. package/lib/types/config/IConfiguration.d.ts +5 -5
  32. package/lib/types/config/defaults/DefaultConfigurationParams.d.ts +1 -1
  33. package/lib/types/config/defaults/index.d.ts +0 -3
  34. package/lib/types/config/params/CommonConfigurationParams.d.ts +1 -2
  35. package/lib/types/config/params/ConfigurationParams.d.ts +3 -3
  36. package/lib/types/config/params/RemoteConfigurationParams.d.ts +3 -5
  37. package/lib/types/config/params/RemoteConfigurationParamsOnly.d.ts +10 -0
  38. package/lib/types/config/params/StaticConfigurationParams.d.ts +3 -7
  39. package/lib/types/config/params/StaticConfigurationParamsOnly.d.ts +7 -0
  40. package/lib/types/config/params/index.d.ts +3 -2
  41. package/lib/types/config/remote_config/RemoteConfigUtils.d.ts +4 -0
  42. package/lib/types/config/remote_config/constants.d.ts +2 -0
  43. package/lib/types/config/remote_config/model/RemoteConfigData.d.ts +2 -2
  44. package/lib/types/telemetry/model/TelemetryActivity.d.ts +3 -3
  45. package/lib/types/utils/constants.d.ts +2 -1
  46. package/lib/types/utils/utils.d.ts +3 -1
  47. package/package.json +7 -7
  48. package/lib/cjs/config/defaults/DefaultCommonConfigurationParams.js +0 -123
  49. package/lib/cjs/config/defaults/DefaultRemoteConfigurationParams.js +0 -8
  50. package/lib/cjs/config/defaults/DefaultStaticConfigurationParams.js +0 -10
  51. package/lib/cjs/config/defaults/constants.js +0 -0
  52. package/lib/esm/config/defaults/DefaultCommonConfigurationParams.js +0 -120
  53. package/lib/esm/config/defaults/DefaultRemoteConfigurationParams.js +0 -5
  54. package/lib/esm/config/defaults/DefaultStaticConfigurationParams.js +0 -7
  55. package/lib/esm/config/defaults/constants.js +0 -0
  56. package/lib/types/config/defaults/DefaultCommonConfigurationParams.d.ts +0 -2
  57. package/lib/types/config/defaults/DefaultRemoteConfigurationParams.d.ts +0 -2
  58. package/lib/types/config/defaults/DefaultStaticConfigurationParams.d.ts +0 -2
  59. package/lib/types/config/defaults/constants.d.ts +0 -0
  60. package/lib/types/config/params/InitializeConfigurationParams.d.ts +0 -3
  61. /package/lib/cjs/config/params/{InitializeConfigurationParams.js → RemoteConfigurationParamsOnly.js} +0 -0
  62. /package/lib/esm/config/params/{InitializeConfigurationParams.js → RemoteConfigurationParamsOnly.js} +0 -0
@@ -15,20 +15,21 @@ exports.ConfigurationBase = void 0;
15
15
  var defaults_1 = require("./defaults");
16
16
  var logger_1 = require("../logger");
17
17
  var utils_1 = require("../utils");
18
+ var remote_config_1 = require("./remote_config");
18
19
  var ConfigurationBase = /** @class */ (function () {
19
20
  function ConfigurationBase(params, defaultParams) {
20
21
  this.defaultConfigParams = __assign(__assign({}, defaults_1.DEFAULT_CONFIGURATION_PARAMS), defaultParams);
21
- this.activeConfigParams = this.initialize(params, this.defaultConfigParams);
22
+ this.activeConfigParams = this.createActiveConfiguration(params, this.defaultConfigParams);
22
23
  this.staticConfigParams = params;
23
- this.internalLogger = this.createInternalLogger(this.activeConfigParams.px_logger_severity);
24
24
  }
25
- ConfigurationBase.prototype.initialize = function (params, defaultParams) {
25
+ ConfigurationBase.prototype.createActiveConfiguration = function (params, defaultParams) {
26
26
  var _this = this;
27
27
  this.throwIfMissingRequiredField(params);
28
28
  var config = {};
29
29
  Object.keys(defaultParams).forEach(function (k) {
30
30
  config[k] = _this.getValidConfigValue(params, defaultParams, k);
31
31
  });
32
+ this.internalLogger = this.createInternalLogger(config.px_logger_severity);
32
33
  return config;
33
34
  };
34
35
  ConfigurationBase.prototype.throwIfMissingRequiredField = function (params) {
@@ -78,7 +79,8 @@ var ConfigurationBase = /** @class */ (function () {
78
79
  };
79
80
  ConfigurationBase.prototype.addRemoteConfig = function (remoteConfigParams) {
80
81
  this.remoteConfigParams = remoteConfigParams;
81
- this.activeConfigParams = this.initialize(__assign(__assign({}, this.staticConfigParams), remoteConfigParams), this.defaultConfigParams);
82
+ var mergedParams = __assign(__assign({}, this.staticConfigParams), remote_config_1.RemoteConfigUtils.prepareRemoteConfigParams(remoteConfigParams, this.logger));
83
+ this.activeConfigParams = this.createActiveConfiguration(mergedParams, this.defaultConfigParams);
82
84
  };
83
85
  ConfigurationBase.prototype.getActiveConfig = function () {
84
86
  return Object.assign({}, this.activeConfigParams);
@@ -48,6 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
50
  exports.ConfigurationBuilderBase = void 0;
51
+ var remote_config_1 = require("./remote_config");
51
52
  var ConfigurationBuilderBase = /** @class */ (function () {
52
53
  function ConfigurationBuilderBase(base64Utils) {
53
54
  this.base64Utils = base64Utils;
@@ -88,12 +89,16 @@ var ConfigurationBuilderBase = /** @class */ (function () {
88
89
  case 2:
89
90
  remoteConfigData = _a.sent();
90
91
  if (!remoteConfigData) {
91
- staticConfig.logger.debug('unable to load remote config from storage');
92
+ staticConfig.logger.debug('unable to load remote config from storage', {
93
+ error_type: remote_config_1.READ_REMOTE_CONFIG_ERROR_NAME,
94
+ });
92
95
  return [2 /*return*/, null];
93
96
  }
94
97
  configValue = remoteConfigData.configValue, id = remoteConfigData.id, version = remoteConfigData.version;
95
98
  if (!this.isValidRemoteConfigId(staticConfig.remoteConfigAuthToken, id)) {
96
- staticConfig.logger.debug("remote config ID in auth token does not match ID found in storage ".concat(id));
99
+ staticConfig.logger.debug("remote config ID in auth token does not match ID found in storage ".concat(id), {
100
+ error_type: remote_config_1.READ_REMOTE_CONFIG_ERROR_NAME,
101
+ });
97
102
  return [2 /*return*/, null];
98
103
  }
99
104
  if (!configValue.px_remote_config_enabled) {
@@ -1,18 +1,136 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.DEFAULT_CONFIGURATION_PARAMS = void 0;
15
- var DefaultStaticConfigurationParams_1 = require("./DefaultStaticConfigurationParams");
16
- var DefaultRemoteConfigurationParams_1 = require("./DefaultRemoteConfigurationParams");
17
- var DefaultCommonConfigurationParams_1 = require("./DefaultCommonConfigurationParams");
18
- exports.DEFAULT_CONFIGURATION_PARAMS = __assign(__assign(__assign({}, DefaultStaticConfigurationParams_1.DEFAULT_STATIC_CONFIGURATION_PARAMS), DefaultRemoteConfigurationParams_1.DEFAULT_REMOTE_CONFIGURATION_PARAMS), DefaultCommonConfigurationParams_1.DEFAULT_COMMON_CONFIGURATION_PARAMS);
4
+ var logger_1 = require("../../logger");
5
+ var utils_1 = require("../../utils");
6
+ var products_1 = require("../../products");
7
+ exports.DEFAULT_CONFIGURATION_PARAMS = {
8
+ px_app_id: '',
9
+ px_auth_token: '',
10
+ px_cookie_secret: '',
11
+ px_logger_auth_token: '',
12
+ px_remote_config_auth_token: '',
13
+ px_remote_config_enabled: true,
14
+ px_remote_config_id: '',
15
+ px_remote_config_version: 0,
16
+ px_filter_by_route_regex: [],
17
+ px_monitored_routes_regex: [],
18
+ px_enforced_routes_regex: [],
19
+ px_graphql_routes_regex: [],
20
+ px_sensitive_routes_regex: [],
21
+ px_s2s_timeout: 1000,
22
+ px_blocking_score: 100,
23
+ px_user_agent_max_length: 8528,
24
+ px_risk_cookie_max_length: 2048,
25
+ px_risk_cookie_min_iterations: 500,
26
+ px_risk_cookie_max_iterations: 5000,
27
+ px_logger_severity: logger_1.LoggerSeverity.ERROR,
28
+ px_ip_headers: [],
29
+ px_module_enabled: true,
30
+ px_module_mode: utils_1.ModuleMode.MONITOR,
31
+ px_additional_activity_handler: null,
32
+ px_advanced_blocking_response_enabled: true,
33
+ px_max_activity_batch_size: 0,
34
+ px_batch_activities_timeout_ms: 1000,
35
+ px_bypass_monitor_header: 'x-px-block',
36
+ px_enforced_routes: [],
37
+ px_first_party_enabled: true,
38
+ px_custom_first_party_prefix: '',
39
+ px_custom_first_party_sensor_endpoint: '',
40
+ px_custom_first_party_xhr_endpoint: '',
41
+ px_custom_first_party_captcha_endpoint: '',
42
+ px_first_party_timeout_ms: 4000,
43
+ px_backend_url: '',
44
+ px_backend_collector_url: '',
45
+ px_backend_captcha_url: 'https://captcha.px-cdn.net',
46
+ px_backend_client_url: 'https://client.perimeterx.net',
47
+ px_login_credentials_extraction_enabled: false,
48
+ px_login_credentials_extraction: [],
49
+ px_credentials_intelligence_version: products_1.CredentialIntelligenceVersion.BOTH,
50
+ px_compromised_credentials_header: products_1.DEFAULT_COMPROMISED_CREDENTIALS_HEADER_NAME,
51
+ px_send_raw_username_on_additional_s2s_activity: false,
52
+ px_automatic_additional_s2s_activity_enabled: true,
53
+ px_additional_s2s_activity_header_enabled: false,
54
+ px_login_successful_reporting_method: products_1.LoginSuccessfulReportingMethod.STATUS,
55
+ px_login_successful_body_regex: '',
56
+ px_login_successful_header_name: '',
57
+ px_login_successful_header_value: '',
58
+ px_login_successful_status: [200],
59
+ px_login_successful_custom_callback: null,
60
+ px_monitored_routes: [],
61
+ px_sensitive_headers: ['cookie', 'cookies'],
62
+ px_sensitive_routes: [],
63
+ px_filter_by_extension: [
64
+ '.css',
65
+ '.bmp',
66
+ '.tif',
67
+ '.ttf',
68
+ '.docx',
69
+ '.woff2',
70
+ '.js',
71
+ '.pict',
72
+ '.tiff',
73
+ '.eot',
74
+ '.xlsx',
75
+ '.jpg',
76
+ '.csv',
77
+ '.eps',
78
+ '.woff',
79
+ '.xls',
80
+ '.jpeg',
81
+ '.doc',
82
+ '.ejs',
83
+ '.otf',
84
+ '.pptx',
85
+ '.gif',
86
+ '.pdf',
87
+ '.swf',
88
+ '.svg',
89
+ '.ps',
90
+ '.ico',
91
+ '.pls',
92
+ '.midi',
93
+ '.svgz',
94
+ '.class',
95
+ '.png',
96
+ '.ppt',
97
+ '.mid',
98
+ '.webp',
99
+ '.jar',
100
+ '.json',
101
+ '.xml',
102
+ ],
103
+ px_filter_by_http_method: [],
104
+ px_filter_by_ip: [],
105
+ px_filter_by_route: [],
106
+ px_filter_by_user_agent: [],
107
+ px_css_ref: '',
108
+ px_js_ref: '',
109
+ px_custom_cookie_header: 'x-px-cookies',
110
+ px_custom_logo: '',
111
+ px_graphql_enabled: true,
112
+ px_graphql_routes: ['/graphql'],
113
+ px_graphql_keywords: [],
114
+ px_sensitive_graphql_operation_names: [],
115
+ px_sensitive_graphql_operation_types: [],
116
+ px_enrich_custom_parameters: null,
117
+ px_jwt_cookie_name: '',
118
+ px_jwt_cookie_user_id_field_name: '',
119
+ px_jwt_cookie_additional_field_names: [],
120
+ px_jwt_header_name: '',
121
+ px_jwt_header_user_id_field_name: '',
122
+ px_jwt_header_additional_field_names: [],
123
+ px_cors_support_enabled: false,
124
+ px_cors_custom_preflight_handler: null,
125
+ px_cors_preflight_request_filter_enabled: false,
126
+ px_cors_create_custom_block_response_headers: null,
127
+ px_remote_config_max_fetch_attempts: 5,
128
+ px_remote_config_retry_interval_ms: 1000,
129
+ px_url_decode_reserved_characters: false,
130
+ px_secured_pxhd_enabled: false,
131
+ px_custom_is_sensitive_request: null,
132
+ px_custom_is_monitored_request: null,
133
+ px_custom_is_enforced_request: null,
134
+ px_custom_is_filtered_request: null,
135
+ px_extract_graphql_keywords: null,
136
+ };
@@ -15,6 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./DefaultConfigurationParams"), exports);
18
- __exportStar(require("./DefaultRemoteConfigurationParams"), exports);
19
- __exportStar(require("./DefaultStaticConfigurationParams"), exports);
20
- __exportStar(require("./DefaultCommonConfigurationParams"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -15,7 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./CommonConfigurationParams"), exports);
18
- __exportStar(require("./RemoteConfigurationParams"), exports);
18
+ __exportStar(require("./RemoteConfigurationParamsOnly"), exports);
19
+ __exportStar(require("./StaticConfigurationParamsOnly"), exports);
19
20
  __exportStar(require("./StaticConfigurationParams"), exports);
21
+ __exportStar(require("./RemoteConfigurationParams"), exports);
20
22
  __exportStar(require("./ConfigurationParams"), exports);
21
- __exportStar(require("./InitializeConfigurationParams"), exports);
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.RemoteConfigUtils = void 0;
4
13
  var http_1 = require("../../http");
@@ -11,4 +20,20 @@ var RemoteConfigUtils;
11
20
  request.headers.get(utils_1.PUSH_DATA_FEATURE_HEADER_NAME) === constants_1.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
12
21
  !!request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
13
22
  };
23
+ RemoteConfigUtils.prepareRemoteConfigParams = function (remoteConfigParams, logger) {
24
+ var remoteConfig = Object.assign({}, remoteConfigParams);
25
+ // Remote config receives strings and regexes in separate fields (px_sensitive_routes, px_sensitive_routes_regex)
26
+ // Before initializing a new active configuration, we merge the two into the more generic field (px_sensitive_routes)
27
+ constants_1.CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG.forEach(function (k) {
28
+ if (remoteConfig[k] || remoteConfig["".concat(k, "_regex")]) {
29
+ remoteConfig[k] = RemoteConfigUtils.mergeStringRegexConfigurationValues(remoteConfig[k], remoteConfig["".concat(k, "_regex")], logger);
30
+ delete remoteConfig["".concat(k, "_regex")];
31
+ }
32
+ });
33
+ return remoteConfig;
34
+ };
35
+ RemoteConfigUtils.mergeStringRegexConfigurationValues = function (stringFields, regexFields, logger) {
36
+ var merged = __spreadArray(__spreadArray([], (stringFields || []), true), (regexFields || []).map(function (regexString) { return (0, utils_1.convertRegexStringToRegex)(regexString, logger); }), true);
37
+ return merged.filter(Boolean);
38
+ };
14
39
  })(RemoteConfigUtils || (exports.RemoteConfigUtils = RemoteConfigUtils = {}));
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WRITE_REMOTE_CONFIG_ERROR_NAME = exports.REMOTE_CONFIG_ENDPOINT = exports.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME = void 0;
3
+ exports.CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG = exports.READ_REMOTE_CONFIG_ERROR_NAME = exports.WRITE_REMOTE_CONFIG_ERROR_NAME = exports.REMOTE_CONFIG_ENDPOINT = exports.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME = void 0;
4
4
  exports.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME = 'enforcer_config';
5
5
  exports.REMOTE_CONFIG_ENDPOINT = '/config/';
6
6
  exports.WRITE_REMOTE_CONFIG_ERROR_NAME = 'write_remote_config';
7
+ exports.READ_REMOTE_CONFIG_ERROR_NAME = 'read_remote_config';
8
+ exports.CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG = [
9
+ 'px_sensitive_routes',
10
+ 'px_monitored_routes',
11
+ 'px_enforced_routes',
12
+ 'px_filter_by_route',
13
+ 'px_graphql_routes',
14
+ ];
@@ -201,8 +201,9 @@ var DefaultGraphQLParser = /** @class */ (function () {
201
201
  return /^\s*{/.test(query);
202
202
  };
203
203
  DefaultGraphQLParser.prototype.getOperationName = function (operationNameToTypeMap, operation) {
204
+ var _a;
204
205
  return (operation.operationName ||
205
- (Object.keys(operationNameToTypeMap).length === 1 ? Object.keys(operationNameToTypeMap)[0] : undefined));
206
+ (Object.keys(operationNameToTypeMap).length === 1 ? (_a = Object.keys(operationNameToTypeMap)) === null || _a === void 0 ? void 0 : _a[0] : undefined));
206
207
  };
207
208
  DefaultGraphQLParser.prototype.getQueryKeywords = function (query, context) {
208
209
  var _a;
@@ -272,7 +273,10 @@ var DefaultGraphQLParser = /** @class */ (function () {
272
273
  return (this.config.sensitiveGraphqlOperationTypes.some(function (type) { return type === operationType; }) ||
273
274
  this.config.sensitiveGraphqlOperationNames.some(function (name) {
274
275
  var pattern = _this.toGlobalRegExp(name);
275
- return pattern.test(operationName) || (keywords === null || keywords === void 0 ? void 0 : keywords.some(function (kw) { return pattern.test(kw); }));
276
+ if (!pattern) {
277
+ return false;
278
+ }
279
+ return !!(operationName === null || operationName === void 0 ? void 0 : operationName.match(pattern)) || (keywords === null || keywords === void 0 ? void 0 : keywords.some(function (kw) { return !!kw.match(pattern); }));
276
280
  }));
277
281
  };
278
282
  DefaultGraphQLParser.prototype.extractGraphQLVariableNames = function (variables) {
@@ -42,10 +42,11 @@ var BodyLoginSuccessfulParser = /** @class */ (function () {
42
42
  this.bodyRegex = new RegExp(regex);
43
43
  }
44
44
  BodyLoginSuccessfulParser.prototype.isLoginSuccessful = function (response) {
45
+ var _a, _b;
45
46
  return __awaiter(this, void 0, void 0, function () {
46
- return __generator(this, function (_a) {
47
+ return __generator(this, function (_c) {
47
48
  // TODO: Possibly add IBody methods to IOutgoingResponse interface?
48
- return [2 /*return*/, this.bodyRegex.test(response.body)];
49
+ return [2 /*return*/, !!((_b = (_a = response.body) === null || _a === void 0 ? void 0 : _a.match) === null || _b === void 0 ? void 0 : _b.call(_a, this.bodyRegex))];
49
50
  });
50
51
  });
51
52
  };
@@ -8,7 +8,7 @@ var RegexPathEndpointMatcher = /** @class */ (function () {
8
8
  }
9
9
  RegexPathEndpointMatcher.prototype.matches = function (_a) {
10
10
  var method = _a.method, url = _a.url;
11
- return method === this.method && this.pathnameRegex.test(url.pathname);
11
+ return method === this.method && !!url.pathname.match(this.pathnameRegex);
12
12
  };
13
13
  return RegexPathEndpointMatcher;
14
14
  }());
@@ -143,9 +143,9 @@ var DefaultTelemetry = /** @class */ (function () {
143
143
  'px_remote_config_auth_token',
144
144
  ];
145
145
  var telemetryConfig = {
146
- active_config: (0, utils_1.removeSensitiveFields)(this.config.getActiveConfig(), SENSITIVE_CONFIG_FIELDS),
147
- static_config: (0, utils_1.removeSensitiveFields)(this.config.getStaticConfig(), SENSITIVE_CONFIG_FIELDS),
148
- remote_config: (0, utils_1.removeSensitiveFields)(this.config.getRemoteConfig(), SENSITIVE_CONFIG_FIELDS),
146
+ active_config: (0, utils_1.redactSensitiveFields)(this.config.getActiveConfig(), SENSITIVE_CONFIG_FIELDS),
147
+ static_config: (0, utils_1.redactSensitiveFields)(this.config.getStaticConfig(), SENSITIVE_CONFIG_FIELDS),
148
+ remote_config: (0, utils_1.redactSensitiveFields)(this.config.getRemoteConfig(), SENSITIVE_CONFIG_FIELDS),
149
149
  };
150
150
  var activity = {
151
151
  type: activities_1.ActivityType.ENFORCER_TELEMETRY,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CORE_MODULE_VERSION = exports.URL_REGEX = exports.EMAIL_ADDRESS_REGEX = exports.PUSH_DATA_FEATURE_HEADER_NAME = exports.PUSH_DATA_HMAC_HEADER_NAME = exports.X_PX_BYPASS_REASON_HEADER_NAME = exports.X_PX_ORIGINAL_TOKEN_HEADER_NAME = exports.X_PX_AUTHORIZATION_HEADER_NAME = exports.BYPASS_MONITOR_HEADER_VALUE = exports.CD_PXVID_COOKIE_NAME = exports.PXDE_COOKIE_NAME = exports.PXHD_COOKIE_NAME = exports.PXVID_COOKIE_NAME = void 0;
3
+ exports.CORE_MODULE_VERSION = exports.REGEX_STRUCTURE = exports.URL_REGEX = exports.EMAIL_ADDRESS_REGEX = exports.PUSH_DATA_FEATURE_HEADER_NAME = exports.PUSH_DATA_HMAC_HEADER_NAME = exports.X_PX_BYPASS_REASON_HEADER_NAME = exports.X_PX_ORIGINAL_TOKEN_HEADER_NAME = exports.X_PX_AUTHORIZATION_HEADER_NAME = exports.BYPASS_MONITOR_HEADER_VALUE = exports.CD_PXVID_COOKIE_NAME = exports.PXDE_COOKIE_NAME = exports.PXHD_COOKIE_NAME = exports.PXVID_COOKIE_NAME = void 0;
4
4
  exports.PXVID_COOKIE_NAME = '_pxvid';
5
5
  exports.PXHD_COOKIE_NAME = '_pxhd';
6
6
  exports.PXDE_COOKIE_NAME = '_pxde';
@@ -13,4 +13,5 @@ exports.PUSH_DATA_HMAC_HEADER_NAME = 'x-px-pushdata';
13
13
  exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
14
14
  exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
15
15
  exports.URL_REGEX = /^(https?\:)\/\/(([^@\s:]+):?([^@\s]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
16
- exports.CORE_MODULE_VERSION = 'JS Core 0.20.0';
16
+ exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
17
+ exports.CORE_MODULE_VERSION = 'JS Core 0.21.0';
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.telemetryConfigReplacer = exports.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.transferExistingProperties = exports.isRouteMatch = exports.isRouteInPatterns = exports.removeSensitiveHeaders = exports.removeSensitiveFields = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
39
+ exports.telemetryConfigReplacer = exports.convertRegexStringToRegex = exports.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.transferExistingProperties = exports.isRouteMatch = exports.isRouteInPatterns = exports.removeSensitiveHeaders = exports.redactSensitiveFields = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
40
40
  var http_1 = require("../http");
41
41
  var error_1 = require("./error");
42
42
  var constants_1 = require("./constants");
@@ -77,14 +77,22 @@ var getExtension = function (route) {
77
77
  return endOfPath.substring(extensionIndex);
78
78
  };
79
79
  exports.getExtension = getExtension;
80
- var removeSensitiveFields = function (object, sensitiveFields) {
80
+ var redactSensitiveFields = function (object, sensitiveFields) {
81
+ var NUMBER_OF_TRAILING_CHARS_TO_EXPOSE = 5;
82
+ var SENSITIVE_VALUE_MINIMUM_LENGTH_TO_EXPOSE_TRAILING_CHARS = NUMBER_OF_TRAILING_CHARS_TO_EXPOSE * 10;
81
83
  var newObj = Object.assign({}, object);
82
84
  sensitiveFields.forEach(function (fieldName) {
83
- delete newObj[fieldName];
85
+ var sensitiveValue = object[fieldName];
86
+ if (!sensitiveValue) {
87
+ return;
88
+ }
89
+ var trailingCharsExposed = sensitiveValue.length >= SENSITIVE_VALUE_MINIMUM_LENGTH_TO_EXPOSE_TRAILING_CHARS;
90
+ var trailingChars = sensitiveValue.substring(sensitiveValue.length - (trailingCharsExposed ? NUMBER_OF_TRAILING_CHARS_TO_EXPOSE : 0));
91
+ newObj[fieldName] = "***REDACTED***".concat(trailingChars);
84
92
  });
85
93
  return newObj;
86
94
  };
87
- exports.removeSensitiveFields = removeSensitiveFields;
95
+ exports.redactSensitiveFields = redactSensitiveFields;
88
96
  var removeSensitiveHeaders = function (headers, sensitiveHeaderNames) {
89
97
  var ret = (0, http_1.toMutableHeaders)(headers);
90
98
  sensitiveHeaderNames.forEach(function (name) {
@@ -101,7 +109,7 @@ var isRouteMatch = function (route, pattern) {
101
109
  if (!route || !pattern) {
102
110
  return false;
103
111
  }
104
- if (pattern instanceof RegExp && pattern.test(route)) {
112
+ if (pattern instanceof RegExp && !!route.match(pattern)) {
105
113
  return true;
106
114
  }
107
115
  if (typeof pattern === 'string' && route.startsWith(pattern)) {
@@ -184,6 +192,27 @@ var algoToCryptoString = function (algo) {
184
192
  }
185
193
  };
186
194
  exports.algoToCryptoString = algoToCryptoString;
195
+ var convertRegexStringToRegex = function (regexString, logger) {
196
+ if (!regexString) {
197
+ logger === null || logger === void 0 ? void 0 : logger.debug('regex string cannot be empty or null');
198
+ return null;
199
+ }
200
+ var match = regexString.match(constants_1.REGEX_STRUCTURE);
201
+ if (!match) {
202
+ logger === null || logger === void 0 ? void 0 : logger.debug("invalid regex string: '".concat(regexString, "'. The string should be in the format ").concat(constants_1.REGEX_STRUCTURE.source));
203
+ return null;
204
+ }
205
+ var pattern = match[1];
206
+ var flags = match[2];
207
+ try {
208
+ return new RegExp(pattern, flags);
209
+ }
210
+ catch (e) {
211
+ logger === null || logger === void 0 ? void 0 : logger.debug("unable to parse string regex with pattern ".concat(pattern, ", flags ").concat(flags, ": ").concat(e));
212
+ return null;
213
+ }
214
+ };
215
+ exports.convertRegexStringToRegex = convertRegexStringToRegex;
187
216
  // Hash based on https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
188
217
  var toHash = function (string) {
189
218
  var hash = 0;
@@ -1,6 +1,7 @@
1
1
  import { DEFAULT_CONFIGURATION_PARAMS } from './defaults';
2
2
  import { LoggerSeverity, DefaultLogger } from '../logger';
3
3
  import { ModuleMode, getScoreApiDomain, getCollectorDomain, isValidEnumValue, EnforcerError, CORE_MODULE_VERSION, } from '../utils';
4
+ import { RemoteConfigUtils } from './remote_config';
4
5
  export class ConfigurationBase {
5
6
  activeConfigParams;
6
7
  staticConfigParams;
@@ -9,16 +10,16 @@ export class ConfigurationBase {
9
10
  internalLogger;
10
11
  constructor(params, defaultParams) {
11
12
  this.defaultConfigParams = { ...DEFAULT_CONFIGURATION_PARAMS, ...defaultParams };
12
- this.activeConfigParams = this.initialize(params, this.defaultConfigParams);
13
+ this.activeConfigParams = this.createActiveConfiguration(params, this.defaultConfigParams);
13
14
  this.staticConfigParams = params;
14
- this.internalLogger = this.createInternalLogger(this.activeConfigParams.px_logger_severity);
15
15
  }
16
- initialize(params, defaultParams) {
16
+ createActiveConfiguration(params, defaultParams) {
17
17
  this.throwIfMissingRequiredField(params);
18
18
  const config = {};
19
19
  Object.keys(defaultParams).forEach((k) => {
20
20
  config[k] = this.getValidConfigValue(params, defaultParams, k);
21
21
  });
22
+ this.internalLogger = this.createInternalLogger(config.px_logger_severity);
22
23
  return config;
23
24
  }
24
25
  throwIfMissingRequiredField(params) {
@@ -68,7 +69,11 @@ export class ConfigurationBase {
68
69
  }
69
70
  addRemoteConfig(remoteConfigParams) {
70
71
  this.remoteConfigParams = remoteConfigParams;
71
- this.activeConfigParams = this.initialize({ ...this.staticConfigParams, ...remoteConfigParams }, this.defaultConfigParams);
72
+ const mergedParams = {
73
+ ...this.staticConfigParams,
74
+ ...RemoteConfigUtils.prepareRemoteConfigParams(remoteConfigParams, this.logger),
75
+ };
76
+ this.activeConfigParams = this.createActiveConfiguration(mergedParams, this.defaultConfigParams);
72
77
  }
73
78
  getActiveConfig() {
74
79
  return Object.assign({}, this.activeConfigParams);
@@ -1,3 +1,4 @@
1
+ import { READ_REMOTE_CONFIG_ERROR_NAME } from './remote_config';
1
2
  export class ConfigurationBuilderBase {
2
3
  base64Utils;
3
4
  constructor(base64Utils) {
@@ -20,12 +21,16 @@ export class ConfigurationBuilderBase {
20
21
  const storageClient = await this.createRemoteConfigStorageClient(staticConfig);
21
22
  const remoteConfigData = await storageClient?.load();
22
23
  if (!remoteConfigData) {
23
- staticConfig.logger.debug('unable to load remote config from storage');
24
+ staticConfig.logger.debug('unable to load remote config from storage', {
25
+ error_type: READ_REMOTE_CONFIG_ERROR_NAME,
26
+ });
24
27
  return null;
25
28
  }
26
29
  const { configValue, id, version } = remoteConfigData;
27
30
  if (!this.isValidRemoteConfigId(staticConfig.remoteConfigAuthToken, id)) {
28
- staticConfig.logger.debug(`remote config ID in auth token does not match ID found in storage ${id}`);
31
+ staticConfig.logger.debug(`remote config ID in auth token does not match ID found in storage ${id}`, {
32
+ error_type: READ_REMOTE_CONFIG_ERROR_NAME,
33
+ });
29
34
  return null;
30
35
  }
31
36
  if (!configValue.px_remote_config_enabled) {
@@ -1,8 +1,133 @@
1
- import { DEFAULT_STATIC_CONFIGURATION_PARAMS } from './DefaultStaticConfigurationParams';
2
- import { DEFAULT_REMOTE_CONFIGURATION_PARAMS } from './DefaultRemoteConfigurationParams';
3
- import { DEFAULT_COMMON_CONFIGURATION_PARAMS } from './DefaultCommonConfigurationParams';
1
+ import { LoggerSeverity } from '../../logger';
2
+ import { ModuleMode } from '../../utils';
3
+ import { CredentialIntelligenceVersion, DEFAULT_COMPROMISED_CREDENTIALS_HEADER_NAME, LoginSuccessfulReportingMethod, } from '../../products';
4
4
  export const DEFAULT_CONFIGURATION_PARAMS = {
5
- ...DEFAULT_STATIC_CONFIGURATION_PARAMS,
6
- ...DEFAULT_REMOTE_CONFIGURATION_PARAMS,
7
- ...DEFAULT_COMMON_CONFIGURATION_PARAMS,
5
+ px_app_id: '',
6
+ px_auth_token: '',
7
+ px_cookie_secret: '',
8
+ px_logger_auth_token: '',
9
+ px_remote_config_auth_token: '',
10
+ px_remote_config_enabled: true,
11
+ px_remote_config_id: '',
12
+ px_remote_config_version: 0,
13
+ px_filter_by_route_regex: [],
14
+ px_monitored_routes_regex: [],
15
+ px_enforced_routes_regex: [],
16
+ px_graphql_routes_regex: [],
17
+ px_sensitive_routes_regex: [],
18
+ px_s2s_timeout: 1000,
19
+ px_blocking_score: 100,
20
+ px_user_agent_max_length: 8528,
21
+ px_risk_cookie_max_length: 2048,
22
+ px_risk_cookie_min_iterations: 500,
23
+ px_risk_cookie_max_iterations: 5000,
24
+ px_logger_severity: LoggerSeverity.ERROR,
25
+ px_ip_headers: [],
26
+ px_module_enabled: true,
27
+ px_module_mode: ModuleMode.MONITOR,
28
+ px_additional_activity_handler: null,
29
+ px_advanced_blocking_response_enabled: true,
30
+ px_max_activity_batch_size: 0,
31
+ px_batch_activities_timeout_ms: 1000,
32
+ px_bypass_monitor_header: 'x-px-block',
33
+ px_enforced_routes: [],
34
+ px_first_party_enabled: true,
35
+ px_custom_first_party_prefix: '',
36
+ px_custom_first_party_sensor_endpoint: '',
37
+ px_custom_first_party_xhr_endpoint: '',
38
+ px_custom_first_party_captcha_endpoint: '',
39
+ px_first_party_timeout_ms: 4000,
40
+ px_backend_url: '',
41
+ px_backend_collector_url: '',
42
+ px_backend_captcha_url: 'https://captcha.px-cdn.net',
43
+ px_backend_client_url: 'https://client.perimeterx.net',
44
+ px_login_credentials_extraction_enabled: false,
45
+ px_login_credentials_extraction: [],
46
+ px_credentials_intelligence_version: CredentialIntelligenceVersion.BOTH,
47
+ px_compromised_credentials_header: DEFAULT_COMPROMISED_CREDENTIALS_HEADER_NAME,
48
+ px_send_raw_username_on_additional_s2s_activity: false,
49
+ px_automatic_additional_s2s_activity_enabled: true,
50
+ px_additional_s2s_activity_header_enabled: false,
51
+ px_login_successful_reporting_method: LoginSuccessfulReportingMethod.STATUS,
52
+ px_login_successful_body_regex: '',
53
+ px_login_successful_header_name: '',
54
+ px_login_successful_header_value: '',
55
+ px_login_successful_status: [200],
56
+ px_login_successful_custom_callback: null,
57
+ px_monitored_routes: [],
58
+ px_sensitive_headers: ['cookie', 'cookies'],
59
+ px_sensitive_routes: [],
60
+ px_filter_by_extension: [
61
+ '.css',
62
+ '.bmp',
63
+ '.tif',
64
+ '.ttf',
65
+ '.docx',
66
+ '.woff2',
67
+ '.js',
68
+ '.pict',
69
+ '.tiff',
70
+ '.eot',
71
+ '.xlsx',
72
+ '.jpg',
73
+ '.csv',
74
+ '.eps',
75
+ '.woff',
76
+ '.xls',
77
+ '.jpeg',
78
+ '.doc',
79
+ '.ejs',
80
+ '.otf',
81
+ '.pptx',
82
+ '.gif',
83
+ '.pdf',
84
+ '.swf',
85
+ '.svg',
86
+ '.ps',
87
+ '.ico',
88
+ '.pls',
89
+ '.midi',
90
+ '.svgz',
91
+ '.class',
92
+ '.png',
93
+ '.ppt',
94
+ '.mid',
95
+ '.webp',
96
+ '.jar',
97
+ '.json',
98
+ '.xml',
99
+ ],
100
+ px_filter_by_http_method: [],
101
+ px_filter_by_ip: [],
102
+ px_filter_by_route: [],
103
+ px_filter_by_user_agent: [],
104
+ px_css_ref: '',
105
+ px_js_ref: '',
106
+ px_custom_cookie_header: 'x-px-cookies',
107
+ px_custom_logo: '',
108
+ px_graphql_enabled: true,
109
+ px_graphql_routes: ['/graphql'],
110
+ px_graphql_keywords: [],
111
+ px_sensitive_graphql_operation_names: [],
112
+ px_sensitive_graphql_operation_types: [],
113
+ px_enrich_custom_parameters: null,
114
+ px_jwt_cookie_name: '',
115
+ px_jwt_cookie_user_id_field_name: '',
116
+ px_jwt_cookie_additional_field_names: [],
117
+ px_jwt_header_name: '',
118
+ px_jwt_header_user_id_field_name: '',
119
+ px_jwt_header_additional_field_names: [],
120
+ px_cors_support_enabled: false,
121
+ px_cors_custom_preflight_handler: null,
122
+ px_cors_preflight_request_filter_enabled: false,
123
+ px_cors_create_custom_block_response_headers: null,
124
+ px_remote_config_max_fetch_attempts: 5,
125
+ px_remote_config_retry_interval_ms: 1000,
126
+ px_url_decode_reserved_characters: false,
127
+ px_secured_pxhd_enabled: false,
128
+ px_custom_is_sensitive_request: null,
129
+ px_custom_is_monitored_request: null,
130
+ px_custom_is_enforced_request: null,
131
+ px_custom_is_filtered_request: null,
132
+ px_extract_graphql_keywords: null,
8
133
  };
@@ -1,4 +1 @@
1
1
  export * from './DefaultConfigurationParams';
2
- export * from './DefaultRemoteConfigurationParams';
3
- export * from './DefaultStaticConfigurationParams';
4
- export * from './DefaultCommonConfigurationParams';