perimeterx-js-core 0.20.1 → 0.21.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.
Files changed (63) 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/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +4 -2
  10. package/lib/cjs/utils/constants.js +3 -2
  11. package/lib/cjs/utils/utils.js +23 -2
  12. package/lib/esm/config/ConfigurationBase.js +9 -4
  13. package/lib/esm/config/ConfigurationBuilderBase.js +7 -2
  14. package/lib/esm/config/defaults/DefaultConfigurationParams.js +131 -6
  15. package/lib/esm/config/defaults/index.js +0 -3
  16. package/lib/esm/config/params/StaticConfigurationParamsOnly.js +1 -0
  17. package/lib/esm/config/params/index.js +3 -2
  18. package/lib/esm/config/remote_config/RemoteConfigUtils.js +21 -2
  19. package/lib/esm/config/remote_config/constants.js +8 -0
  20. package/lib/esm/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -2
  21. package/lib/esm/utils/constants.js +2 -1
  22. package/lib/esm/utils/utils.js +22 -2
  23. package/lib/types/activities/utils.d.ts +30 -0
  24. package/lib/types/blocker/utils.d.ts +3 -0
  25. package/lib/types/config/ConfigurationBase.d.ts +10 -10
  26. package/lib/types/config/ConfigurationBuilderBase.d.ts +4 -4
  27. package/lib/types/config/IConfiguration.d.ts +5 -5
  28. package/lib/types/config/defaults/DefaultConfigurationParams.d.ts +1 -1
  29. package/lib/types/config/defaults/index.d.ts +0 -3
  30. package/lib/types/config/params/CommonConfigurationParams.d.ts +1 -2
  31. package/lib/types/config/params/ConfigurationParams.d.ts +3 -3
  32. package/lib/types/config/params/RemoteConfigurationParams.d.ts +3 -5
  33. package/lib/types/config/params/RemoteConfigurationParamsOnly.d.ts +10 -0
  34. package/lib/types/config/params/StaticConfigurationParams.d.ts +3 -7
  35. package/lib/types/config/params/StaticConfigurationParamsOnly.d.ts +7 -0
  36. package/lib/types/config/params/index.d.ts +3 -2
  37. package/lib/types/config/remote_config/RemoteConfigUtils.d.ts +4 -0
  38. package/lib/types/config/remote_config/constants.d.ts +2 -0
  39. package/lib/types/config/remote_config/model/RemoteConfigData.d.ts +2 -2
  40. package/lib/types/http/interfaces/IBody.d.ts +1 -1
  41. package/lib/types/http/interfaces/IOutgoingResponse.d.ts +7 -2
  42. package/lib/types/monitored_request/MonitoredRequestUtils.d.ts +9 -0
  43. package/lib/types/pxhd/PXHDUtils.d.ts +6 -0
  44. package/lib/types/sensitive_request/SensitiveRequestUtils.d.ts +6 -0
  45. package/lib/types/telemetry/model/TelemetryActivity.d.ts +3 -3
  46. package/lib/types/utils/constants.d.ts +2 -1
  47. package/lib/types/utils/utils.d.ts +3 -1
  48. package/package.json +7 -7
  49. package/lib/cjs/config/defaults/DefaultCommonConfigurationParams.js +0 -123
  50. package/lib/cjs/config/defaults/DefaultRemoteConfigurationParams.js +0 -8
  51. package/lib/cjs/config/defaults/DefaultStaticConfigurationParams.js +0 -10
  52. package/lib/cjs/config/defaults/constants.js +0 -0
  53. package/lib/esm/config/defaults/DefaultCommonConfigurationParams.js +0 -120
  54. package/lib/esm/config/defaults/DefaultRemoteConfigurationParams.js +0 -5
  55. package/lib/esm/config/defaults/DefaultStaticConfigurationParams.js +0 -7
  56. package/lib/esm/config/defaults/constants.js +0 -0
  57. package/lib/types/config/defaults/DefaultCommonConfigurationParams.d.ts +0 -2
  58. package/lib/types/config/defaults/DefaultRemoteConfigurationParams.d.ts +0 -2
  59. package/lib/types/config/defaults/DefaultStaticConfigurationParams.d.ts +0 -2
  60. package/lib/types/config/defaults/constants.d.ts +0 -0
  61. package/lib/types/config/params/InitializeConfigurationParams.d.ts +0 -3
  62. /package/lib/cjs/config/params/{InitializeConfigurationParams.js → RemoteConfigurationParamsOnly.js} +0 -0
  63. /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
+ ];
@@ -45,8 +45,10 @@ var BodyLoginSuccessfulParser = /** @class */ (function () {
45
45
  var _a, _b;
46
46
  return __awaiter(this, void 0, void 0, function () {
47
47
  return __generator(this, function (_c) {
48
- // TODO: Possibly add IBody methods to IOutgoingResponse interface?
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))];
48
+ switch (_c.label) {
49
+ case 0: return [4 /*yield*/, response.text()];
50
+ case 1: return [2 /*return*/, !!((_b = (_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.match) === null || _b === void 0 ? void 0 : _b.call(_a, this.bodyRegex))];
51
+ }
50
52
  });
51
53
  });
52
54
  };
@@ -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.1';
16
+ exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
17
+ exports.CORE_MODULE_VERSION = 'JS Core 0.21.1';
@@ -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.redactSensitiveFields = 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");
@@ -192,6 +192,27 @@ var algoToCryptoString = function (algo) {
192
192
  }
193
193
  };
194
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;
195
216
  // Hash based on https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
196
217
  var toHash = function (string) {
197
218
  var hash = 0;
@@ -207,7 +228,7 @@ var toHash = function (string) {
207
228
  };
208
229
  var telemetryConfigReplacer = function (key, value) {
209
230
  if (value instanceof RegExp) {
210
- return '_REGEXP ' + value.toString();
231
+ return '_REGEXP ' + value.toString().replace(/\\\//g, '/');
211
232
  }
212
233
  if (value instanceof Function) {
213
234
  return '_FUNCTION_HASH' + toHash(value.toString()); // NOTE: Do not log functions
@@ -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';
@@ -1,5 +1,6 @@
1
1
  export * from './CommonConfigurationParams';
2
- export * from './RemoteConfigurationParams';
2
+ export * from './RemoteConfigurationParamsOnly';
3
+ export * from './StaticConfigurationParamsOnly';
3
4
  export * from './StaticConfigurationParams';
5
+ export * from './RemoteConfigurationParams';
4
6
  export * from './ConfigurationParams';
5
- export * from './InitializeConfigurationParams';
@@ -1,9 +1,28 @@
1
1
  import { HttpMethod } from '../../http';
2
- import { PUSH_DATA_FEATURE_HEADER_NAME, PUSH_DATA_HMAC_HEADER_NAME } from '../../utils';
3
- import { REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME } from './constants';
2
+ import { convertRegexStringToRegex, PUSH_DATA_FEATURE_HEADER_NAME, PUSH_DATA_HMAC_HEADER_NAME } from '../../utils';
3
+ import { REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME, CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG } from './constants';
4
4
  export var RemoteConfigUtils;
5
5
  (function (RemoteConfigUtils) {
6
6
  RemoteConfigUtils.isRemoteConfigUpdateRequest = (request) => request.method === HttpMethod.POST &&
7
7
  request.headers.get(PUSH_DATA_FEATURE_HEADER_NAME) === REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
8
8
  !!request.headers.get(PUSH_DATA_HMAC_HEADER_NAME);
9
+ RemoteConfigUtils.prepareRemoteConfigParams = (remoteConfigParams, logger) => {
10
+ const remoteConfig = Object.assign({}, remoteConfigParams);
11
+ // Remote config receives strings and regexes in separate fields (px_sensitive_routes, px_sensitive_routes_regex)
12
+ // Before initializing a new active configuration, we merge the two into the more generic field (px_sensitive_routes)
13
+ CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG.forEach((k) => {
14
+ if (remoteConfig[k] || remoteConfig[`${k}_regex`]) {
15
+ remoteConfig[k] = RemoteConfigUtils.mergeStringRegexConfigurationValues(remoteConfig[k], remoteConfig[`${k}_regex`], logger);
16
+ delete remoteConfig[`${k}_regex`];
17
+ }
18
+ });
19
+ return remoteConfig;
20
+ };
21
+ RemoteConfigUtils.mergeStringRegexConfigurationValues = (stringFields, regexFields, logger) => {
22
+ const merged = [
23
+ ...(stringFields || []),
24
+ ...(regexFields || []).map((regexString) => convertRegexStringToRegex(regexString, logger)),
25
+ ];
26
+ return merged.filter(Boolean);
27
+ };
9
28
  })(RemoteConfigUtils || (RemoteConfigUtils = {}));
@@ -1,3 +1,11 @@
1
1
  export const REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME = 'enforcer_config';
2
2
  export const REMOTE_CONFIG_ENDPOINT = '/config/';
3
3
  export const WRITE_REMOTE_CONFIG_ERROR_NAME = 'write_remote_config';
4
+ export const READ_REMOTE_CONFIG_ERROR_NAME = 'read_remote_config';
5
+ export const CONFIG_KEYS_WITH_REGEX_EQUIVALENT_IN_REMOTE_CONFIG = [
6
+ 'px_sensitive_routes',
7
+ 'px_monitored_routes',
8
+ 'px_enforced_routes',
9
+ 'px_filter_by_route',
10
+ 'px_graphql_routes',
11
+ ];
@@ -4,7 +4,6 @@ export class BodyLoginSuccessfulParser {
4
4
  this.bodyRegex = new RegExp(regex);
5
5
  }
6
6
  async isLoginSuccessful(response) {
7
- // TODO: Possibly add IBody methods to IOutgoingResponse interface?
8
- return !!response.body?.match?.(this.bodyRegex);
7
+ return !!(await response.text())?.match?.(this.bodyRegex);
9
8
  }
10
9
  }