perimeterx-js-core 0.7.0 → 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 (216) 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 +2 -1
  19. package/lib/config/DefaultConfigurations.js +1 -0
  20. package/lib/config/IConfiguration.d.ts +5 -1
  21. package/lib/config/StaticConfigurationBase.d.ts +2 -1
  22. package/lib/config/StaticConfigurationBase.js +6 -1
  23. package/lib/context/DefaultContext.d.ts +1 -1
  24. package/lib/context/DefaultContext.js +40 -8
  25. package/lib/context/interfaces/RiskApiData.d.ts +4 -0
  26. package/lib/cors/DefaultCors.js +21 -31
  27. package/lib/custom_parameters/CustomParametersUtils.js +3 -12
  28. package/lib/enforcer/EnforcerBase.d.ts +2 -1
  29. package/lib/enforcer/EnforcerBase.js +56 -57
  30. package/lib/enforcer/options/EnforcerBaseOptions.d.ts +2 -0
  31. package/lib/graphql/DefaultGraphQLParser.js +30 -39
  32. package/lib/http/index.d.ts +0 -1
  33. package/lib/http/index.js +0 -1
  34. package/lib/http/interfaces/IBody.d.ts +3 -2
  35. package/lib/http/interfaces/IIncomingRequest.d.ts +4 -0
  36. package/lib/http/interfaces/IURL.d.ts +3 -0
  37. package/lib/http/interfaces/IURLSearchParams.d.ts +9 -0
  38. package/lib/http/interfaces/IURLSearchParams.js +1 -0
  39. package/lib/http/interfaces/index.d.ts +1 -0
  40. package/lib/http/interfaces/index.js +1 -0
  41. package/lib/http/{impl → utils}/FormDataImpl.js +4 -4
  42. package/lib/http/{impl → utils}/MinimalResponseImpl.js +3 -0
  43. package/lib/http/utils/MinimalResponseUtils.js +5 -7
  44. package/lib/http/utils/MultipartFormDataUtils.js +4 -5
  45. package/lib/http/{impl → utils}/OutgoingRequestImpl.d.ts +1 -1
  46. package/lib/http/{impl → utils}/OutgoingRequestImpl.js +5 -1
  47. package/lib/http/utils/URLUtils.d.ts +7 -0
  48. package/lib/http/utils/URLUtils.js +62 -0
  49. package/lib/http/utils/UrlImpl.d.ts +18 -0
  50. package/lib/http/utils/UrlImpl.js +54 -0
  51. package/lib/http/utils/UrlSearchParamsImpl.d.ts +19 -0
  52. package/lib/http/utils/UrlSearchParamsImpl.js +116 -0
  53. package/lib/http/utils/index.d.ts +6 -0
  54. package/lib/http/utils/index.js +6 -0
  55. package/lib/{utils → impl}/base64/AtobBase64Utils.d.ts +1 -1
  56. package/lib/{utils → impl}/base64/BufferBase64Utils.d.ts +1 -1
  57. package/lib/{utils → impl}/base64/BufferBase64Utils.js +1 -1
  58. package/lib/{utils → impl}/base64/JSBase64Base64Utils.d.ts +1 -1
  59. package/lib/{utils → impl}/cipher/CryptoCipherUtils.d.ts +1 -1
  60. package/lib/impl/cipher/CryptoCipherUtils.js +18 -0
  61. package/lib/{utils → impl}/cipher/SubtleCryptoCipherUtils.d.ts +1 -2
  62. package/lib/impl/cipher/SubtleCryptoCipherUtils.js +38 -0
  63. package/lib/{utils → impl}/hash/CryptoHashUtils.d.ts +1 -2
  64. package/lib/impl/hash/CryptoHashUtils.js +10 -0
  65. package/lib/{utils → impl}/hash/CryptoJSHashUtils.d.ts +1 -2
  66. package/lib/{utils → impl}/hash/CryptoJSHashUtils.js +1 -1
  67. package/lib/{utils → impl}/hash/SubtleCryptoHashUtils.d.ts +1 -2
  68. package/lib/impl/hash/SubtleCryptoHashUtils.js +21 -0
  69. package/lib/{utils → impl}/hmac/CryptoHmacUtils.d.ts +1 -2
  70. package/lib/{utils → impl}/hmac/CryptoHmacUtils.js +2 -1
  71. package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.d.ts +1 -2
  72. package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.js +1 -1
  73. package/lib/{http/impl → impl/http}/phin/PhinHttpClient.d.ts +1 -1
  74. package/lib/impl/http/phin/PhinHttpClient.js +31 -0
  75. package/lib/{http/impl → impl/http}/phin/PhinIncomingResponse.d.ts +2 -2
  76. package/lib/impl/http/phin/PhinIncomingResponse.js +23 -0
  77. package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.d.ts +1 -1
  78. package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.d.ts +1 -1
  79. package/lib/{utils → impl}/url_parser/DefaultUrlParser.d.ts +4 -4
  80. package/lib/{utils → impl}/url_parser/DefaultUrlParser.js +9 -2
  81. package/lib/logger/HttpLogServiceClient.d.ts +17 -0
  82. package/lib/logger/HttpLogServiceClient.js +52 -0
  83. package/lib/logger/ILogServiceClient.d.ts +6 -0
  84. package/lib/logger/ILogServiceClient.js +1 -0
  85. package/lib/logger/ILogger.d.ts +6 -0
  86. package/lib/logger/LoggerBase.d.ts +6 -2
  87. package/lib/logger/LoggerBase.js +14 -1
  88. package/lib/logger/constants.d.ts +2 -0
  89. package/lib/logger/constants.js +2 -0
  90. package/lib/logger/index.d.ts +4 -0
  91. package/lib/logger/index.js +3 -0
  92. package/lib/logger/model/EnrichedLogRecord.d.ts +3 -0
  93. package/lib/logger/model/EnrichedLogRecord.js +1 -0
  94. package/lib/logger/model/LogMetadata.d.ts +9 -0
  95. package/lib/logger/model/LogMetadata.js +1 -0
  96. package/lib/logger/model/LogRecord.d.ts +6 -0
  97. package/lib/logger/model/LogRecord.js +1 -0
  98. package/lib/logger/model/index.d.ts +3 -0
  99. package/lib/logger/model/index.js +3 -0
  100. package/lib/phase/flow/EndEnforcerFlow.d.ts +6 -0
  101. package/lib/phase/flow/EndEnforcerFlow.js +10 -0
  102. package/lib/phase/flow/index.d.ts +1 -0
  103. package/lib/phase/flow/index.js +1 -0
  104. package/lib/phase/impl/AdditionalActivityHandlerPhase.js +4 -15
  105. package/lib/phase/impl/CompositePhase.js +9 -19
  106. package/lib/phase/impl/CreateBlockResponsePhase.js +24 -35
  107. package/lib/phase/impl/DecideActionPhase.js +11 -21
  108. package/lib/phase/impl/EnrichContextFromRequestPhase.js +28 -45
  109. package/lib/phase/impl/EnrichContextFromResponsePhase.js +12 -23
  110. package/lib/phase/impl/FilterPhase.js +3 -13
  111. package/lib/phase/impl/FirstPartyPhase.js +21 -32
  112. package/lib/phase/impl/ModifyIncomingRequestPhase.js +4 -14
  113. package/lib/phase/impl/ModifyOutgoingResponsePhase.js +7 -18
  114. package/lib/phase/impl/ParseTokenPhase.js +5 -15
  115. package/lib/phase/impl/PreflightPhase.js +12 -20
  116. package/lib/phase/impl/RiskApiPhase.js +24 -36
  117. package/lib/phase/impl/SendAsyncActivitiesOnRequestPhase.js +8 -20
  118. package/lib/phase/impl/SendAsyncActivitiesOnResponsePhase.js +4 -14
  119. package/lib/phase/impl/SendLogsPhase.d.ts +11 -0
  120. package/lib/phase/impl/SendLogsPhase.js +16 -0
  121. package/lib/phase/impl/TelemetryPhase.js +9 -21
  122. package/lib/phase/impl/index.d.ts +1 -0
  123. package/lib/phase/impl/index.js +1 -0
  124. package/lib/products/account_defender/AccountDefender.js +16 -35
  125. package/lib/products/bot_defender/BotDefender.js +51 -72
  126. package/lib/products/bot_defender/BotDefenderActionData.js +2 -0
  127. package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.d.ts +4 -4
  128. package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.js +5 -3
  129. package/lib/products/bot_defender/block/captcha/CaptchaBlocker.d.ts +7 -4
  130. package/lib/products/bot_defender/block/captcha/CaptchaBlocker.js +12 -8
  131. package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.d.ts +1 -1
  132. package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +1 -0
  133. package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.d.ts +1 -1
  134. package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +5 -4
  135. package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.d.ts +2 -2
  136. package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.js +2 -0
  137. package/lib/products/bot_defender/block/utils.js +1 -2
  138. package/lib/products/bot_defender/filter/DefaultBotDefenderFilter.js +7 -1
  139. package/lib/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +51 -68
  140. package/lib/products/bot_defender/first_party/constants.d.ts +0 -4
  141. package/lib/products/bot_defender/first_party/constants.js +0 -7
  142. package/lib/products/credential_intelligence/CredentialIntelligence.js +42 -63
  143. package/lib/products/credential_intelligence/endpoint/CredentialEndpoint.js +15 -23
  144. package/lib/products/credential_intelligence/endpoint/CredentialEndpointManager.js +9 -22
  145. package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.d.ts +5 -5
  146. package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +22 -33
  147. package/lib/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +8 -18
  148. package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +2 -0
  149. package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.d.ts +1 -1
  150. package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +11 -16
  151. package/lib/products/credential_intelligence/endpoint/hash_protocol/MultistepHashProtocol.js +11 -21
  152. package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepAndMultistepHashProtocol.js +9 -18
  153. package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepHashProtocol.js +13 -25
  154. package/lib/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +4 -14
  155. package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulParser.js +10 -20
  156. package/lib/products/credential_intelligence/endpoint/login_successful/HeaderLoginSuccessfulParser.js +7 -16
  157. package/lib/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +7 -6
  158. package/lib/products/credential_intelligence/endpoint/login_successful/StatusLoginSuccessfulParser.js +3 -13
  159. package/lib/products/credential_intelligence/endpoint/matcher/ExactPathEndpointMatcher.js +2 -0
  160. package/lib/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +2 -0
  161. package/lib/pxde/DefaultDataEnrichment.js +47 -61
  162. package/lib/pxhd/PXHDUtils.js +2 -2
  163. package/lib/risk_api/client/PostRiskApiClientBase.d.ts +7 -12
  164. package/lib/risk_api/client/PostRiskApiClientBase.js +70 -171
  165. package/lib/risk_api/model/RiskActivity.d.ts +5 -45
  166. package/lib/risk_api/risk_response/IRiskResponse.d.ts +1 -0
  167. package/lib/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
  168. package/lib/risk_api/risk_response/RiskResponseBase.js +20 -33
  169. package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.d.ts +1 -1
  170. package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.js +3 -5
  171. package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -0
  172. package/lib/risk_api/risk_response/v3/DefaultRiskResponseV3.js +2 -4
  173. package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -0
  174. package/lib/risk_token/parser/TokenParserBase.js +25 -36
  175. package/lib/risk_token/token/TokenBase.js +24 -29
  176. package/lib/risk_token/token/v2/DefaultTokenV2.js +34 -49
  177. package/lib/risk_token/token/v3/DefaultTokenV3.js +63 -77
  178. package/lib/telemetry/DefaultTelemetry.js +46 -58
  179. package/lib/utils/base64/index.d.ts +0 -3
  180. package/lib/utils/base64/index.js +0 -3
  181. package/lib/utils/cipher/index.d.ts +1 -3
  182. package/lib/utils/cipher/index.js +1 -2
  183. package/lib/utils/constants.d.ts +2 -1
  184. package/lib/utils/constants.js +2 -1
  185. package/lib/utils/hash/index.d.ts +0 -3
  186. package/lib/utils/hash/index.js +0 -3
  187. package/lib/utils/hmac/index.d.ts +0 -2
  188. package/lib/utils/hmac/index.js +0 -2
  189. package/lib/utils/ip_range_checker/index.d.ts +1 -2
  190. package/lib/utils/ip_range_checker/index.js +1 -1
  191. package/lib/utils/request_id_generator/index.d.ts +1 -2
  192. package/lib/utils/request_id_generator/index.js +1 -1
  193. package/lib/utils/url_parser/index.d.ts +0 -1
  194. package/lib/utils/url_parser/index.js +0 -1
  195. package/lib/utils/utils.d.ts +1 -7
  196. package/lib/utils/utils.js +3 -25
  197. package/package.json +12 -6
  198. package/lib/activities/model/Activity.d.ts +0 -13
  199. package/lib/http/impl/index.d.ts +0 -4
  200. package/lib/http/impl/index.js +0 -4
  201. package/lib/http/impl/phin/PhinHttpClient.js +0 -41
  202. package/lib/http/impl/phin/PhinIncomingResponse.js +0 -38
  203. package/lib/utils/cipher/CryptoCipherUtils.js +0 -28
  204. package/lib/utils/cipher/SubtleCryptoCipherUtils.js +0 -47
  205. package/lib/utils/hash/CryptoHashUtils.js +0 -20
  206. package/lib/utils/hash/SubtleCryptoHashUtils.js +0 -31
  207. /package/lib/activities/model/{Activity.js → AsyncActivity.js} +0 -0
  208. /package/lib/activities/model/{ActivityDetails.js → AsyncActivityDetails.js} +0 -0
  209. /package/lib/http/{impl → utils}/FormDataImpl.d.ts +0 -0
  210. /package/lib/http/{impl → utils}/MinimalResponseImpl.d.ts +0 -0
  211. /package/lib/{utils → impl}/base64/AtobBase64Utils.js +0 -0
  212. /package/lib/{utils → impl}/base64/JSBase64Base64Utils.js +0 -0
  213. /package/lib/{http/impl → impl/http}/phin/index.d.ts +0 -0
  214. /package/lib/{http/impl → impl/http}/phin/index.js +0 -0
  215. /package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.js +0 -0
  216. /package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.js +0 -0
@@ -1,18 +1,18 @@
1
- import { removeSensitiveHeaders, transferExistingProperties } from '../utils';
2
- import { joinHeaderValues } from '../http';
1
+ import { ModuleMode, removeSensitiveHeaders, transferExistingProperties } from '../utils';
2
+ import { ProductName } from '../products';
3
3
  import { BLOCK_ACTION_TO_PRODUCT_MAP } from '../blocker';
4
4
  import { Action } from '../action';
5
5
  import { ActivityType } from './ActivityType';
6
- export const createActivity = (activityType, config, context) => {
7
- var _a;
6
+ import { TokenParseResult } from '../risk_token';
7
+ export const createAsyncActivity = (activityType, config, context) => {
8
8
  return {
9
9
  type: activityType,
10
10
  px_app_id: config.appId,
11
11
  url: context.requestData.rawUrl,
12
12
  headers: activityType !== ActivityType.ADDITIONAL_S2S
13
- ? joinHeaderValues(removeSensitiveHeaders(context.requestData.headers, config.sensitiveHeaders))
13
+ ? toHeaderEntryArray(removeSensitiveHeaders(context.requestData.headers, config.sensitiveHeaders))
14
14
  : undefined,
15
- pxhd: (_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.value,
15
+ pxhd: context.pxhd?.value,
16
16
  socket_ip: context.requestData.ip,
17
17
  timestamp: Date.now(),
18
18
  vid: context.vid,
@@ -20,7 +20,8 @@ export const createActivity = (activityType, config, context) => {
20
20
  };
21
21
  };
22
22
  export const createActivityDetails = (activityType, config, context) => {
23
- const genericActivityDetails = createGenericActivityDetails(config, context);
23
+ const commonActivityDetails = createCommonActivityDetails(config, context);
24
+ const commonAsyncActivityDetails = createAsyncActivityCommonDetails(context);
24
25
  let specificActivityDetails = {};
25
26
  switch (activityType) {
26
27
  case ActivityType.PAGE_REQUESTED:
@@ -33,38 +34,43 @@ export const createActivityDetails = (activityType, config, context) => {
33
34
  specificActivityDetails = createAdditionalS2SActivityDetails(config, context);
34
35
  break;
35
36
  }
36
- return Object.assign(genericActivityDetails, specificActivityDetails);
37
+ return Object.assign(commonActivityDetails, commonAsyncActivityDetails, specificActivityDetails);
37
38
  };
38
- export const createGenericActivityDetails = (config, context) => {
39
- const genericActivityDetails = {
39
+ export const createAsyncActivityCommonDetails = (context) => {
40
+ const details = {
41
+ client_uuid: context.uuid,
42
+ };
43
+ addRiskApiDataToAsyncActivityCommonDetails(details, context);
44
+ addResponseDataToAsyncActivityCommonDetails(details, context);
45
+ return details;
46
+ };
47
+ export const createCommonActivityDetails = (config, context) => {
48
+ const details = {
40
49
  module_version: config.moduleVersion,
50
+ // Note: risk_mode currently reflects only Bot Defender mode
51
+ risk_mode: context.productData.bd?.isMonitoredRequest ? ModuleMode.MONITOR : ModuleMode.ACTIVE_BLOCKING,
41
52
  };
42
- if (context.customParameters) {
43
- Object.assign(genericActivityDetails, context.customParameters);
44
- }
45
- transferExistingProperties(context, genericActivityDetails, {
53
+ addRootContextDataToDetails(details, context);
54
+ addRequestDataToDetails(details, context.requestData);
55
+ addTokenDataToDetails(details, context.tokenData);
56
+ addProductDataToDetails(details, context.productData);
57
+ addServerDataToDetails(details, context.serverData);
58
+ addTlsDataToDetails(details, context.tlsData);
59
+ addCustomParametersToDetails(details, context.customParameters);
60
+ return details;
61
+ };
62
+ export const addRootContextDataToDetails = (details, context) => {
63
+ transferExistingProperties(context, details, {
46
64
  requestId: 'request_id',
47
- uuid: 'client_uuid',
48
65
  tokenOrigin: 'cookie_origin',
66
+ vidSource: 'enforcer_vid_source',
49
67
  graphqlData: 'graphql_operations',
50
68
  });
51
- transferExistingProperties(context.requestData, genericActivityDetails, {
52
- httpVersion: 'http_version',
53
- method: 'http_method',
54
- requestCookieNames: 'request_cookie_names',
55
- });
56
- transferExistingProperties(context.riskApiData, genericActivityDetails, {
57
- riskRtt: 'risk_rtt',
58
- });
59
- transferExistingProperties(context.serverData, genericActivityDetails, {
60
- region: 'server_info_region',
61
- datacenter: 'server_info_datacenter',
62
- });
63
- transferExistingProperties(context.response, genericActivityDetails, {
64
- status: 'http_status_code',
65
- });
66
- addProductDataToDetails(genericActivityDetails, context.productData);
67
- return genericActivityDetails;
69
+ };
70
+ export const addCustomParametersToDetails = (details, customParameters) => {
71
+ if (customParameters) {
72
+ Object.assign(details, customParameters);
73
+ }
68
74
  };
69
75
  export const addProductDataToDetails = (details, productData) => {
70
76
  transferExistingProperties(productData.ad, details, {
@@ -73,9 +79,74 @@ export const addProductDataToDetails = (details, productData) => {
73
79
  crossTabSession: 'cross_tab_session',
74
80
  });
75
81
  transferExistingProperties(productData.ci, details, {
82
+ hashedUsername: 'user',
83
+ hashedPassword: 'pass',
76
84
  ciVersion: 'ci_version',
77
85
  ssoStep: 'sso_step',
78
- isCompromised: 'credentials_compromised',
86
+ });
87
+ };
88
+ export const addTlsDataToDetails = (details, tlsData) => {
89
+ transferExistingProperties(tlsData, details, {
90
+ tlsProtocol: 'tls_protocol',
91
+ tlsServer: 'tls_server',
92
+ tlsCipher: 'tls_cipher',
93
+ tlsCiphersSha: 'tls_ciphers_sha',
94
+ tlsExtensionSha: 'tls_extension_sha',
95
+ tlsPreferredCiphers: 'tls_preferred_ciphers',
96
+ tlsJa3Fingerprint: 'tls_ja3_fingerprint',
97
+ });
98
+ };
99
+ export const addServerDataToDetails = (details, serverData) => {
100
+ transferExistingProperties(serverData, details, {
101
+ region: 'server_info_region',
102
+ datacenter: 'server_info_datacenter',
103
+ });
104
+ };
105
+ export const addRequestDataToDetails = (details, requestData) => {
106
+ transferExistingProperties(requestData, details, {
107
+ httpVersion: 'http_version',
108
+ method: 'http_method',
109
+ requestCookieNames: 'request_cookie_names',
110
+ });
111
+ };
112
+ export const addTokenDataToDetails = (details, { token, mobileData }) => {
113
+ if (token) {
114
+ if (token.isValid()) {
115
+ details.px_cookie = token.getPayloadString();
116
+ details.px_cookie_hmac = token.hmac;
117
+ }
118
+ else {
119
+ details.px_orig_cookie = token.getTokenString();
120
+ }
121
+ }
122
+ if (mobileData) {
123
+ transferExistingProperties(mobileData, details, {
124
+ originalToken: 'original_token',
125
+ decodedOriginalToken: 'px_decoded_original_token',
126
+ });
127
+ if (mobileData.originalTokenParseResult === TokenParseResult.DECRYPTION_FAILED) {
128
+ details.original_token_error = 'cookie_decryption_failed';
129
+ }
130
+ else if (mobileData.originalTokenParseResult === TokenParseResult.VALIDATION_FAILED) {
131
+ details.original_token_error = 'cookie_validation_failed';
132
+ }
133
+ }
134
+ };
135
+ export const addRiskApiDataToAsyncActivityCommonDetails = (details, context) => {
136
+ transferExistingProperties(context.riskApiData, details, {
137
+ riskRtt: 'risk_rtt',
138
+ s2sCallReason: 's2s_call_reason',
139
+ });
140
+ if (context.riskApiData.riskResponse?.additionalRiskInfo) {
141
+ details.additional_risk_info = context.riskApiData.riskResponse.additionalRiskInfo;
142
+ }
143
+ if (context.productData[ProductName.CREDENTIAL_INTELLIGENCE]) {
144
+ details.credentials_compromised = context.productData[ProductName.CREDENTIAL_INTELLIGENCE].isCompromised;
145
+ }
146
+ };
147
+ export const addResponseDataToAsyncActivityCommonDetails = (details, context) => {
148
+ transferExistingProperties(context.response, details, {
149
+ status: 'http_status_code',
79
150
  });
80
151
  };
81
152
  export const createPageRequestedActivityDetails = (context) => {
@@ -91,10 +162,9 @@ export const createPageRequestedActivityDetails = (context) => {
91
162
  return details;
92
163
  };
93
164
  export const createBlockActivityDetails = (context) => {
94
- var _a;
95
165
  const details = {};
96
166
  const blockingProduct = BLOCK_ACTION_TO_PRODUCT_MAP.get(context.blockAction);
97
- details.block_reason = (_a = context.reasons) === null || _a === void 0 ? void 0 : _a[blockingProduct];
167
+ details.block_reason = context.reasons?.[blockingProduct];
98
168
  details.simulated_block = context.action === Action.SIMULATED_BLOCK;
99
169
  transferExistingProperties(context, details, {
100
170
  blockAction: 'block_action',
@@ -112,3 +182,9 @@ export const createAdditionalS2SActivityDetails = ({ ciSendRawUsernameOnAddition
112
182
  }
113
183
  return details;
114
184
  };
185
+ export const toHeaderEntryArray = (headers) => {
186
+ return Object.entries(headers).flatMap(([key, values]) => values.map((value) => ({
187
+ name: key,
188
+ value: value,
189
+ })));
190
+ };
@@ -1,3 +1,3 @@
1
1
  import { ConfigurationParams } from '../config';
2
2
  import { ReadonlyContext } from '../context';
3
- export type AdditionalActivityHandler = <Req, Res>(config: ConfigurationParams<Req, Res>, context: ReadonlyContext<Req, Res>, request: Req) => void | Promise<void>;
3
+ export type AdditionalActivityHandler<Req, Res> = (config: ConfigurationParams<Req, Res>, context: ReadonlyContext<Req, Res>, request: Req) => void | Promise<void>;
@@ -1,22 +1,14 @@
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
  export var AdditionalActivityHandlerUtils;
11
2
  (function (AdditionalActivityHandlerUtils) {
12
- AdditionalActivityHandlerUtils.invokeAdditionalActivityHandler = (config, context) => __awaiter(this, void 0, void 0, function* () {
3
+ AdditionalActivityHandlerUtils.invokeAdditionalActivityHandler = async (config, context) => {
13
4
  if (config.additionalActivityHandler && typeof config.additionalActivityHandler === 'function') {
14
5
  try {
15
- yield config.additionalActivityHandler(config.toParams(), context, context.requestData.request.getUnderlyingRequest());
6
+ config.logger.debug('calling additional activity handler');
7
+ await config.additionalActivityHandler(config.toParams(), context, context.requestData.request.getUnderlyingRequest());
16
8
  }
17
9
  catch (e) {
18
10
  config.logger.error(`caught additional activity handler error - ${e}`);
19
11
  }
20
12
  }
21
- });
13
+ };
22
14
  })(AdditionalActivityHandlerUtils || (AdditionalActivityHandlerUtils = {}));
@@ -73,8 +73,9 @@ export type ConfigurationParams<Req, Res> = {
73
73
  px_sensitive_graphql_operation_types?: Array<'query' | 'mutation' | 'subscription' | GraphQLOperationType>;
74
74
  px_cors_support_enabled?: boolean;
75
75
  px_cors_preflight_request_filter_enabled?: boolean;
76
+ px_logger_auth_token?: string;
76
77
  px_extract_ip?: () => {};
77
- px_additional_activity_handler?: AdditionalActivityHandler;
78
+ px_additional_activity_handler?: AdditionalActivityHandler<Req, Res>;
78
79
  px_enrich_custom_parameters?: CustomParametersFunction<Req, Res>;
79
80
  px_login_successful_custom_callback?: CustomLoginSuccessfulCallback<Res>;
80
81
  px_cors_custom_preflight_handler?: CustomPreflightHandler<Req>;
@@ -114,4 +114,5 @@ export const DEFAULT_CONFIGURATIONS = {
114
114
  px_cors_custom_preflight_handler: null,
115
115
  px_cors_preflight_request_filter_enabled: false,
116
116
  px_cors_create_custom_block_response_headers: null,
117
+ px_logger_auth_token: '',
117
118
  };
@@ -207,7 +207,7 @@ export interface IConfiguration<Req, Res, ParamsType extends ConfigurationParams
207
207
  /**
208
208
  * A function that will be called after the asynchronous activities are sent to the backend.
209
209
  */
210
- readonly additionalActivityHandler: AdditionalActivityHandler;
210
+ readonly additionalActivityHandler: AdditionalActivityHandler<Req, Res>;
211
211
  /**
212
212
  * Whether cors support feature should be enabled.
213
213
  */
@@ -301,6 +301,10 @@ export interface IConfiguration<Req, Res, ParamsType extends ConfigurationParams
301
301
  * The default login successful custom callback to use if none is defined for an endpoint.
302
302
  */
303
303
  readonly ciDefaultLoginSuccessfulCustomCallback: CustomLoginSuccessfulCallback<Res>;
304
+ /**
305
+ * The authentication token for the logging service.
306
+ */
307
+ readonly loggerAuthToken: string;
304
308
  /**
305
309
  * Returns an object representation of the current configuration.
306
310
  */
@@ -63,7 +63,7 @@ export declare abstract class StaticConfigurationBase<Req, Res, ParamsType exten
63
63
  get sensitiveGraphqlOperationNames(): string[];
64
64
  get sensitiveGraphqlOperationTypes(): string[];
65
65
  get enrichCustomParameters(): CustomParametersFunction<Req, Res>;
66
- get additionalActivityHandler(): AdditionalActivityHandler;
66
+ get additionalActivityHandler(): AdditionalActivityHandler<Req, Res>;
67
67
  get altBackendCaptchaUrl(): string;
68
68
  get corsSupportEnabled(): boolean;
69
69
  get corsCustomPreflightHandler(): CustomPreflightHandler<Req>;
@@ -76,6 +76,7 @@ export declare abstract class StaticConfigurationBase<Req, Res, ParamsType exten
76
76
  get jwtHeaderName(): string;
77
77
  get jwtHeaderUserIdFieldName(): string;
78
78
  get ciEnabled(): boolean;
79
+ get loggerAuthToken(): string;
79
80
  get ciEndpoints(): CredentialEndpointConfiguration<Req, Res>[];
80
81
  get ciCompromisedCredentialsHeaderName(): string;
81
82
  get ciSendRawUsernameOnAdditionalS2SActivity(): boolean;
@@ -2,8 +2,10 @@ import { DEFAULT_CONFIGURATIONS } from './DefaultConfigurations';
2
2
  import { LoggerSeverity, DefaultLogger } from '../logger';
3
3
  import { ModuleMode, getScoreApiDomain, getCollectorDomain, isValidEnumValue, EnforcerError, CORE_MODULE_VERSION, } from '../utils';
4
4
  export class StaticConfigurationBase {
5
+ configParams;
6
+ internalLogger;
5
7
  constructor(params, defaultParams) {
6
- this.configParams = this.initialize(params, Object.assign(Object.assign({}, DEFAULT_CONFIGURATIONS), defaultParams));
8
+ this.configParams = this.initialize(params, { ...DEFAULT_CONFIGURATIONS, ...defaultParams });
7
9
  this.internalLogger = new DefaultLogger(this.configParams.px_logger_severity);
8
10
  }
9
11
  initialize(params, defaultParams) {
@@ -236,6 +238,9 @@ export class StaticConfigurationBase {
236
238
  get ciEnabled() {
237
239
  return this.configParams.px_login_credentials_extraction_enabled;
238
240
  }
241
+ get loggerAuthToken() {
242
+ return this.configParams.px_logger_auth_token;
243
+ }
239
244
  get ciEndpoints() {
240
245
  return this.configParams.px_login_credentials_extraction;
241
246
  }
@@ -9,7 +9,7 @@ import { ICookieParser, IRequestIdGenerator, VidSource } from '../utils';
9
9
  import { IContext, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
10
10
  import { ProductData, ProductName } from '../products';
11
11
  import { Action } from '../action';
12
- import { IURLParser } from '../utils/url_parser';
12
+ import { IURLParser } from '../utils';
13
13
  export type DefaultContextOptions = {
14
14
  cookieParser?: ICookieParser;
15
15
  requestIdGenerator: IRequestIdGenerator;
@@ -4,8 +4,30 @@ import { TokenOrigin, TokenParseResult } from '../risk_token';
4
4
  import { RiskApiCallResult } from '../risk_api';
5
5
  import { COOKIE_HEADER_NAME, toReadonlyHeaders, USER_AGENT_HEADER_NAME, } from '../http';
6
6
  import { StringSplitCookieParser, PXHD_COOKIE_NAME, PXVID_COOKIE_NAME, X_PX_AUTHORIZATION_HEADER_NAME, } from '../utils';
7
- import { DefaultUrlParser } from '../utils/url_parser';
7
+ import { DefaultUrlParser } from '../impl/url_parser/DefaultUrlParser';
8
8
  export class DefaultContext {
9
+ requestId;
10
+ tokenOrigin;
11
+ requestData;
12
+ tokenData;
13
+ riskApiData;
14
+ tlsData;
15
+ serverData;
16
+ productData;
17
+ uuid;
18
+ vid;
19
+ vidSource;
20
+ action;
21
+ reasons;
22
+ score;
23
+ blockAction;
24
+ pxhd;
25
+ pxde;
26
+ pxdeVerified;
27
+ customParameters;
28
+ response;
29
+ config;
30
+ urlParser;
9
31
  constructor(config, request, options) {
10
32
  this.config = config;
11
33
  this.urlParser = options.urlParser || new DefaultUrlParser();
@@ -40,7 +62,19 @@ export class DefaultContext {
40
62
  const readOnlyHeaders = toReadonlyHeaders(headers);
41
63
  const userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
42
64
  const ip = this.extractIpFromHeader(config, readOnlyHeaders) || request.clientIP;
43
- return { url, rawUrl, method, headers: readOnlyHeaders, cookies, ip, userAgent, requestCookieNames, request };
65
+ const httpVersion = request.httpVersion;
66
+ return {
67
+ url,
68
+ rawUrl,
69
+ method,
70
+ headers: readOnlyHeaders,
71
+ cookies,
72
+ ip,
73
+ userAgent,
74
+ requestCookieNames,
75
+ request,
76
+ httpVersion,
77
+ };
44
78
  }
45
79
  static getCookies(cookieParser, ...cookieHeaderValues) {
46
80
  const cookies = {};
@@ -50,8 +84,7 @@ export class DefaultContext {
50
84
  return cookies;
51
85
  }
52
86
  extractUserAgentFromHeader(config, headers) {
53
- var _a;
54
- let userAgent = ((_a = headers[USER_AGENT_HEADER_NAME]) === null || _a === void 0 ? void 0 : _a[0]) || '';
87
+ let userAgent = headers[USER_AGENT_HEADER_NAME]?.[0] || '';
55
88
  if (userAgent.length > config.userAgentMaxLength) {
56
89
  userAgent = userAgent.substring(0, config.userAgentMaxLength);
57
90
  }
@@ -60,8 +93,7 @@ export class DefaultContext {
60
93
  extractIpFromHeader(config, headers) {
61
94
  let ip;
62
95
  config.ipHeaders.some((ipHeader) => {
63
- var _a;
64
- const headerValue = (_a = headers[ipHeader]) === null || _a === void 0 ? void 0 : _a[0];
96
+ const headerValue = headers[ipHeader]?.[0];
65
97
  if (headerValue) {
66
98
  ip = headerValue;
67
99
  return true;
@@ -73,8 +105,8 @@ export class DefaultContext {
73
105
  return request.headers.get(X_PX_AUTHORIZATION_HEADER_NAME) ? TokenOrigin.HEADER : TokenOrigin.COOKIE;
74
106
  }
75
107
  setCookiesOnContext() {
76
- this.vid = this.requestData.cookies[PXVID_COOKIE_NAME] || '';
77
- const pxhdCookie = this.requestData.cookies[PXHD_COOKIE_NAME] || '';
108
+ this.vid = this.requestData.cookies[PXVID_COOKIE_NAME];
109
+ const pxhdCookie = this.requestData.cookies[PXHD_COOKIE_NAME];
78
110
  if (pxhdCookie) {
79
111
  this.pxhd = {
80
112
  value: pxhdCookie,
@@ -4,6 +4,10 @@ export type RiskApiData = {
4
4
  * The result of the risk API call.
5
5
  */
6
6
  riskApiCallResult: RiskApiCallResult;
7
+ /**
8
+ * The reason for the Risk API call.
9
+ */
10
+ s2sCallReason?: string;
7
11
  /**
8
12
  * An interface representing the risk API response.
9
13
  */
@@ -1,15 +1,9 @@
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 { ACCESS_CONTROL_REQUEST_METHOD_HEADER, ORIGIN_HEADER } from './constants';
11
2
  import { HttpMethod } from '../http';
12
3
  export class DefaultCors {
4
+ customBlockResponseHeaders;
5
+ customPreflightHandler;
6
+ logger;
13
7
  constructor(config) {
14
8
  this.customBlockResponseHeaders = config.corsCreateCustomBlockResponseHeaders;
15
9
  this.customPreflightHandler = config.corsCustomPreflightHandler;
@@ -21,34 +15,30 @@ export class DefaultCors {
21
15
  requestData.headers[ORIGIN_HEADER] &&
22
16
  requestData.headers[ACCESS_CONTROL_REQUEST_METHOD_HEADER]);
23
17
  }
24
- runPreflightCustomHandler(context) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- if (this.customPreflightHandler && typeof this.customPreflightHandler === 'function') {
27
- try {
28
- return yield this.customPreflightHandler(context.requestData.request.getUnderlyingRequest());
29
- }
30
- catch (e) {
31
- this.logger.debug(`Exception occurred while executing custom preflight handler: ${e}`);
32
- }
18
+ async runPreflightCustomHandler(context) {
19
+ if (this.customPreflightHandler && typeof this.customPreflightHandler === 'function') {
20
+ try {
21
+ return await this.customPreflightHandler(context.requestData.request.getUnderlyingRequest());
33
22
  }
34
- return null;
35
- });
23
+ catch (e) {
24
+ this.logger.debug(`Exception occurred while executing custom preflight handler: ${e}`);
25
+ }
26
+ }
27
+ return null;
36
28
  }
37
29
  isCorsRequest(context) {
38
30
  return !!context.requestData.headers[ORIGIN_HEADER];
39
31
  }
40
- getCorsBlockHeaders(context) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (this.customBlockResponseHeaders && typeof this.customBlockResponseHeaders === 'function') {
43
- try {
44
- return yield this.customBlockResponseHeaders(context.requestData.request.getUnderlyingRequest());
45
- }
46
- catch (e) {
47
- this.logger.debug(`Exception occurred in px_cors_create_custom_block_response_headers custom function: ${e}`);
48
- }
32
+ async getCorsBlockHeaders(context) {
33
+ if (this.customBlockResponseHeaders && typeof this.customBlockResponseHeaders === 'function') {
34
+ try {
35
+ return await this.customBlockResponseHeaders(context.requestData.request.getUnderlyingRequest());
36
+ }
37
+ catch (e) {
38
+ this.logger.debug(`Exception occurred in px_cors_create_custom_block_response_headers custom function: ${e}`);
49
39
  }
50
- return this.getDefaultCorsHeaders(context);
51
- });
40
+ }
41
+ return this.getDefaultCorsHeaders(context);
52
42
  }
53
43
  getDefaultCorsHeaders(context) {
54
44
  return {
@@ -1,18 +1,9 @@
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
  export var CustomParametersUtils;
11
2
  (function (CustomParametersUtils) {
12
- CustomParametersUtils.createCustomParameters = (config, context) => __awaiter(this, void 0, void 0, function* () {
3
+ CustomParametersUtils.createCustomParameters = async (config, context) => {
13
4
  if (config.enrichCustomParameters && typeof config.enrichCustomParameters === 'function') {
14
5
  try {
15
- const parameters = yield config.enrichCustomParameters(config.toParams(), context.requestData.request.getUnderlyingRequest());
6
+ const parameters = await config.enrichCustomParameters(config.toParams(), context.requestData.request.getUnderlyingRequest());
16
7
  return CustomParametersUtils.normalizeCustomParams(parameters);
17
8
  }
18
9
  catch (e) {
@@ -20,7 +11,7 @@ export var CustomParametersUtils;
20
11
  }
21
12
  }
22
13
  return null;
23
- });
14
+ };
24
15
  CustomParametersUtils.normalizeCustomParams = (customParameters) => {
25
16
  const normalizedParams = {};
26
17
  if (customParameters && typeof customParameters === 'object') {
@@ -13,6 +13,7 @@ export declare abstract class EnforcerBase<TokenV extends TokenVersion, Req, Res
13
13
  protected readonly filterFlow: IPhase<Req, Res>;
14
14
  protected readonly enforceFlow: IPhase<Req, Res>;
15
15
  protected readonly postEnforceFlow: IPhase<Req, Res>;
16
+ protected readonly endEnforcerFlow: IPhase<Req, Res>;
16
17
  protected readonly activityClient: IActivityClient<Req, Res>;
17
18
  /**
18
19
  * Constructs the concrete request context given the provided EnforceArgs.
@@ -42,7 +43,7 @@ export declare abstract class EnforcerBase<TokenV extends TokenVersion, Req, Res
42
43
  * @returns Promise<Res> - A Promise resolving to Res.
43
44
  * @protected
44
45
  */
45
- protected abstract convertToRes(response: IMinimalResponse): Promise<Res>;
46
+ protected abstract convertToRes(response: IMinimalResponse, ...args: EnforceArgs): Promise<Res>;
46
47
  /**
47
48
  * Converts the Res object into the IOutgoingResponse interface.
48
49
  * @param args - PostEnforceArgs