perimeterx-js-core 0.7.1 → 0.8.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 (189) hide show
  1. package/lib/action/utils.js +1 -1
  2. package/lib/activities/HttpActivityClient.d.ts +5 -5
  3. package/lib/activities/HttpActivityClient.js +28 -39
  4. package/lib/activities/HttpBatchedActivityClient.d.ts +2 -2
  5. package/lib/activities/HttpBatchedActivityClient.js +19 -32
  6. package/lib/activities/model/AsyncActivity.d.ts +14 -0
  7. package/lib/activities/model/{ActivityDetails.d.ts → AsyncActivityDetails.d.ts} +6 -23
  8. package/lib/activities/model/CommonActivityDetails.d.ts +40 -0
  9. package/lib/activities/model/CommonActivityDetails.js +1 -0
  10. package/lib/activities/model/HeaderEntry.d.ts +4 -0
  11. package/lib/activities/model/HeaderEntry.js +1 -0
  12. package/lib/activities/model/index.d.ts +4 -2
  13. package/lib/activities/model/index.js +4 -2
  14. package/lib/activities/utils.d.ts +6071 -9
  15. package/lib/activities/utils.js +111 -35
  16. package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
  17. package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +4 -12
  18. package/lib/config/ConfigurationParams.d.ts +1 -1
  19. package/lib/config/IConfiguration.d.ts +1 -1
  20. package/lib/config/StaticConfigurationBase.d.ts +1 -1
  21. package/lib/config/StaticConfigurationBase.js +3 -1
  22. package/lib/context/DefaultContext.d.ts +1 -1
  23. package/lib/context/DefaultContext.js +40 -8
  24. package/lib/context/interfaces/RiskApiData.d.ts +4 -0
  25. package/lib/cors/DefaultCors.js +21 -31
  26. package/lib/custom_parameters/CustomParametersUtils.js +3 -12
  27. package/lib/enforcer/EnforcerBase.js +51 -62
  28. package/lib/graphql/DefaultGraphQLParser.js +30 -39
  29. package/lib/http/index.d.ts +0 -1
  30. package/lib/http/index.js +0 -1
  31. package/lib/http/interfaces/IBody.d.ts +3 -2
  32. package/lib/http/interfaces/IIncomingRequest.d.ts +4 -0
  33. package/lib/http/interfaces/IURL.d.ts +3 -0
  34. package/lib/http/interfaces/IURLSearchParams.d.ts +9 -0
  35. package/lib/http/interfaces/IURLSearchParams.js +1 -0
  36. package/lib/http/interfaces/index.d.ts +1 -0
  37. package/lib/http/interfaces/index.js +1 -0
  38. package/lib/http/{impl → utils}/FormDataImpl.js +4 -4
  39. package/lib/http/{impl → utils}/MinimalResponseImpl.js +3 -0
  40. package/lib/http/utils/MinimalResponseUtils.js +5 -7
  41. package/lib/http/utils/MultipartFormDataUtils.js +4 -5
  42. package/lib/http/{impl → utils}/OutgoingRequestImpl.d.ts +1 -1
  43. package/lib/http/{impl → utils}/OutgoingRequestImpl.js +5 -1
  44. package/lib/http/utils/URLUtils.d.ts +7 -0
  45. package/lib/http/utils/URLUtils.js +62 -0
  46. package/lib/http/utils/UrlImpl.d.ts +18 -0
  47. package/lib/http/utils/UrlImpl.js +54 -0
  48. package/lib/http/utils/UrlSearchParamsImpl.d.ts +19 -0
  49. package/lib/http/utils/UrlSearchParamsImpl.js +116 -0
  50. package/lib/http/utils/index.d.ts +6 -0
  51. package/lib/http/utils/index.js +6 -0
  52. package/lib/{utils → impl}/base64/AtobBase64Utils.d.ts +1 -1
  53. package/lib/{utils → impl}/base64/BufferBase64Utils.d.ts +1 -1
  54. package/lib/{utils → impl}/base64/BufferBase64Utils.js +1 -1
  55. package/lib/{utils → impl}/base64/JSBase64Base64Utils.d.ts +1 -1
  56. package/lib/{utils → impl}/cipher/CryptoCipherUtils.d.ts +1 -1
  57. package/lib/impl/cipher/CryptoCipherUtils.js +18 -0
  58. package/lib/{utils → impl}/cipher/SubtleCryptoCipherUtils.d.ts +1 -2
  59. package/lib/impl/cipher/SubtleCryptoCipherUtils.js +38 -0
  60. package/lib/{utils → impl}/hash/CryptoHashUtils.d.ts +1 -2
  61. package/lib/impl/hash/CryptoHashUtils.js +10 -0
  62. package/lib/{utils → impl}/hash/CryptoJSHashUtils.d.ts +1 -2
  63. package/lib/{utils → impl}/hash/CryptoJSHashUtils.js +1 -1
  64. package/lib/{utils → impl}/hash/SubtleCryptoHashUtils.d.ts +1 -2
  65. package/lib/impl/hash/SubtleCryptoHashUtils.js +21 -0
  66. package/lib/{utils → impl}/hmac/CryptoHmacUtils.d.ts +1 -2
  67. package/lib/{utils → impl}/hmac/CryptoHmacUtils.js +2 -1
  68. package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.d.ts +1 -2
  69. package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.js +1 -1
  70. package/lib/{http/impl → impl/http}/phin/PhinHttpClient.d.ts +1 -1
  71. package/lib/impl/http/phin/PhinHttpClient.js +31 -0
  72. package/lib/{http/impl → impl/http}/phin/PhinIncomingResponse.d.ts +2 -2
  73. package/lib/impl/http/phin/PhinIncomingResponse.js +23 -0
  74. package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.d.ts +1 -1
  75. package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.d.ts +1 -1
  76. package/lib/{utils → impl}/url_parser/DefaultUrlParser.d.ts +4 -4
  77. package/lib/{utils → impl}/url_parser/DefaultUrlParser.js +9 -2
  78. package/lib/logger/HttpLogServiceClient.js +27 -35
  79. package/lib/logger/LoggerBase.js +2 -0
  80. package/lib/phase/impl/AdditionalActivityHandlerPhase.js +4 -15
  81. package/lib/phase/impl/CompositePhase.js +9 -19
  82. package/lib/phase/impl/CreateBlockResponsePhase.js +24 -35
  83. package/lib/phase/impl/DecideActionPhase.js +11 -21
  84. package/lib/phase/impl/EnrichContextFromRequestPhase.js +28 -45
  85. package/lib/phase/impl/EnrichContextFromResponsePhase.js +12 -23
  86. package/lib/phase/impl/FilterPhase.js +3 -13
  87. package/lib/phase/impl/FirstPartyPhase.js +21 -32
  88. package/lib/phase/impl/ModifyIncomingRequestPhase.js +4 -14
  89. package/lib/phase/impl/ModifyOutgoingResponsePhase.js +7 -18
  90. package/lib/phase/impl/ParseTokenPhase.js +5 -15
  91. package/lib/phase/impl/PreflightPhase.js +12 -20
  92. package/lib/phase/impl/RiskApiPhase.js +24 -36
  93. package/lib/phase/impl/SendAsyncActivitiesOnRequestPhase.js +8 -20
  94. package/lib/phase/impl/SendAsyncActivitiesOnResponsePhase.js +4 -14
  95. package/lib/phase/impl/SendLogsPhase.js +8 -18
  96. package/lib/phase/impl/TelemetryPhase.js +9 -21
  97. package/lib/products/account_defender/AccountDefender.js +16 -35
  98. package/lib/products/bot_defender/BotDefender.js +51 -72
  99. package/lib/products/bot_defender/BotDefenderActionData.js +2 -0
  100. package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.d.ts +4 -4
  101. package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.js +5 -3
  102. package/lib/products/bot_defender/block/captcha/CaptchaBlocker.d.ts +7 -4
  103. package/lib/products/bot_defender/block/captcha/CaptchaBlocker.js +12 -8
  104. package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.d.ts +1 -1
  105. package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +1 -0
  106. package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.d.ts +1 -1
  107. package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +5 -4
  108. package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.d.ts +2 -2
  109. package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.js +2 -0
  110. package/lib/products/bot_defender/block/utils.js +1 -2
  111. package/lib/products/bot_defender/filter/DefaultBotDefenderFilter.js +2 -0
  112. package/lib/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +51 -68
  113. package/lib/products/bot_defender/first_party/constants.d.ts +0 -4
  114. package/lib/products/bot_defender/first_party/constants.js +0 -7
  115. package/lib/products/credential_intelligence/CredentialIntelligence.js +42 -63
  116. package/lib/products/credential_intelligence/endpoint/CredentialEndpoint.js +15 -23
  117. package/lib/products/credential_intelligence/endpoint/CredentialEndpointManager.js +9 -22
  118. package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.d.ts +5 -5
  119. package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +22 -33
  120. package/lib/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +8 -18
  121. package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +2 -0
  122. package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.d.ts +1 -1
  123. package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +11 -16
  124. package/lib/products/credential_intelligence/endpoint/hash_protocol/MultistepHashProtocol.js +11 -21
  125. package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepAndMultistepHashProtocol.js +9 -18
  126. package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepHashProtocol.js +13 -25
  127. package/lib/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +4 -14
  128. package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulParser.js +10 -20
  129. package/lib/products/credential_intelligence/endpoint/login_successful/HeaderLoginSuccessfulParser.js +7 -16
  130. package/lib/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +7 -6
  131. package/lib/products/credential_intelligence/endpoint/login_successful/StatusLoginSuccessfulParser.js +3 -13
  132. package/lib/products/credential_intelligence/endpoint/matcher/ExactPathEndpointMatcher.js +2 -0
  133. package/lib/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +2 -0
  134. package/lib/pxde/DefaultDataEnrichment.js +47 -61
  135. package/lib/pxhd/PXHDUtils.js +2 -2
  136. package/lib/risk_api/client/PostRiskApiClientBase.d.ts +7 -12
  137. package/lib/risk_api/client/PostRiskApiClientBase.js +70 -171
  138. package/lib/risk_api/model/RiskActivity.d.ts +5 -45
  139. package/lib/risk_api/risk_response/IRiskResponse.d.ts +1 -0
  140. package/lib/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
  141. package/lib/risk_api/risk_response/RiskResponseBase.js +20 -33
  142. package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.d.ts +1 -1
  143. package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.js +3 -5
  144. package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -0
  145. package/lib/risk_api/risk_response/v3/DefaultRiskResponseV3.js +2 -4
  146. package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -0
  147. package/lib/risk_token/parser/TokenParserBase.js +25 -36
  148. package/lib/risk_token/token/TokenBase.js +24 -29
  149. package/lib/risk_token/token/v2/DefaultTokenV2.js +34 -49
  150. package/lib/risk_token/token/v3/DefaultTokenV3.js +63 -77
  151. package/lib/telemetry/DefaultTelemetry.js +46 -58
  152. package/lib/utils/base64/index.d.ts +0 -3
  153. package/lib/utils/base64/index.js +0 -3
  154. package/lib/utils/cipher/index.d.ts +1 -3
  155. package/lib/utils/cipher/index.js +1 -2
  156. package/lib/utils/constants.d.ts +2 -1
  157. package/lib/utils/constants.js +2 -1
  158. package/lib/utils/hash/index.d.ts +0 -3
  159. package/lib/utils/hash/index.js +0 -3
  160. package/lib/utils/hmac/index.d.ts +0 -2
  161. package/lib/utils/hmac/index.js +0 -2
  162. package/lib/utils/ip_range_checker/index.d.ts +1 -2
  163. package/lib/utils/ip_range_checker/index.js +1 -1
  164. package/lib/utils/request_id_generator/index.d.ts +1 -2
  165. package/lib/utils/request_id_generator/index.js +1 -1
  166. package/lib/utils/url_parser/index.d.ts +0 -1
  167. package/lib/utils/url_parser/index.js +0 -1
  168. package/lib/utils/utils.d.ts +1 -7
  169. package/lib/utils/utils.js +3 -25
  170. package/package.json +12 -6
  171. package/lib/activities/model/Activity.d.ts +0 -13
  172. package/lib/http/impl/index.d.ts +0 -4
  173. package/lib/http/impl/index.js +0 -4
  174. package/lib/http/impl/phin/PhinHttpClient.js +0 -41
  175. package/lib/http/impl/phin/PhinIncomingResponse.js +0 -38
  176. package/lib/utils/cipher/CryptoCipherUtils.js +0 -28
  177. package/lib/utils/cipher/SubtleCryptoCipherUtils.js +0 -47
  178. package/lib/utils/hash/CryptoHashUtils.js +0 -20
  179. package/lib/utils/hash/SubtleCryptoHashUtils.js +0 -31
  180. /package/lib/activities/model/{Activity.js → AsyncActivity.js} +0 -0
  181. /package/lib/activities/model/{ActivityDetails.js → AsyncActivityDetails.js} +0 -0
  182. /package/lib/http/{impl → utils}/FormDataImpl.d.ts +0 -0
  183. /package/lib/http/{impl → utils}/MinimalResponseImpl.d.ts +0 -0
  184. /package/lib/{utils → impl}/base64/AtobBase64Utils.js +0 -0
  185. /package/lib/{utils → impl}/base64/JSBase64Base64Utils.js +0 -0
  186. /package/lib/{http/impl → impl/http}/phin/index.d.ts +0 -0
  187. /package/lib/{http/impl → impl/http}/phin/index.js +0 -0
  188. /package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.js +0 -0
  189. /package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.js +0 -0
@@ -1,48 +1,30 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { getPropertyFromObject } from '../../utils';
11
2
  import { CROSS_TAB_SESSION_COOKIE_NAME } from './constants';
12
3
  export class AccountDefender {
4
+ config;
5
+ base64Utils;
13
6
  constructor(config, options) {
14
7
  this.config = config;
15
8
  this.base64Utils = options.base64Utils;
16
9
  }
17
- enrichContextFromRequest(context) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const crossTabSession = context.requestData.cookies[CROSS_TAB_SESSION_COOKIE_NAME];
20
- const jwtData = this.getJwtData(context.requestData);
21
- return Object.assign({ crossTabSession }, jwtData);
22
- });
10
+ async enrichContextFromRequest(context) {
11
+ const crossTabSession = context.requestData.cookies[CROSS_TAB_SESSION_COOKIE_NAME];
12
+ const jwtData = this.getJwtData(context.requestData);
13
+ return { crossTabSession, ...jwtData };
23
14
  }
24
- enrichContextFromRiskApi(context) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return;
27
- });
15
+ async enrichContextFromRiskApi(context) {
16
+ return;
28
17
  }
29
- enrichContextFromResponse(context) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- return;
32
- });
18
+ async enrichContextFromResponse(context) {
19
+ return;
33
20
  }
34
- modifyIncomingRequest(context) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- return;
37
- });
21
+ async modifyIncomingRequest(context) {
22
+ return;
38
23
  }
39
- modifyOutgoingResponse(context) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- return;
42
- });
24
+ async modifyOutgoingResponse(context) {
25
+ return;
43
26
  }
44
27
  getJwtData(requestData) {
45
- var _a;
46
28
  let jwtToken;
47
29
  let userIdFieldName;
48
30
  let additionalFieldNames;
@@ -54,7 +36,7 @@ export class AccountDefender {
54
36
  }
55
37
  }
56
38
  if (!jwtToken && this.config.jwtHeaderName) {
57
- jwtToken = (_a = requestData.headers[this.config.jwtHeaderName]) === null || _a === void 0 ? void 0 : _a[0];
39
+ jwtToken = requestData.headers[this.config.jwtHeaderName]?.[0];
58
40
  if (jwtToken) {
59
41
  userIdFieldName = this.config.jwtHeaderUserIdFieldName;
60
42
  additionalFieldNames = this.config.jwtHeaderAdditionalFieldNames;
@@ -84,9 +66,8 @@ export class AccountDefender {
84
66
  return null;
85
67
  }
86
68
  getDecodedJwt(jwt) {
87
- var _a;
88
69
  try {
89
- const encodedPayload = (_a = jwt.split('.')) === null || _a === void 0 ? void 0 : _a[1];
70
+ const encodedPayload = jwt.split('.')?.[1];
90
71
  const base64 = encodedPayload.replace('-', '+').replace('_', '/');
91
72
  return JSON.parse(this.base64Utils.base64Decode(base64));
92
73
  }
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { Action } from '../../action';
11
2
  import { TokenParseResult } from '../../risk_token';
12
3
  import { RiskApiCallResult } from '../../risk_api';
@@ -18,30 +9,31 @@ import { BotDefenderBlockReason, BotDefenderPassReason, BotDefenderS2SCallReason
18
9
  import { BotDefenderUtils } from './BotDefenderUtils';
19
10
  import { DefaultBotDefenderBlocker } from './block';
20
11
  export class BotDefender {
12
+ config;
13
+ firstParty;
14
+ filter;
15
+ blocker;
21
16
  constructor(config, options) {
22
- var _a, _b, _c;
23
17
  this.config = config;
24
- this.firstParty = (_a = options.firstParty) !== null && _a !== void 0 ? _a : new DefaultBotDefenderFirstParty(config);
25
- this.filter = (_b = options.filter) !== null && _b !== void 0 ? _b : new DefaultBotDefenderFilter(config, options.ipRangeChecker);
26
- this.blocker = (_c = options.blocker) !== null && _c !== void 0 ? _c : new DefaultBotDefenderBlocker(config, options.base64Utils);
18
+ this.firstParty = options.firstParty ?? new DefaultBotDefenderFirstParty(config);
19
+ this.filter = options.filter ?? new DefaultBotDefenderFilter(config, options.ipRangeChecker);
20
+ this.blocker = options.blocker ?? new DefaultBotDefenderBlocker(config, options.base64Utils);
27
21
  }
28
- handleFirstPartyRequest(context) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- return this.firstParty.handleFirstPartyRequest(context);
31
- });
22
+ async handleFirstPartyRequest(context) {
23
+ return this.firstParty.handleFirstPartyRequest(context);
32
24
  }
33
25
  shouldFilter(context) {
34
26
  return this.filter.shouldFilter(context);
35
27
  }
36
- enrichContextFromRequest(context) {
37
- var _a;
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const isMonitoredRequest = this.isMonitoredRoute(context);
40
- const isSensitiveRequest = this.isSensitiveRequest(context) || ((_a = context.graphqlData) === null || _a === void 0 ? void 0 : _a.some((operation) => operation.sensitive));
41
- const actionData = yield this.getTokenAction(context, isMonitoredRequest, isSensitiveRequest);
42
- return Object.assign(Object.assign({}, actionData), { isMonitoredRequest,
43
- isSensitiveRequest });
44
- });
28
+ async enrichContextFromRequest(context) {
29
+ const isMonitoredRequest = this.isMonitoredRoute(context);
30
+ const isSensitiveRequest = this.isSensitiveRequest(context) || context.graphqlData?.some((operation) => operation.sensitive);
31
+ const actionData = await this.getTokenAction(context, isMonitoredRequest, isSensitiveRequest);
32
+ return {
33
+ ...actionData,
34
+ isMonitoredRequest,
35
+ isSensitiveRequest,
36
+ };
45
37
  }
46
38
  isMonitoredRoute(context) {
47
39
  return isMonitoredRequest(this.config, context);
@@ -50,28 +42,23 @@ export class BotDefender {
50
42
  // TODO: Include custom sensitive request function
51
43
  return isRouteInPatterns(url.pathname, this.config.sensitiveRoutes);
52
44
  }
53
- enrichContextFromResponse(context) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- return;
56
- });
57
- }
58
- getTokenAction(context, isMonitoredRequest, isSensitiveRequest) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- switch (context.tokenData.tokenParseResult) {
61
- case TokenParseResult.NONE:
62
- return new BotDefenderActionData(Action.TRIGGER_RISK_API, this.getNoTokenS2SCallReason(context));
63
- case TokenParseResult.DECRYPTION_FAILED:
64
- return new BotDefenderActionData(Action.TRIGGER_RISK_API, BotDefenderS2SCallReason.COOKIE_DECRYPTION_FAILED);
65
- case TokenParseResult.VALIDATION_FAILED:
66
- return new BotDefenderActionData(Action.TRIGGER_RISK_API, BotDefenderS2SCallReason.COOKIE_VALIDATION_FAILED);
67
- case TokenParseResult.SUCCESSFUL:
68
- return this.getActionForSuccessfulTokenParse(context, isMonitoredRequest, isSensitiveRequest);
69
- }
70
- });
45
+ async enrichContextFromResponse(context) {
46
+ return;
47
+ }
48
+ async getTokenAction(context, isMonitoredRequest, isSensitiveRequest) {
49
+ switch (context.tokenData.tokenParseResult) {
50
+ case TokenParseResult.NONE:
51
+ return new BotDefenderActionData(Action.TRIGGER_RISK_API, this.getNoTokenS2SCallReason(context));
52
+ case TokenParseResult.DECRYPTION_FAILED:
53
+ return new BotDefenderActionData(Action.TRIGGER_RISK_API, BotDefenderS2SCallReason.COOKIE_DECRYPTION_FAILED);
54
+ case TokenParseResult.VALIDATION_FAILED:
55
+ return new BotDefenderActionData(Action.TRIGGER_RISK_API, BotDefenderS2SCallReason.COOKIE_VALIDATION_FAILED);
56
+ case TokenParseResult.SUCCESSFUL:
57
+ return this.getActionForSuccessfulTokenParse(context, isMonitoredRequest, isSensitiveRequest);
58
+ }
71
59
  }
72
60
  getNoTokenS2SCallReason({ pxhd, isMobile, tokenData, }) {
73
- var _a;
74
- if (isMobile && ((_a = tokenData.mobileData) === null || _a === void 0 ? void 0 : _a.mobileError)) {
61
+ if (isMobile && tokenData.mobileData?.mobileError) {
75
62
  return BotDefenderUtils.getS2SCallReasonFromMobileError(tokenData.mobileData.mobileError);
76
63
  }
77
64
  if (pxhd) {
@@ -91,24 +78,20 @@ export class BotDefender {
91
78
  }
92
79
  return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.COOKIE);
93
80
  }
94
- enrichContextFromRiskApi(context) {
95
- return __awaiter(this, void 0, void 0, function* () {
96
- return yield this.getRiskApiActionData(context);
97
- });
98
- }
99
- getRiskApiActionData({ riskApiData, productData: { bd }, }) {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- switch (riskApiData.riskApiCallResult) {
102
- case RiskApiCallResult.NONE:
103
- throw new EnforcerError('risk api call result should not be none!');
104
- case RiskApiCallResult.ERROR:
105
- return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_ERROR);
106
- case RiskApiCallResult.TIMEOUT:
107
- return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_TIMEOUT);
108
- case RiskApiCallResult.SUCCESSFUL:
109
- return this.getSuccessfulRiskApiAction(riskApiData.riskResponse, bd.isMonitoredRequest);
110
- }
111
- });
81
+ async enrichContextFromRiskApi(context) {
82
+ return await this.getRiskApiActionData(context);
83
+ }
84
+ async getRiskApiActionData({ riskApiData, productData: { bd }, }) {
85
+ switch (riskApiData.riskApiCallResult) {
86
+ case RiskApiCallResult.NONE:
87
+ throw new EnforcerError('risk api call result should not be none!');
88
+ case RiskApiCallResult.ERROR:
89
+ return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_ERROR);
90
+ case RiskApiCallResult.TIMEOUT:
91
+ return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_TIMEOUT);
92
+ case RiskApiCallResult.SUCCESSFUL:
93
+ return this.getSuccessfulRiskApiAction(riskApiData.riskResponse, bd.isMonitoredRequest);
94
+ }
112
95
  }
113
96
  getSuccessfulRiskApiAction(riskResponse, isMonitored) {
114
97
  if (riskResponse.score >= this.config.blockingScore) {
@@ -122,14 +105,10 @@ export class BotDefender {
122
105
  createBlockResponse(context) {
123
106
  return this.blocker.createBlockResponse(context);
124
107
  }
125
- modifyIncomingRequest(context) {
126
- return __awaiter(this, void 0, void 0, function* () {
127
- // intentionally left blank
128
- });
108
+ async modifyIncomingRequest(context) {
109
+ // intentionally left blank
129
110
  }
130
- modifyOutgoingResponse(context) {
131
- return __awaiter(this, void 0, void 0, function* () {
132
- // intentionally left blank
133
- });
111
+ async modifyOutgoingResponse(context) {
112
+ // intentionally left blank
134
113
  }
135
114
  }
@@ -1,4 +1,6 @@
1
1
  export class BotDefenderActionData {
2
+ action;
3
+ reason;
2
4
  constructor(action, reason) {
3
5
  this.action = action;
4
6
  this.reason = reason;
@@ -1,14 +1,14 @@
1
1
  import { ReadonlyContext } from '../../../context';
2
2
  import { IConfiguration } from '../../../config';
3
3
  import { IBase64Utils } from '../../../utils';
4
- import { IConditionalBlocker } from '../../../blocker';
4
+ import { IBlocker, IConditionalBlocker } from '../../../blocker';
5
5
  import { IMinimalResponse } from '../../../http';
6
6
  export declare class DefaultBotDefenderBlocker<Req, Res> implements IConditionalBlocker<Req, Res> {
7
- private readonly config;
8
- private readonly captchaResponseGenerator;
7
+ protected readonly config: IConfiguration<Req, Res>;
8
+ protected readonly captchaBlocker: IBlocker<Req, Res>;
9
9
  constructor(config: IConfiguration<Req, Res>, base64Utils: IBase64Utils);
10
10
  shouldBlock({ action, reasons, productData }: ReadonlyContext<Req, Res>): boolean;
11
11
  createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
12
- private createRateLimitResponse;
12
+ protected createRateLimitResponse(): IMinimalResponse;
13
13
  private createCaptchaResponse;
14
14
  }
@@ -5,12 +5,14 @@ import { ProductName } from '../../utils';
5
5
  import { CaptchaBlocker } from './captcha';
6
6
  import { RATE_LIMIT_TEMPLATE } from './templates';
7
7
  export class DefaultBotDefenderBlocker {
8
+ config;
9
+ captchaBlocker;
8
10
  constructor(config, base64Utils) {
9
11
  this.config = config;
10
- this.captchaResponseGenerator = new CaptchaBlocker(config, base64Utils);
12
+ this.captchaBlocker = new CaptchaBlocker(config, base64Utils);
11
13
  }
12
14
  shouldBlock({ action, reasons, productData }) {
13
- return action === Action.BLOCK && !!(reasons === null || reasons === void 0 ? void 0 : reasons[ProductName.BOT_DEFENDER]);
15
+ return action === Action.BLOCK && !!reasons?.[ProductName.BOT_DEFENDER];
14
16
  }
15
17
  createBlockResponse(context) {
16
18
  switch (context.blockAction) {
@@ -34,6 +36,6 @@ export class DefaultBotDefenderBlocker {
34
36
  });
35
37
  }
36
38
  createCaptchaResponse(context) {
37
- return this.captchaResponseGenerator.createBlockResponse(context);
39
+ return this.captchaBlocker.createBlockResponse(context);
38
40
  }
39
41
  }
@@ -3,11 +3,14 @@ import { ReadonlyContext } from '../../../../context';
3
3
  import { IBase64Utils } from '../../../../utils';
4
4
  import { IBlocker } from '../../../../blocker';
5
5
  import { IMinimalResponse } from '../../../../http';
6
+ import { JsonCaptchaBlocker } from './JsonCaptchaBlocker';
7
+ import { MobileCaptchaBlocker } from './MobileCaptchaBlocker';
8
+ import { HtmlCaptchaBlocker } from './HtmlCaptchaBlocker';
6
9
  export declare class CaptchaBlocker<Req, Res> implements IBlocker<Req, Res> {
7
- private readonly config;
8
- private readonly jsonCaptchaGenerator;
9
- private readonly mobileCaptchaGenerator;
10
- private readonly htmlCaptchaGenerator;
10
+ protected readonly config: IConfiguration<Req, Res>;
11
+ protected readonly jsonCaptchaBlocker: JsonCaptchaBlocker<Req, Res>;
12
+ protected readonly mobileCaptchaBlocker: MobileCaptchaBlocker<Req, Res>;
13
+ protected readonly htmlCaptchaBlocker: HtmlCaptchaBlocker<Req, Res>;
11
14
  constructor(config: IConfiguration<Req, Res>, base64Utils: IBase64Utils);
12
15
  createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
13
16
  }
@@ -2,19 +2,23 @@ import { JsonCaptchaBlocker } from './JsonCaptchaBlocker';
2
2
  import { MobileCaptchaBlocker } from './MobileCaptchaBlocker';
3
3
  import { HtmlCaptchaBlocker } from './HtmlCaptchaBlocker';
4
4
  export class CaptchaBlocker {
5
+ config;
6
+ jsonCaptchaBlocker;
7
+ mobileCaptchaBlocker;
8
+ htmlCaptchaBlocker;
5
9
  constructor(config, base64Utils) {
6
10
  this.config = config;
7
- this.jsonCaptchaGenerator = new JsonCaptchaBlocker(config);
8
- this.mobileCaptchaGenerator = new MobileCaptchaBlocker(config, base64Utils);
9
- this.htmlCaptchaGenerator = new HtmlCaptchaBlocker(config);
11
+ this.jsonCaptchaBlocker = new JsonCaptchaBlocker(config);
12
+ this.mobileCaptchaBlocker = new MobileCaptchaBlocker(config, base64Utils);
13
+ this.htmlCaptchaBlocker = new HtmlCaptchaBlocker(config);
10
14
  }
11
15
  createBlockResponse(context) {
12
- if (this.mobileCaptchaGenerator.shouldBlock(context)) {
13
- return this.mobileCaptchaGenerator.createBlockResponse(context);
16
+ if (this.mobileCaptchaBlocker.shouldBlock(context)) {
17
+ return this.mobileCaptchaBlocker.createBlockResponse(context);
14
18
  }
15
- if (this.jsonCaptchaGenerator.shouldBlock(context)) {
16
- return this.jsonCaptchaGenerator.createBlockResponse(context);
19
+ if (this.jsonCaptchaBlocker.shouldBlock(context)) {
20
+ return this.jsonCaptchaBlocker.createBlockResponse(context);
17
21
  }
18
- return this.htmlCaptchaGenerator.createBlockResponse(context);
22
+ return this.htmlCaptchaBlocker.createBlockResponse(context);
19
23
  }
20
24
  }
@@ -3,7 +3,7 @@ import { ReadonlyContext } from '../../../../context';
3
3
  import { IBlocker } from '../../../../blocker';
4
4
  import { IMinimalResponse } from '../../../../http';
5
5
  export declare class HtmlCaptchaBlocker<Req, Res> implements IBlocker<Req, Res> {
6
- private readonly config;
6
+ protected readonly config: IConfiguration<Req, Res>;
7
7
  constructor(config: IConfiguration<Req, Res>);
8
8
  createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
9
9
  }
@@ -2,6 +2,7 @@ import { ContentType, CONTENT_TYPE_HEADER_NAME, MinimalResponseImpl } from '../.
2
2
  import { createBlockData, renderHtml } from '../utils';
3
3
  import { CAPTCHA_TEMPLATE } from '../templates';
4
4
  export class HtmlCaptchaBlocker {
5
+ config;
5
6
  constructor(config) {
6
7
  this.config = config;
7
8
  }
@@ -3,7 +3,7 @@ import { ReadonlyContext } from '../../../../context';
3
3
  import { IConditionalBlocker } from '../../../../blocker';
4
4
  import { IMinimalResponse } from '../../../../http';
5
5
  export declare class JsonCaptchaBlocker<Req, Res> implements IConditionalBlocker<Req, Res> {
6
- private readonly config;
6
+ protected readonly config: IConfiguration<Req, Res>;
7
7
  constructor(config: IConfiguration<Req, Res>);
8
8
  shouldBlock(context: ReadonlyContext<Req, Res>): boolean;
9
9
  createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
@@ -2,6 +2,7 @@ import { BlockAction } from '../../../../blocker';
2
2
  import { ContentType, CONTENT_TYPE_HEADER_NAME, ACCEPT_HEADER_NAME, MinimalResponseImpl, } from '../../../../http';
3
3
  import { createBlockData } from '../utils';
4
4
  export class JsonCaptchaBlocker {
5
+ config;
5
6
  constructor(config) {
6
7
  this.config = config;
7
8
  }
@@ -9,10 +10,10 @@ export class JsonCaptchaBlocker {
9
10
  if (!this.config.advancedBlockingResponseEnabled) {
10
11
  return false;
11
12
  }
12
- const acceptHeaderValue = context.requestData.request.headers.get(ACCEPT_HEADER_NAME) ||
13
- context.requestData.request.headers.get(CONTENT_TYPE_HEADER_NAME) ||
14
- '';
15
- const acceptHeaderContainsJson = acceptHeaderValue === null || acceptHeaderValue === void 0 ? void 0 : acceptHeaderValue.split(',').some((value) => value.toLowerCase() === ContentType.APPLICATION_JSON);
13
+ const acceptHeaderValue = context.requestData.request.headers.get(ACCEPT_HEADER_NAME) || '';
14
+ const acceptHeaderContainsJson = acceptHeaderValue
15
+ ?.split(',')
16
+ .some((value) => value.toLowerCase() === ContentType.APPLICATION_JSON);
16
17
  return !context.isMobile && context.blockAction !== BlockAction.RATE_LIMIT && acceptHeaderContainsJson;
17
18
  }
18
19
  createBlockResponse(context) {
@@ -4,8 +4,8 @@ import { IBase64Utils } from '../../../../utils';
4
4
  import { IConditionalBlocker } from '../../../../blocker';
5
5
  import { IMinimalResponse } from '../../../../http';
6
6
  export declare class MobileCaptchaBlocker<Req, Res> implements IConditionalBlocker<Req, Res> {
7
- private readonly config;
8
- private readonly base64Utils;
7
+ protected readonly config: IConfiguration<Req, Res>;
8
+ protected readonly base64Utils: IBase64Utils;
9
9
  constructor(config: IConfiguration<Req, Res>, base64Utils: IBase64Utils);
10
10
  shouldBlock(context: ReadonlyContext<Req, Res>): boolean;
11
11
  createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
@@ -3,6 +3,8 @@ import { ContentType, CONTENT_TYPE_HEADER_NAME, MinimalResponseImpl } from '../.
3
3
  import { createBlockData, renderHtml } from '../utils';
4
4
  import { CAPTCHA_TEMPLATE } from '../templates';
5
5
  export class MobileCaptchaBlocker {
6
+ config;
7
+ base64Utils;
6
8
  constructor(config, base64Utils) {
7
9
  this.config = config;
8
10
  this.base64Utils = base64Utils;
@@ -12,7 +12,6 @@ export const renderHtml = (htmlTemplate, blockData) => {
12
12
  return htmlTemplate;
13
13
  };
14
14
  export const createBlockData = (config, context) => {
15
- var _a, _b;
16
15
  const captchaScriptSuffix = '/captcha.js';
17
16
  const captchaParams = `?a=${context.blockAction}&u=${context.uuid}&v=${context.vid || ''}&m=${context.isMobile ? '1' : '0'}`;
18
17
  let jsClientSrc = `${config.backendClientUrl}/${config.appId}/main.min.js`;
@@ -28,7 +27,7 @@ export const createBlockData = (config, context) => {
28
27
  const altBlockScript = `${config.altBackendCaptchaUrl}/${config.appId}${captchaScriptSuffix}${captchaParams}`;
29
28
  return {
30
29
  appId: config.appId,
31
- vid: context.vid || ((_b = (_a = context.requestData) === null || _a === void 0 ? void 0 : _a.cookies) === null || _b === void 0 ? void 0 : _b[PXVID_COOKIE_NAME]) || '',
30
+ vid: context.vid || context.requestData?.cookies?.[PXVID_COOKIE_NAME] || '',
32
31
  uuid: context.uuid || '',
33
32
  isMobile: context.isMobile,
34
33
  customLogo: config.customLogo || '',
@@ -2,6 +2,8 @@ import { HttpMethod } from '../../../http';
2
2
  import { FilterReason } from '../../../filter';
3
3
  import { getExtension, isRouteInPatterns } from '../../../utils';
4
4
  export class DefaultBotDefenderFilter {
5
+ config;
6
+ ipRangeChecker;
5
7
  constructor(config, ipRangeChecker) {
6
8
  this.config = config;
7
9
  this.ipRangeChecker = ipRangeChecker;
@@ -1,61 +1,47 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { removeSensitiveHeaders } from '../../../utils';
11
- import { COOKIE_HEADER_NAME, HOST_HEADER_NAME, X_FORWARDED_FOR_HEADER_NAME, OutgoingRequestImpl, MinimalResponseImpl, toMutableHeaders, } from '../../../http';
2
+ import { COOKIE_HEADER_NAME, HOST_HEADER_NAME, X_FORWARDED_FOR_HEADER_NAME, OutgoingRequestImpl, MinimalResponseImpl, toMutableHeaders, URLUtils, } from '../../../http';
12
3
  import { getFirstPartyCaptchaScriptPathPrefixes, getFirstPartySensorScriptPaths, getFirstPartyXhrPathPrefixes, } from './utils';
13
4
  import { DEFAULT_CLIENT_RESPONSE_OPTIONS, DEFAULT_GIF_RESPONSE, DEFAULT_XHR_RESPONSE, FIRST_PARTY_HEADER_NAME, FIRST_PARTY_HEADER_VALUE, X_PX_ENFORCER_TRUE_IP_HEADER_NAME, } from './constants';
14
5
  import { FirstPartySuffix } from './FirstPartySuffix';
15
6
  export class DefaultBotDefenderFirstParty {
7
+ config;
16
8
  constructor(config) {
17
9
  this.config = config;
18
10
  }
19
- handleFirstPartyRequest(context) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const { pathname } = context.requestData.url;
22
- if (getFirstPartySensorScriptPaths(this.config).includes(pathname)) {
23
- return yield this.proxySensorScriptRequest(context);
24
- }
25
- const xhrPrefix = getFirstPartyXhrPathPrefixes(this.config).find((prefix) => pathname.startsWith(prefix));
26
- if (xhrPrefix) {
27
- return yield this.proxyXhrRequest(context, xhrPrefix);
28
- }
29
- const captchaPrefix = getFirstPartyCaptchaScriptPathPrefixes(this.config).find((prefix) => pathname.startsWith(prefix));
30
- if (captchaPrefix) {
31
- return yield this.proxyCaptchaScriptRequest(context);
32
- }
33
- return null;
34
- });
11
+ async handleFirstPartyRequest(context) {
12
+ const { pathname } = context.requestData.url;
13
+ if (getFirstPartySensorScriptPaths(this.config).includes(pathname)) {
14
+ return await this.proxySensorScriptRequest(context);
15
+ }
16
+ const xhrPrefix = getFirstPartyXhrPathPrefixes(this.config).find((prefix) => pathname.startsWith(prefix));
17
+ if (xhrPrefix) {
18
+ return await this.proxyXhrRequest(context, xhrPrefix);
19
+ }
20
+ const captchaPrefix = getFirstPartyCaptchaScriptPathPrefixes(this.config).find((prefix) => pathname.startsWith(prefix));
21
+ if (captchaPrefix) {
22
+ return await this.proxyCaptchaScriptRequest(context);
23
+ }
24
+ return null;
35
25
  }
36
- proxySensorScriptRequest(context) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const defaultResponse = new MinimalResponseImpl(DEFAULT_CLIENT_RESPONSE_OPTIONS);
39
- if (!this.config.firstPartyEnabled) {
40
- return { defaultResponse };
41
- }
42
- const url = this.getThirdPartySensorScriptUrl();
43
- const request = yield this.getOutgoingRequest(url, context);
44
- this.config.logger.debug(`proxying sensor script ${context.requestData.url.pathname} to ${url}`);
45
- return { request, defaultResponse };
46
- });
26
+ async proxySensorScriptRequest(context) {
27
+ const defaultResponse = new MinimalResponseImpl(DEFAULT_CLIENT_RESPONSE_OPTIONS);
28
+ if (!this.config.firstPartyEnabled) {
29
+ return { defaultResponse };
30
+ }
31
+ const url = this.getThirdPartySensorScriptUrl();
32
+ const request = await this.getOutgoingRequest(url, context);
33
+ this.config.logger.debug(`proxying first party sensor script ${context.requestData.url.pathname} to ${url}`);
34
+ return { request, defaultResponse };
47
35
  }
48
- proxyXhrRequest(context, prefix) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const defaultResponse = DefaultBotDefenderFirstParty.getDefaultXhrResponse(context.requestData.url.pathname);
51
- if (!this.config.firstPartyEnabled) {
52
- return { defaultResponse };
53
- }
54
- const url = this.getThirdPartyXhrUrl(context, prefix);
55
- const request = yield this.getOutgoingRequest(url, context);
56
- this.config.logger.debug(`proxying XHR request ${context.requestData.url.pathname} to ${url}`);
57
- return { request, defaultResponse };
58
- });
36
+ async proxyXhrRequest(context, prefix) {
37
+ const defaultResponse = DefaultBotDefenderFirstParty.getDefaultXhrResponse(context.requestData.url.pathname);
38
+ if (!this.config.firstPartyEnabled) {
39
+ return { defaultResponse };
40
+ }
41
+ const url = this.getThirdPartyXhrUrl(context, prefix);
42
+ const request = await this.getOutgoingRequest(url, context);
43
+ this.config.logger.debug(`proxying first party XHR request ${context.requestData.url.pathname} to ${url}`);
44
+ return { request, defaultResponse };
59
45
  }
60
46
  static getDefaultXhrResponse(path) {
61
47
  const { content, options } = path.endsWith('.gif') ? DEFAULT_GIF_RESPONSE : DEFAULT_XHR_RESPONSE;
@@ -65,26 +51,22 @@ export class DefaultBotDefenderFirstParty {
65
51
  headers: options.headers,
66
52
  });
67
53
  }
68
- proxyCaptchaScriptRequest(context) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const defaultResponse = new MinimalResponseImpl(DEFAULT_CLIENT_RESPONSE_OPTIONS);
71
- if (!this.config.firstPartyEnabled) {
72
- return { defaultResponse };
73
- }
74
- const url = this.getThirdPartyCaptchaScriptUrl(context);
75
- const request = yield this.getOutgoingRequest(url, context);
76
- this.config.logger.debug(`proxying captcha script ${context.requestData.url.pathname} to ${url}`);
77
- return { request, defaultResponse };
78
- });
54
+ async proxyCaptchaScriptRequest(context) {
55
+ const defaultResponse = new MinimalResponseImpl(DEFAULT_CLIENT_RESPONSE_OPTIONS);
56
+ if (!this.config.firstPartyEnabled) {
57
+ return { defaultResponse };
58
+ }
59
+ const url = this.getThirdPartyCaptchaScriptUrl(context);
60
+ const request = await this.getOutgoingRequest(url, context);
61
+ this.config.logger.debug(`proxying first party captcha script ${context.requestData.url.pathname} to ${url}`);
62
+ return { request, defaultResponse };
79
63
  }
80
- getOutgoingRequest(url, { requestData, vid }) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- return new OutgoingRequestImpl({
83
- url: url,
84
- method: requestData.method,
85
- headers: this.prepareFirstPartyHeaders(url, requestData, vid),
86
- body: requestData.request.body,
87
- });
64
+ async getOutgoingRequest(url, { requestData, vid }) {
65
+ return new OutgoingRequestImpl({
66
+ url: url,
67
+ method: requestData.method,
68
+ headers: this.prepareFirstPartyHeaders(url, requestData, vid),
69
+ body: requestData.request.body,
88
70
  });
89
71
  }
90
72
  prepareFirstPartyHeaders(url, requestData, vid) {
@@ -105,7 +87,8 @@ export class DefaultBotDefenderFirstParty {
105
87
  return headers;
106
88
  }
107
89
  setHostHeader(headers, url) {
108
- headers[HOST_HEADER_NAME] = [new URL(url).host];
90
+ const { host } = URLUtils.parseURL(url);
91
+ headers[HOST_HEADER_NAME] = [host];
109
92
  }
110
93
  setXffHeader(headers, ip) {
111
94
  const xffValue = headers[X_FORWARDED_FOR_HEADER_NAME] || [];
@@ -1,12 +1,8 @@
1
1
  import { ContentType } from '../../../http';
2
2
  import { MinimalResponseOptions } from '../../../http';
3
- export declare const EMPTY_GIF: number[];
4
3
  export declare const X_PX_ENFORCER_TRUE_IP_HEADER_NAME = "x-px-enforcer-true-ip";
5
4
  export declare const FIRST_PARTY_HEADER_NAME = "x-px-first-party";
6
5
  export declare const FIRST_PARTY_HEADER_VALUE = "1";
7
- export declare const FIRST_PARTY_SENSOR_SUFFIX = "/init.js";
8
- export declare const FIRST_PARTY_CAPTCHA_SUFFIX = "/captcha";
9
- export declare const FIRST_PARTY_XHR_SUFFIX = "/xhr";
10
6
  export declare const DEFAULT_CLIENT_RESPONSE_OPTIONS: MinimalResponseOptions;
11
7
  export declare const DEFAULT_XHR_RESPONSE: {
12
8
  content: string;