perimeterx-js-core 0.13.0 → 0.15.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 (75) hide show
  1. package/lib/cjs/config/ConfigurationBase.js +35 -0
  2. package/lib/cjs/config/CustomRequestFunction.js +2 -0
  3. package/lib/cjs/config/defaults/DefaultCommonConfigurationParams.js +5 -5
  4. package/lib/cjs/config/index.js +1 -0
  5. package/lib/cjs/enforcer/EnforcerBase.js +16 -4
  6. package/lib/cjs/filter/FilterReason.js +1 -0
  7. package/lib/cjs/impl/url/UrlImpl.js +27 -7
  8. package/lib/cjs/index.js +2 -0
  9. package/lib/cjs/logger/LoggerBase.js +3 -0
  10. package/lib/cjs/monitored_request/MonitoredRequestUtils.js +123 -0
  11. package/lib/cjs/monitored_request/index.js +17 -0
  12. package/lib/cjs/phase/flow/PostEnforceFlow.js +1 -1
  13. package/lib/cjs/phase/impl/CreateBlockResponsePhase.js +1 -1
  14. package/lib/cjs/phase/impl/FilterPhase.js +20 -2
  15. package/lib/cjs/phase/impl/ModifyOutgoingResponsePhase.js +3 -2
  16. package/lib/cjs/phase/impl/SendLogsPhase.js +3 -1
  17. package/lib/cjs/products/bot_defender/BotDefender.js +31 -31
  18. package/lib/cjs/products/bot_defender/filter/DefaultBotDefenderFilter.js +103 -24
  19. package/lib/cjs/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +45 -10
  20. package/lib/cjs/products/utils/index.js +0 -1
  21. package/lib/cjs/pxhd/PXHDUtils.js +7 -6
  22. package/lib/cjs/sensitive_request/SensitiveRequestUtils.js +85 -0
  23. package/lib/cjs/sensitive_request/index.js +17 -0
  24. package/lib/cjs/utils/constants.js +2 -2
  25. package/lib/esm/config/ConfigurationBase.js +15 -0
  26. package/lib/esm/config/CustomRequestFunction.js +1 -0
  27. package/lib/esm/config/defaults/DefaultCommonConfigurationParams.js +5 -5
  28. package/lib/esm/config/index.js +1 -0
  29. package/lib/esm/enforcer/EnforcerBase.js +16 -4
  30. package/lib/esm/filter/FilterReason.js +1 -0
  31. package/lib/esm/impl/url/UrlImpl.js +26 -7
  32. package/lib/esm/index.js +2 -0
  33. package/lib/esm/logger/LoggerBase.js +3 -0
  34. package/lib/esm/monitored_request/MonitoredRequestUtils.js +43 -0
  35. package/lib/esm/monitored_request/index.js +1 -0
  36. package/lib/esm/phase/flow/PostEnforceFlow.js +1 -1
  37. package/lib/esm/phase/impl/CreateBlockResponsePhase.js +1 -1
  38. package/lib/esm/phase/impl/FilterPhase.js +6 -1
  39. package/lib/esm/phase/impl/ModifyOutgoingResponsePhase.js +4 -2
  40. package/lib/esm/phase/impl/SendLogsPhase.js +1 -0
  41. package/lib/esm/products/bot_defender/BotDefender.js +9 -14
  42. package/lib/esm/products/bot_defender/filter/DefaultBotDefenderFilter.js +22 -8
  43. package/lib/esm/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +45 -10
  44. package/lib/esm/products/utils/index.js +0 -1
  45. package/lib/esm/pxhd/PXHDUtils.js +7 -6
  46. package/lib/esm/sensitive_request/SensitiveRequestUtils.js +26 -0
  47. package/lib/esm/sensitive_request/index.js +1 -0
  48. package/lib/esm/utils/constants.js +2 -2
  49. package/lib/types/config/ConfigurationBase.d.ts +6 -0
  50. package/lib/types/config/CustomRequestFunction.d.ts +1 -0
  51. package/lib/types/config/IConfiguration.d.ts +24 -0
  52. package/lib/types/config/index.d.ts +1 -0
  53. package/lib/types/config/params/CommonConfigurationParams.d.ts +6 -5
  54. package/lib/types/enforcer/EnforcerBase.d.ts +4 -0
  55. package/lib/types/filter/FilterReason.d.ts +1 -0
  56. package/lib/types/filter/IFilter.d.ts +4 -3
  57. package/lib/types/impl/url/UrlImpl.d.ts +5 -1
  58. package/lib/types/index.d.ts +2 -0
  59. package/lib/types/logger/ILogger.d.ts +4 -0
  60. package/lib/types/logger/LoggerBase.d.ts +1 -0
  61. package/lib/types/monitored_request/MonitoredRequestUtils.d.ts +647 -0
  62. package/lib/types/monitored_request/index.d.ts +1 -0
  63. package/lib/types/phase/impl/ModifyOutgoingResponsePhase.d.ts +3 -1
  64. package/lib/types/products/bot_defender/BotDefender.d.ts +3 -5
  65. package/lib/types/products/bot_defender/filter/DefaultBotDefenderFilter.d.ts +12 -9
  66. package/lib/types/products/bot_defender/first_party/DefaultBotDefenderFirstParty.d.ts +11 -8
  67. package/lib/types/products/utils/index.d.ts +0 -1
  68. package/lib/types/pxhd/PXHDUtils.d.ts +1274 -3
  69. package/lib/types/sensitive_request/SensitiveRequestUtils.d.ts +647 -0
  70. package/lib/types/sensitive_request/index.d.ts +1 -0
  71. package/lib/types/utils/constants.d.ts +1 -1
  72. package/package.json +1 -1
  73. package/lib/cjs/products/utils/utils.js +0 -18
  74. package/lib/esm/products/utils/utils.js +0 -12
  75. package/lib/types/products/utils/utils.d.ts +0 -5
@@ -144,6 +144,13 @@ var ConfigurationBase = /** @class */ (function () {
144
144
  enumerable: false,
145
145
  configurable: true
146
146
  });
147
+ Object.defineProperty(ConfigurationBase.prototype, "customIsEnforcedRequest", {
148
+ get: function () {
149
+ return this.configParams.px_custom_is_enforced_request;
150
+ },
151
+ enumerable: false,
152
+ configurable: true
153
+ });
147
154
  Object.defineProperty(ConfigurationBase.prototype, "filteredExtensions", {
148
155
  get: function () {
149
156
  return this.configParams.px_filter_by_extension.map(function (ext) { return (ext.startsWith('.') ? ext : ".".concat(ext)); });
@@ -186,6 +193,13 @@ var ConfigurationBase = /** @class */ (function () {
186
193
  enumerable: false,
187
194
  configurable: true
188
195
  });
196
+ Object.defineProperty(ConfigurationBase.prototype, "customIsFilteredRequest", {
197
+ get: function () {
198
+ return this.configParams.px_custom_is_filtered_request;
199
+ },
200
+ enumerable: false,
201
+ configurable: true
202
+ });
189
203
  Object.defineProperty(ConfigurationBase.prototype, "customFirstPartyPrefix", {
190
204
  get: function () {
191
205
  return this.configParams.px_custom_first_party_prefix;
@@ -249,6 +263,13 @@ var ConfigurationBase = /** @class */ (function () {
249
263
  enumerable: false,
250
264
  configurable: true
251
265
  });
266
+ Object.defineProperty(ConfigurationBase.prototype, "customIsMonitoredRequest", {
267
+ get: function () {
268
+ return this.configParams.px_custom_is_monitored_request;
269
+ },
270
+ enumerable: false,
271
+ configurable: true
272
+ });
252
273
  Object.defineProperty(ConfigurationBase.prototype, "s2sTimeout", {
253
274
  get: function () {
254
275
  return this.configParams.px_s2s_timeout;
@@ -270,6 +291,13 @@ var ConfigurationBase = /** @class */ (function () {
270
291
  enumerable: false,
271
292
  configurable: true
272
293
  });
294
+ Object.defineProperty(ConfigurationBase.prototype, "customIsSensitiveRequest", {
295
+ get: function () {
296
+ return this.configParams.px_custom_is_sensitive_request;
297
+ },
298
+ enumerable: false,
299
+ configurable: true
300
+ });
273
301
  Object.defineProperty(ConfigurationBase.prototype, "advancedBlockingResponseEnabled", {
274
302
  get: function () {
275
303
  return this.configParams.px_advanced_blocking_response_enabled;
@@ -634,6 +662,13 @@ var ConfigurationBase = /** @class */ (function () {
634
662
  enumerable: false,
635
663
  configurable: true
636
664
  });
665
+ Object.defineProperty(ConfigurationBase.prototype, "securedPxhdEnabled", {
666
+ get: function () {
667
+ return this.configParams.px_secured_pxhd_enabled;
668
+ },
669
+ enumerable: false,
670
+ configurable: true
671
+ });
637
672
  return ConfigurationBase;
638
673
  }());
639
674
  exports.ConfigurationBase = ConfigurationBase;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -13,7 +13,6 @@ exports.DEFAULT_COMMON_CONFIGURATION_PARAMS = {
13
13
  px_risk_cookie_max_iterations: 5000,
14
14
  px_logger_severity: logger_1.LoggerSeverity.ERROR,
15
15
  px_ip_headers: [],
16
- px_extract_ip: null,
17
16
  px_module_enabled: true,
18
17
  px_module_mode: utils_1.ModuleMode.MONITOR,
19
18
  px_additional_activity_handler: null,
@@ -21,9 +20,6 @@ exports.DEFAULT_COMMON_CONFIGURATION_PARAMS = {
21
20
  px_max_activity_batch_size: 0,
22
21
  px_batch_activities_timeout_ms: 1000,
23
22
  px_bypass_monitor_header: '',
24
- px_csp_enabled: false,
25
- px_csp_no_updates_max_interval_minutes: 60,
26
- px_csp_policy_refresh_interval_minutes: 5,
27
23
  px_enforced_routes: [],
28
24
  px_first_party_enabled: true,
29
25
  px_custom_first_party_prefix: '',
@@ -104,7 +100,6 @@ exports.DEFAULT_COMMON_CONFIGURATION_PARAMS = {
104
100
  px_sensitive_graphql_operation_names: [],
105
101
  px_sensitive_graphql_operation_types: [],
106
102
  px_enrich_custom_parameters: null,
107
- px_proxy_url: '',
108
103
  px_jwt_cookie_name: '',
109
104
  px_jwt_cookie_user_id_field_name: '',
110
105
  px_jwt_cookie_additional_field_names: [],
@@ -118,4 +113,9 @@ exports.DEFAULT_COMMON_CONFIGURATION_PARAMS = {
118
113
  px_remote_config_max_fetch_attempts: 5,
119
114
  px_remote_config_retry_interval_ms: 1000,
120
115
  px_url_decode_reserved_characters: false,
116
+ px_secured_pxhd_enabled: false,
117
+ px_custom_is_sensitive_request: null,
118
+ px_custom_is_monitored_request: null,
119
+ px_custom_is_enforced_request: null,
120
+ px_custom_is_filtered_request: null,
121
121
  };
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./IConfiguration"), exports);
18
18
  __exportStar(require("./ConfigurationBase"), exports);
19
19
  __exportStar(require("./ConfigurationBuilderBase"), exports);
20
+ __exportStar(require("./CustomRequestFunction"), exports);
20
21
  __exportStar(require("./remote_config"), exports);
21
22
  __exportStar(require("./params"), exports);
22
23
  __exportStar(require("./defaults"), exports);
@@ -80,11 +80,23 @@ var EnforcerBase = /** @class */ (function () {
80
80
  this.config = config;
81
81
  var initializationBlock = this.getInitializationBlock(config, options);
82
82
  this.activityClient = initializationBlock.activityClient;
83
- this.filterFlow = new phase_1.FilterFlow(config, initializationBlock);
84
- this.enforceFlow = new phase_1.EnforceFlow(config, initializationBlock);
85
- this.postEnforceFlow = new phase_1.PostEnforceFlow(config, initializationBlock);
86
- this.endEnforcerFlow = new phase_1.EndEnforcerFlow(config, initializationBlock);
83
+ this.filterFlow = this.createFilterFlow(config, initializationBlock);
84
+ this.enforceFlow = this.createEnforceFlow(config, initializationBlock);
85
+ this.postEnforceFlow = this.createPostEnforceFlow(config, initializationBlock);
86
+ this.endEnforcerFlow = this.createEndEnforcerFlow(config, initializationBlock);
87
87
  }
88
+ EnforcerBase.prototype.createFilterFlow = function (config, initializationBlock) {
89
+ return new phase_1.FilterFlow(config, initializationBlock);
90
+ };
91
+ EnforcerBase.prototype.createPostEnforceFlow = function (config, initializationBlock) {
92
+ return new phase_1.PostEnforceFlow(config, initializationBlock);
93
+ };
94
+ EnforcerBase.prototype.createEnforceFlow = function (config, initializationBlock) {
95
+ return new phase_1.EnforceFlow(config, initializationBlock);
96
+ };
97
+ EnforcerBase.prototype.createEndEnforcerFlow = function (config, initializationBlock) {
98
+ return new phase_1.EndEnforcerFlow(config, initializationBlock);
99
+ };
88
100
  /**
89
101
  * The central function that triggers enforcement on the incoming request.
90
102
  * @param args - The EnforceArgs required to enforce the incoming request.
@@ -9,6 +9,7 @@ var FilterReason;
9
9
  FilterReason["HTTP_METHOD"] = "http_method";
10
10
  FilterReason["USER_AGENT"] = "user_agent";
11
11
  FilterReason["IP"] = "ip";
12
+ FilterReason["CUSTOM"] = "custom";
12
13
  FilterReason["TELEMETRY_REQUEST"] = "telemetry_request";
13
14
  FilterReason["CORS_PREFLIGHT_REQUEST"] = "cors_preflight_request";
14
15
  })(FilterReason || (exports.FilterReason = FilterReason = {}));
@@ -11,15 +11,18 @@ var UrlImpl = /** @class */ (function () {
11
11
  throw new Error("Invalid UrlImpl: ".concat(rawUrl));
12
12
  }
13
13
  this.protocol = match[1];
14
- this.hostname = match[3];
15
- this.port = match[4] || '';
16
- this.pathname = match[5] || '/';
17
- this.search = match[6] || '';
18
- this.hash = match[7] || '';
14
+ this.username = match[3] || '';
15
+ this.password = match[4] || '';
16
+ this.hostname = match[6];
17
+ this.port = match[7] || '';
18
+ this.pathname = match[8] || '/';
19
+ this.search = match[9] || '';
20
+ this.hash = match[10] || '';
21
+ this.urlUtils = new CustomImplUrlUtils_1.CustomImplUrlUtils();
19
22
  }
20
23
  Object.defineProperty(UrlImpl.prototype, "href", {
21
24
  get: function () {
22
- return "".concat(this.origin).concat(this.pathname).concat(this.search).concat(this.hash);
25
+ return "".concat(this.protocol, "//").concat(this.credentials).concat(this.host).concat(this.pathname).concat(this.search).concat(this.hash);
23
26
  },
24
27
  enumerable: false,
25
28
  configurable: true
@@ -57,7 +60,7 @@ var UrlImpl = /** @class */ (function () {
57
60
  });
58
61
  Object.defineProperty(UrlImpl.prototype, "searchParams", {
59
62
  get: function () {
60
- return new UrlSearchParamsImpl_1.UrlSearchParamsImpl(new CustomImplUrlUtils_1.CustomImplUrlUtils(), this.search);
63
+ return new UrlSearchParamsImpl_1.UrlSearchParamsImpl(this.urlUtils, this.search);
61
64
  },
62
65
  enumerable: false,
63
66
  configurable: true
@@ -69,6 +72,23 @@ var UrlImpl = /** @class */ (function () {
69
72
  };
70
73
  return PROTOCOL_TO_DEFAULT_PORT[this.protocol] === port;
71
74
  };
75
+ Object.defineProperty(UrlImpl.prototype, "credentials", {
76
+ get: function () {
77
+ if (!this.username && !this.password) {
78
+ return '';
79
+ }
80
+ var credentials = '';
81
+ if (this.username) {
82
+ credentials += this.urlUtils.encodeUriComponent(this.username);
83
+ }
84
+ if (this.password) {
85
+ credentials += ":".concat(this.urlUtils.encodeUriComponent(this.password));
86
+ }
87
+ return "".concat(credentials, "@");
88
+ },
89
+ enumerable: false,
90
+ configurable: true
91
+ });
72
92
  return UrlImpl;
73
93
  }());
74
94
  exports.UrlImpl = UrlImpl;
package/lib/cjs/index.js CHANGED
@@ -21,6 +21,8 @@ __exportStar(require("./blocker"), exports);
21
21
  __exportStar(require("./config"), exports);
22
22
  __exportStar(require("./context"), exports);
23
23
  __exportStar(require("./custom_parameters"), exports);
24
+ __exportStar(require("./sensitive_request"), exports);
25
+ __exportStar(require("./monitored_request"), exports);
24
26
  __exportStar(require("./cors"), exports);
25
27
  __exportStar(require("./enforcer"), exports);
26
28
  __exportStar(require("./filter"), exports);
@@ -54,6 +54,9 @@ var LoggerBase = /** @class */ (function () {
54
54
  var logRecord = __assign(__assign({}, metadata), { message: message, severity: loggerSeverity, messageTimestamp: Date.now() });
55
55
  this.logs.push(logRecord);
56
56
  };
57
+ LoggerBase.prototype.clearLogs = function () {
58
+ this.logs = [];
59
+ };
57
60
  return LoggerBase;
58
61
  }());
59
62
  exports.LoggerBase = LoggerBase;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.MonitoredRequestUtils = void 0;
40
+ var utils_1 = require("../utils");
41
+ var MonitoredRequestUtils;
42
+ (function (MonitoredRequestUtils) {
43
+ var _this = this;
44
+ MonitoredRequestUtils.isMonitoredRequest = function (config, context) { return __awaiter(_this, void 0, void 0, function () {
45
+ var _a, url, request, isEnforcedRequest, _b, monitoredRoute, _c, _d, monitorMode;
46
+ return __generator(this, function (_e) {
47
+ switch (_e.label) {
48
+ case 0:
49
+ _a = context.requestData, url = _a.url, request = _a.request;
50
+ _b = MonitoredRequestUtils.isEnforcedRoute(url, config.enforcedRoutes);
51
+ if (_b) return [3 /*break*/, 2];
52
+ return [4 /*yield*/, MonitoredRequestUtils.invokeCustomIsEnforcedRequest(config, request)];
53
+ case 1:
54
+ _b = (_e.sent());
55
+ _e.label = 2;
56
+ case 2:
57
+ isEnforcedRequest = _b;
58
+ _c = !isEnforcedRequest;
59
+ if (!_c) return [3 /*break*/, 5];
60
+ _d = MonitoredRequestUtils.isMonitoredRoute(url, config.monitoredRoutes);
61
+ if (_d) return [3 /*break*/, 4];
62
+ return [4 /*yield*/, MonitoredRequestUtils.invokeCustomIsMonitoredRequest(config, request)];
63
+ case 3:
64
+ _d = (_e.sent());
65
+ _e.label = 4;
66
+ case 4:
67
+ _c = (_d);
68
+ _e.label = 5;
69
+ case 5:
70
+ monitoredRoute = _c;
71
+ monitorMode = !isEnforcedRequest && config.moduleMode === utils_1.ModuleMode.MONITOR;
72
+ return [2 /*return*/, (monitorMode || monitoredRoute) && !MonitoredRequestUtils.isAllowedToBypassMonitor(config.bypassMonitorHeader, request)];
73
+ }
74
+ });
75
+ }); };
76
+ MonitoredRequestUtils.isMonitoredRoute = function (url, isMonitoredRoute) {
77
+ return (0, utils_1.isRouteInPatterns)(url.pathname, isMonitoredRoute);
78
+ };
79
+ MonitoredRequestUtils.isEnforcedRoute = function (url, enforcedRoutes) {
80
+ return (0, utils_1.isRouteInPatterns)(url.pathname, enforcedRoutes);
81
+ };
82
+ MonitoredRequestUtils.invokeCustomIsEnforcedRequest = function (config, request) { return __awaiter(_this, void 0, void 0, function () {
83
+ var err_1;
84
+ return __generator(this, function (_a) {
85
+ switch (_a.label) {
86
+ case 0:
87
+ if (!(config.customIsEnforcedRequest && typeof config.customIsEnforcedRequest === 'function')) return [3 /*break*/, 4];
88
+ _a.label = 1;
89
+ case 1:
90
+ _a.trys.push([1, 3, , 4]);
91
+ return [4 /*yield*/, config.customIsEnforcedRequest(request.getUnderlyingRequest())];
92
+ case 2: return [2 /*return*/, _a.sent()];
93
+ case 3:
94
+ err_1 = _a.sent();
95
+ config.logger.debug("caught custom enforced request error - ".concat(err_1));
96
+ return [3 /*break*/, 4];
97
+ case 4: return [2 /*return*/, false];
98
+ }
99
+ });
100
+ }); };
101
+ MonitoredRequestUtils.invokeCustomIsMonitoredRequest = function (config, request) { return __awaiter(_this, void 0, void 0, function () {
102
+ var err_2;
103
+ return __generator(this, function (_a) {
104
+ switch (_a.label) {
105
+ case 0:
106
+ if (!(config.customIsMonitoredRequest && typeof config.customIsMonitoredRequest === 'function')) return [3 /*break*/, 4];
107
+ _a.label = 1;
108
+ case 1:
109
+ _a.trys.push([1, 3, , 4]);
110
+ return [4 /*yield*/, config.customIsMonitoredRequest(request.getUnderlyingRequest())];
111
+ case 2: return [2 /*return*/, _a.sent()];
112
+ case 3:
113
+ err_2 = _a.sent();
114
+ config.logger.debug("caught custom monitored request error - ".concat(err_2));
115
+ return [3 /*break*/, 4];
116
+ case 4: return [2 /*return*/, false];
117
+ }
118
+ });
119
+ }); };
120
+ MonitoredRequestUtils.isAllowedToBypassMonitor = function (bypassMonitorHeader, request) {
121
+ return !!bypassMonitorHeader && request.headers.get(bypassMonitorHeader) === utils_1.BYPASS_MONITOR_HEADER_VALUE;
122
+ };
123
+ })(MonitoredRequestUtils || (exports.MonitoredRequestUtils = MonitoredRequestUtils = {}));
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./MonitoredRequestUtils"), exports);
@@ -23,7 +23,7 @@ var PostEnforceFlow = /** @class */ (function (_super) {
23
23
  var products = _a.products, activityClient = _a.activityClient;
24
24
  return _super.call(this, [
25
25
  new impl_1.EnrichContextFromResponsePhase(config, products),
26
- new impl_1.ModifyOutgoingResponsePhase(Object.values(products)),
26
+ new impl_1.ModifyOutgoingResponsePhase(config, Object.values(products)),
27
27
  new impl_1.SendAsyncActivitiesOnResponsePhase(activityClient),
28
28
  ]) || this;
29
29
  }
@@ -92,7 +92,7 @@ var CreateBlockResponsePhase = /** @class */ (function () {
92
92
  switch (_c.label) {
93
93
  case 0:
94
94
  if (!context.isMobile && ((_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.source) === pxhd_1.PXHDSource.RISK) {
95
- response = pxhd_1.PXHDUtils.addPxhdToMinimalResponse(context, response);
95
+ response = pxhd_1.PXHDUtils.addPxhdToMinimalResponse(this.config, context, response);
96
96
  }
97
97
  if (!(this.config.corsSupportEnabled && ((_b = this.cors) === null || _b === void 0 ? void 0 : _b.isCorsRequest(context)))) return [3 /*break*/, 2];
98
98
  return [4 /*yield*/, this.cors.getCorsBlockHeaders(context)];
@@ -43,8 +43,26 @@ var FilterPhase = /** @class */ (function () {
43
43
  }
44
44
  FilterPhase.prototype.execute = function (context) {
45
45
  return __awaiter(this, void 0, void 0, function () {
46
- return __generator(this, function (_a) {
47
- return [2 /*return*/, { done: this.filters.some(function (filter) { return filter.shouldFilter(context); }) }];
46
+ var _i, _a, filter;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0:
50
+ _i = 0, _a = this.filters;
51
+ _b.label = 1;
52
+ case 1:
53
+ if (!(_i < _a.length)) return [3 /*break*/, 4];
54
+ filter = _a[_i];
55
+ return [4 /*yield*/, filter.shouldFilter(context)];
56
+ case 2:
57
+ if (_b.sent()) {
58
+ return [2 /*return*/, { done: true }];
59
+ }
60
+ _b.label = 3;
61
+ case 3:
62
+ _i++;
63
+ return [3 /*break*/, 1];
64
+ case 4: return [2 /*return*/, { done: false }];
65
+ }
48
66
  });
49
67
  });
50
68
  };
@@ -39,7 +39,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ModifyOutgoingResponsePhase = void 0;
40
40
  var pxhd_1 = require("../../pxhd");
41
41
  var ModifyOutgoingResponsePhase = /** @class */ (function () {
42
- function ModifyOutgoingResponsePhase(products) {
42
+ function ModifyOutgoingResponsePhase(config, products) {
43
+ this.config = config;
43
44
  this.products = products;
44
45
  }
45
46
  ModifyOutgoingResponsePhase.prototype.execute = function (context) {
@@ -51,7 +52,7 @@ var ModifyOutgoingResponsePhase = /** @class */ (function () {
51
52
  case 1:
52
53
  _b.sent();
53
54
  if (((_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.source) === pxhd_1.PXHDSource.RISK) {
54
- pxhd_1.PXHDUtils.addPxhdToOutgoingResponse(context, context.response);
55
+ pxhd_1.PXHDUtils.addPxhdToOutgoingResponse(this.config, context, context.response);
55
56
  }
56
57
  return [2 /*return*/, { done: false }];
57
58
  }
@@ -52,7 +52,9 @@ var SendLogsPhase = /** @class */ (function () {
52
52
  case 1:
53
53
  _a.sent();
54
54
  _a.label = 2;
55
- case 2: return [2 /*return*/, { done: false }];
55
+ case 2:
56
+ this.config.logger.clearLogs();
57
+ return [2 /*return*/, { done: false }];
56
58
  }
57
59
  });
58
60
  });
@@ -52,12 +52,14 @@ var action_1 = require("../../action");
52
52
  var risk_token_1 = require("../../risk_token");
53
53
  var risk_api_1 = require("../../risk_api");
54
54
  var utils_1 = require("../../utils");
55
- var __1 = require("../");
56
- var first_party_1 = require("./first_party");
55
+ var sensitive_request_1 = require("../../sensitive_request");
56
+ var monitored_request_1 = require("../../monitored_request");
57
+ var block_1 = require("./block");
57
58
  var filter_1 = require("./filter");
59
+ var first_party_1 = require("./first_party");
58
60
  var reasons_1 = require("./reasons");
61
+ var BotDefenderActionData_1 = require("./BotDefenderActionData");
59
62
  var BotDefenderUtils_1 = require("./BotDefenderUtils");
60
- var block_1 = require("./block");
61
63
  var BotDefender = /** @class */ (function () {
62
64
  function BotDefender(config, options) {
63
65
  var _a, _b, _c;
@@ -75,33 +77,31 @@ var BotDefender = /** @class */ (function () {
75
77
  });
76
78
  };
77
79
  BotDefender.prototype.shouldFilter = function (context) {
78
- return this.filter.shouldFilter(context);
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ return __generator(this, function (_a) {
82
+ return [2 /*return*/, this.filter.shouldFilter(context)];
83
+ });
84
+ });
79
85
  };
80
86
  BotDefender.prototype.enrichContextFromRequest = function (context) {
81
- var _a;
82
87
  return __awaiter(this, void 0, void 0, function () {
83
88
  var isMonitoredRequest, isSensitiveRequest, actionData;
84
- return __generator(this, function (_b) {
85
- switch (_b.label) {
86
- case 0:
87
- isMonitoredRequest = this.isMonitoredRoute(context);
88
- isSensitiveRequest = this.isSensitiveRequest(context) || ((_a = context.graphqlData) === null || _a === void 0 ? void 0 : _a.some(function (operation) { return operation.sensitive; }));
89
- return [4 /*yield*/, this.getTokenAction(context, isMonitoredRequest, isSensitiveRequest)];
89
+ return __generator(this, function (_a) {
90
+ switch (_a.label) {
91
+ case 0: return [4 /*yield*/, monitored_request_1.MonitoredRequestUtils.isMonitoredRequest(this.config, context)];
90
92
  case 1:
91
- actionData = _b.sent();
93
+ isMonitoredRequest = _a.sent();
94
+ return [4 /*yield*/, sensitive_request_1.SensitiveRequestUtils.isSensitiveRequest(this.config, context)];
95
+ case 2:
96
+ isSensitiveRequest = _a.sent();
97
+ return [4 /*yield*/, this.getTokenAction(context, isMonitoredRequest, isSensitiveRequest)];
98
+ case 3:
99
+ actionData = _a.sent();
92
100
  return [2 /*return*/, __assign(__assign({}, actionData), { isMonitoredRequest: isMonitoredRequest, isSensitiveRequest: isSensitiveRequest })];
93
101
  }
94
102
  });
95
103
  });
96
104
  };
97
- BotDefender.prototype.isMonitoredRoute = function (context) {
98
- return (0, __1.isMonitoredRequest)(this.config, context);
99
- };
100
- BotDefender.prototype.isSensitiveRequest = function (_a) {
101
- var url = _a.requestData.url;
102
- // TODO: Include custom sensitive request function
103
- return (0, utils_1.isRouteInPatterns)(url.pathname, this.config.sensitiveRoutes);
104
- };
105
105
  BotDefender.prototype.enrichContextFromResponse = function (context) {
106
106
  return __awaiter(this, void 0, void 0, function () {
107
107
  return __generator(this, function (_a) {
@@ -114,11 +114,11 @@ var BotDefender = /** @class */ (function () {
114
114
  return __generator(this, function (_a) {
115
115
  switch (context.tokenData.tokenParseResult) {
116
116
  case risk_token_1.TokenParseResult.NONE:
117
- return [2 /*return*/, new __1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, this.getNoTokenS2SCallReason(context))];
117
+ return [2 /*return*/, new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, this.getNoTokenS2SCallReason(context))];
118
118
  case risk_token_1.TokenParseResult.DECRYPTION_FAILED:
119
- return [2 /*return*/, new __1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.COOKIE_DECRYPTION_FAILED)];
119
+ return [2 /*return*/, new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.COOKIE_DECRYPTION_FAILED)];
120
120
  case risk_token_1.TokenParseResult.VALIDATION_FAILED:
121
- return [2 /*return*/, new __1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.COOKIE_VALIDATION_FAILED)];
121
+ return [2 /*return*/, new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.COOKIE_VALIDATION_FAILED)];
122
122
  case risk_token_1.TokenParseResult.SUCCESSFUL:
123
123
  return [2 /*return*/, this.getActionForSuccessfulTokenParse(context, isMonitoredRequest, isSensitiveRequest)];
124
124
  }
@@ -140,15 +140,15 @@ var BotDefender = /** @class */ (function () {
140
140
  BotDefender.prototype.getActionForSuccessfulTokenParse = function (_a, isMonitoredRequest, isSensitiveRequest) {
141
141
  var token = _a.tokenData.token;
142
142
  if (token.isExpired()) {
143
- return new __1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.COOKIE_EXPIRED);
143
+ return new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.COOKIE_EXPIRED);
144
144
  }
145
145
  if (token.isHighScore()) {
146
- return new __1.BotDefenderActionData(isMonitoredRequest ? action_1.Action.SIMULATED_BLOCK : action_1.Action.BLOCK, reasons_1.BotDefenderBlockReason.COOKIE_HIGH_SCORE);
146
+ return new BotDefenderActionData_1.BotDefenderActionData(isMonitoredRequest ? action_1.Action.SIMULATED_BLOCK : action_1.Action.BLOCK, reasons_1.BotDefenderBlockReason.COOKIE_HIGH_SCORE);
147
147
  }
148
148
  if (isSensitiveRequest) {
149
- return new __1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.SENSITIVE_ROUTE);
149
+ return new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.TRIGGER_RISK_API, reasons_1.BotDefenderS2SCallReason.SENSITIVE_ROUTE);
150
150
  }
151
- return new __1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.COOKIE);
151
+ return new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.COOKIE);
152
152
  };
153
153
  BotDefender.prototype.enrichContextFromRiskApi = function (context) {
154
154
  return __awaiter(this, void 0, void 0, function () {
@@ -168,9 +168,9 @@ var BotDefender = /** @class */ (function () {
168
168
  case risk_api_1.RiskApiCallResult.NONE:
169
169
  throw new utils_1.EnforcerError('risk api call result should not be none!');
170
170
  case risk_api_1.RiskApiCallResult.ERROR:
171
- return [2 /*return*/, new __1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S_ERROR)];
171
+ return [2 /*return*/, new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S_ERROR)];
172
172
  case risk_api_1.RiskApiCallResult.TIMEOUT:
173
- return [2 /*return*/, new __1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S_TIMEOUT)];
173
+ return [2 /*return*/, new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S_TIMEOUT)];
174
174
  case risk_api_1.RiskApiCallResult.SUCCESSFUL:
175
175
  return [2 /*return*/, this.getSuccessfulRiskApiAction(riskApiData.riskResponse, bd.isMonitoredRequest)];
176
176
  }
@@ -180,9 +180,9 @@ var BotDefender = /** @class */ (function () {
180
180
  };
181
181
  BotDefender.prototype.getSuccessfulRiskApiAction = function (riskResponse, isMonitored) {
182
182
  if (riskResponse.score >= this.config.blockingScore) {
183
- return new __1.BotDefenderActionData(isMonitored ? action_1.Action.SIMULATED_BLOCK : action_1.Action.BLOCK, reasons_1.BotDefenderBlockReason.S2S_HIGH_SCORE);
183
+ return new BotDefenderActionData_1.BotDefenderActionData(isMonitored ? action_1.Action.SIMULATED_BLOCK : action_1.Action.BLOCK, reasons_1.BotDefenderBlockReason.S2S_HIGH_SCORE);
184
184
  }
185
- return new __1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S);
185
+ return new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S);
186
186
  };
187
187
  BotDefender.prototype.shouldBlock = function (context) {
188
188
  return this.blocker.shouldBlock(context);