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,14 +1,7 @@
1
1
  import { ContentType, CONTENT_TYPE_HEADER_NAME } from '../../../http';
2
- export const EMPTY_GIF = [
3
- 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00, 0x80, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
4
- 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x3b,
5
- ];
6
2
  export const X_PX_ENFORCER_TRUE_IP_HEADER_NAME = 'x-px-enforcer-true-ip';
7
3
  export const FIRST_PARTY_HEADER_NAME = 'x-px-first-party';
8
4
  export const FIRST_PARTY_HEADER_VALUE = '1';
9
- export const FIRST_PARTY_SENSOR_SUFFIX = '/init.js';
10
- export const FIRST_PARTY_CAPTCHA_SUFFIX = '/captcha';
11
- export const FIRST_PARTY_XHR_SUFFIX = '/xhr';
12
5
  export const DEFAULT_CLIENT_RESPONSE_OPTIONS = {
13
6
  body: '',
14
7
  status: 200,
@@ -1,76 +1,56 @@
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
- import { ActivityType, createActivity, ACTIVITIES_ENDPOINT } from '../../activities';
2
+ import { ActivityType, createAsyncActivity, ACTIVITIES_ENDPOINT } from '../../activities';
12
3
  import { CredentialEndpoint, CredentialEndpointManager, CredentialExtractorFactory, CredentialIntelligenceEndpointMatcherFactory, CredentialIntelligenceHashProtocolFactory, LoginSuccessfulParserFactory, } from './endpoint';
13
4
  import { ADDITIONAL_S2S_ACTIVITY_HEADER_NAME, ADDITIONAL_S2S_URL_HEADER_NAME, COMPROMISED_CREDENTIALS_HEADER_VALUE, } from './constants';
14
5
  export class CredentialIntelligence {
6
+ config;
7
+ endpointManager;
15
8
  constructor(config, hashUtils) {
16
9
  this.config = config;
17
10
  this.endpointManager = new CredentialEndpointManager(this.initializeCredentialIntelligenceEndpoints(config, hashUtils));
18
11
  }
19
- enrichContextFromRequest(context) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const endpointIndex = this.endpointManager.getEndpointIndex(context);
22
- if (endpointIndex === -1) {
23
- return null;
24
- }
25
- const data = yield this.endpointManager.getCredentialsData(endpointIndex, context);
26
- if (!data) {
27
- return null;
28
- }
29
- return Object.assign(Object.assign({}, data), { endpointIndex, action: Action.TRIGGER_RISK_API, reason: 'sensitive_route' });
30
- });
12
+ async enrichContextFromRequest(context) {
13
+ const endpointIndex = this.endpointManager.getEndpointIndex(context);
14
+ if (endpointIndex === -1) {
15
+ return null;
16
+ }
17
+ const data = await this.endpointManager.getCredentialsData(endpointIndex, context);
18
+ if (!data) {
19
+ return null;
20
+ }
21
+ return { ...data, endpointIndex, action: Action.TRIGGER_RISK_API, reason: 'sensitive_route' };
31
22
  }
32
- enrichContextFromRiskApi(context) {
33
- var _a, _b;
34
- return __awaiter(this, void 0, void 0, function* () {
35
- if (!context.productData.ci) {
36
- return;
37
- }
38
- const isCompromised = !!((_b = (_a = context.riskApiData.riskResponse) === null || _a === void 0 ? void 0 : _a.dataEnrichment) === null || _b === void 0 ? void 0 : _b.breached_account);
39
- return { action: undefined, reason: undefined, isCompromised };
40
- });
23
+ async enrichContextFromRiskApi(context) {
24
+ if (!context.productData.ci) {
25
+ return;
26
+ }
27
+ const isCompromised = !!context.riskApiData.riskResponse?.dataEnrichment?.breached_account;
28
+ return { action: undefined, reason: undefined, isCompromised };
41
29
  }
42
- modifyIncomingRequest(context) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- if (!context.productData.ci) {
45
- return;
46
- }
47
- const { productData: { ci: { isCompromised }, }, requestData: { request }, } = context;
48
- if (isCompromised) {
49
- this.setCompromisedCredentialHeader(request);
50
- }
51
- if (this.shouldSetAdditionalS2SActivityHeaders()) {
52
- this.setAdditionalS2SActivityHeaders(request, context);
53
- }
54
- });
30
+ async modifyIncomingRequest(context) {
31
+ if (!context.productData.ci) {
32
+ return;
33
+ }
34
+ const { productData: { ci: { isCompromised }, }, requestData: { request }, } = context;
35
+ if (isCompromised) {
36
+ this.setCompromisedCredentialHeader(request);
37
+ }
38
+ if (this.shouldSetAdditionalS2SActivityHeaders()) {
39
+ this.setAdditionalS2SActivityHeaders(request, context);
40
+ }
55
41
  }
56
- enrichContextFromResponse(context) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- if (!context.productData.ci) {
59
- return;
60
- }
61
- return { isLoginSuccessful: yield this.isLoginSuccessful(context) };
62
- });
42
+ async enrichContextFromResponse(context) {
43
+ if (!context.productData.ci) {
44
+ return;
45
+ }
46
+ return { isLoginSuccessful: await this.isLoginSuccessful(context) };
63
47
  }
64
- modifyOutgoingResponse(context) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- // intentionally left blank
67
- });
48
+ async modifyOutgoingResponse(context) {
49
+ // intentionally left blank
68
50
  }
69
- isLoginSuccessful(context) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- const { endpointIndex } = context.productData.ci;
72
- return yield this.endpointManager.isLoginSuccessful(endpointIndex, context);
73
- });
51
+ async isLoginSuccessful(context) {
52
+ const { endpointIndex } = context.productData.ci;
53
+ return await this.endpointManager.isLoginSuccessful(endpointIndex, context);
74
54
  }
75
55
  setCompromisedCredentialHeader(request) {
76
56
  request.headers.set(this.config.ciCompromisedCredentialsHeaderName, COMPROMISED_CREDENTIALS_HEADER_VALUE);
@@ -79,16 +59,15 @@ export class CredentialIntelligence {
79
59
  return !this.config.ciAutomaticAdditionalS2SEnabled && this.config.ciAdditionalS2SHeaderEnabled;
80
60
  }
81
61
  setAdditionalS2SActivityHeaders(request, context) {
82
- const activity = createActivity(ActivityType.ADDITIONAL_S2S, this.config, context);
62
+ const activity = createAsyncActivity(ActivityType.ADDITIONAL_S2S, this.config, context);
83
63
  request.headers.set(ADDITIONAL_S2S_ACTIVITY_HEADER_NAME, JSON.stringify(activity));
84
64
  request.headers.set(ADDITIONAL_S2S_URL_HEADER_NAME, `${this.config.backendCollectorUrl}${ACTIVITIES_ENDPOINT}`);
85
65
  }
86
66
  initializeCredentialIntelligenceEndpoints(config, hashUtils) {
87
67
  return config.ciEndpoints.map((endpointConfig) => {
88
- var _a;
89
68
  const matcher = CredentialIntelligenceEndpointMatcherFactory.create(endpointConfig);
90
69
  const extractor = CredentialExtractorFactory.create(endpointConfig);
91
- const protocol = CredentialIntelligenceHashProtocolFactory.create(((_a = endpointConfig.protocol) !== null && _a !== void 0 ? _a : config.ciDefaultVersion), hashUtils);
70
+ const protocol = CredentialIntelligenceHashProtocolFactory.create((endpointConfig.protocol ?? config.ciDefaultVersion), hashUtils);
92
71
  const loginSuccessfulParser = LoginSuccessfulParserFactory.create(config, endpointConfig);
93
72
  return new CredentialEndpoint(config, matcher, extractor, protocol, loginSuccessfulParser);
94
73
  });
@@ -1,13 +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 class CredentialEndpoint {
2
+ config;
3
+ matcher;
4
+ extractor;
5
+ protocol;
6
+ loginSuccessfulParser;
11
7
  constructor(config, matcher, extractor, protocol, loginSuccessfulParser) {
12
8
  this.config = config;
13
9
  this.matcher = matcher;
@@ -18,20 +14,16 @@ export class CredentialEndpoint {
18
14
  matches(requestData) {
19
15
  return this.matcher.matches(requestData);
20
16
  }
21
- getCredentialData(request) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const credentials = yield this.extractor.extractCredentials(request);
24
- if (!(credentials === null || credentials === void 0 ? void 0 : credentials.user) && !(credentials === null || credentials === void 0 ? void 0 : credentials.pass)) {
25
- this.config.logger.debug('unable to extract credentials');
26
- return null;
27
- }
28
- this.config.logger.debug(`successfully extracted credentials`);
29
- return yield this.protocol.hashCredentials(credentials);
30
- });
17
+ async getCredentialData(request) {
18
+ const credentials = await this.extractor.extractCredentials(request);
19
+ if (!credentials?.user && !credentials?.pass) {
20
+ this.config.logger.debug('unable to extract credentials');
21
+ return null;
22
+ }
23
+ this.config.logger.debug(`successfully extracted credentials`);
24
+ return await this.protocol.hashCredentials(credentials);
31
25
  }
32
- isLoginSuccessful(response) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- return this.loginSuccessfulParser.isLoginSuccessful(response);
35
- });
26
+ async isLoginSuccessful(response) {
27
+ return this.loginSuccessfulParser.isLoginSuccessful(response);
36
28
  }
37
29
  }
@@ -1,32 +1,19 @@
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 class CredentialEndpointManager {
2
+ config;
3
+ endpoints;
11
4
  constructor(endpoints) {
12
5
  this.endpoints = endpoints;
13
6
  }
14
7
  getEndpointIndex({ requestData }) {
15
8
  return this.endpoints.findIndex((endpoint) => endpoint.matches(requestData));
16
9
  }
17
- getCredentialsData(endpointIndex, { requestData }) {
18
- var _a;
19
- return __awaiter(this, void 0, void 0, function* () {
20
- return yield ((_a = this.endpoints[endpointIndex]) === null || _a === void 0 ? void 0 : _a.getCredentialData(requestData.request));
21
- });
10
+ async getCredentialsData(endpointIndex, { requestData }) {
11
+ return await this.endpoints[endpointIndex]?.getCredentialData(requestData.request);
22
12
  }
23
- isLoginSuccessful(endpointIndex, { response }) {
24
- var _a;
25
- return __awaiter(this, void 0, void 0, function* () {
26
- if (!response) {
27
- return undefined;
28
- }
29
- return yield ((_a = this.endpoints[endpointIndex]) === null || _a === void 0 ? void 0 : _a.isLoginSuccessful(response));
30
- });
13
+ async isLoginSuccessful(endpointIndex, { response }) {
14
+ if (!response) {
15
+ return undefined;
16
+ }
17
+ return await this.endpoints[endpointIndex]?.isLoginSuccessful(response);
31
18
  }
32
19
  }
@@ -1,15 +1,15 @@
1
1
  import { DeepReadonly } from 'ts-essentials';
2
- import { IFormData, IIncomingRequest } from '../../../../http';
2
+ import { IFormData, IIncomingRequest, IURLSearchParams } from '../../../../http';
3
3
  import { Credentials } from '../../model';
4
4
  import { ICredentialExtractor } from './ICredentialExtractor';
5
- export declare class BodyCredentialExtractor implements ICredentialExtractor<unknown> {
5
+ export declare class BodyCredentialExtractor<Req> implements ICredentialExtractor<Req> {
6
6
  private readonly userField;
7
7
  private readonly passField;
8
8
  constructor(userField: string, passField: string);
9
- extractCredentials(request: DeepReadonly<IIncomingRequest<unknown>>): Promise<Credentials | null>;
10
- protected extractFromBody(contentType: string, request: DeepReadonly<IIncomingRequest<unknown>>): Promise<Credentials>;
9
+ extractCredentials(request: DeepReadonly<IIncomingRequest<Req>>): Promise<Credentials | null>;
10
+ protected extractFromBody(contentType: string, request: DeepReadonly<IIncomingRequest<Req>>): Promise<Credentials>;
11
11
  protected extractFromJson(json: any): Credentials;
12
- protected extractFromUrlEncoded(params: URLSearchParams): Credentials;
12
+ protected extractFromUrlEncoded(params: IURLSearchParams): Credentials;
13
13
  protected extractFromMultipart(formData: IFormData): Credentials;
14
14
  private formDataEntryValueToString;
15
15
  }
@@ -1,44 +1,33 @@
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 { CONTENT_TYPE_HEADER_NAME, ContentType } from '../../../../http';
11
2
  import { getPropertyFromObject } from '../../../../utils';
12
3
  export class BodyCredentialExtractor {
4
+ userField;
5
+ passField;
13
6
  constructor(userField, passField) {
14
7
  this.userField = userField;
15
8
  this.passField = passField;
16
9
  }
17
- extractCredentials(request) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- try {
20
- const contentType = request.headers.get(CONTENT_TYPE_HEADER_NAME);
21
- const credentials = yield this.extractFromBody(contentType, request);
22
- return typeof (credentials === null || credentials === void 0 ? void 0 : credentials.user) === 'string' || typeof (credentials === null || credentials === void 0 ? void 0 : credentials.pass) === 'string' ? credentials : null;
23
- }
24
- catch (e) {
25
- return null;
26
- }
27
- });
28
- }
29
- extractFromBody(contentType, request) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- if (contentType.includes('json')) {
32
- return this.extractFromJson(yield request.json());
33
- }
34
- else if (contentType.includes(ContentType.APPLICATION_X_WWW_FORM_URL_ENCODED)) {
35
- return this.extractFromUrlEncoded(yield request.formUrlEncoded());
36
- }
37
- else if (contentType.includes(ContentType.MULTIPART_FORM_DATA)) {
38
- return this.extractFromMultipart(yield request.formData());
39
- }
10
+ async extractCredentials(request) {
11
+ try {
12
+ const contentType = request.headers.get(CONTENT_TYPE_HEADER_NAME);
13
+ const credentials = await this.extractFromBody(contentType, request);
14
+ return typeof credentials?.user === 'string' || typeof credentials?.pass === 'string' ? credentials : null;
15
+ }
16
+ catch (e) {
40
17
  return null;
41
- });
18
+ }
19
+ }
20
+ async extractFromBody(contentType, request) {
21
+ if (contentType.includes('json')) {
22
+ return this.extractFromJson(await request.json());
23
+ }
24
+ else if (contentType.includes(ContentType.APPLICATION_X_WWW_FORM_URL_ENCODED)) {
25
+ return this.extractFromUrlEncoded(await request.formUrlEncoded());
26
+ }
27
+ else if (contentType.includes(ContentType.MULTIPART_FORM_DATA)) {
28
+ return this.extractFromMultipart(await request.formData());
29
+ }
30
+ return null;
42
31
  }
43
32
  extractFromJson(json) {
44
33
  if (!json) {
@@ -1,24 +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 class CustomCredentialExtractor {
2
+ callback;
11
3
  constructor(callback) {
12
4
  this.callback = callback;
13
5
  }
14
- extractCredentials(request) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- try {
17
- return yield this.callback(request.getUnderlyingRequest());
18
- }
19
- catch (e) {
20
- return null;
21
- }
22
- });
6
+ async extractCredentials(request) {
7
+ try {
8
+ return await this.callback(request.getUnderlyingRequest());
9
+ }
10
+ catch (e) {
11
+ return null;
12
+ }
23
13
  }
24
14
  }
@@ -1,4 +1,6 @@
1
1
  export class HeaderCredentialExtractor {
2
+ userField;
3
+ passField;
2
4
  constructor(userField, passField) {
3
5
  this.userField = userField;
4
6
  this.passField = passField;
@@ -1,6 +1,6 @@
1
+ import { DeepReadonly } from 'ts-essentials';
1
2
  import { ICredentialExtractor } from './ICredentialExtractor';
2
3
  import { Credentials } from '../../model';
3
- import { DeepReadonly } from 'ts-essentials';
4
4
  import { IIncomingRequest } from '../../../../http';
5
5
  export declare class QueryParamCredentialExtractor<Req> implements ICredentialExtractor<Req> {
6
6
  protected readonly userField: string;
@@ -1,23 +1,18 @@
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
- };
1
+ import { URLUtils } from '../../../../http';
10
2
  export class QueryParamCredentialExtractor {
3
+ userField;
4
+ passField;
11
5
  constructor(userField, passField) {
12
6
  this.userField = userField;
13
7
  this.passField = passField;
14
8
  }
15
- extractCredentials(request) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { searchParams } = new URL(request.url);
18
- const user = searchParams.get(this.userField);
19
- const pass = searchParams.get(this.passField);
20
- return typeof user === 'string' || typeof pass === 'string' ? { user, pass } : null;
21
- });
9
+ async extractCredentials(request) {
10
+ const { searchParams } = URLUtils.parseURL(request.url);
11
+ if (!searchParams) {
12
+ return null;
13
+ }
14
+ const user = searchParams.get(this.userField);
15
+ const pass = searchParams.get(this.passField);
16
+ return typeof user === 'string' || typeof pass === 'string' ? { user, pass } : null;
22
17
  }
23
18
  }
@@ -1,30 +1,20 @@
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 { Algorithm } from '../../../../utils';
11
2
  import { SsoStep } from './SsoStep';
12
3
  import { CredentialIntelligenceVersion } from './CredentialIntelligenceVersion';
13
4
  export class MultistepHashProtocol {
5
+ hashUtils;
14
6
  constructor(hashUtils) {
15
7
  this.hashUtils = hashUtils;
16
8
  }
17
- hashCredentials({ user, pass }) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const rawUsername = user !== null && user !== void 0 ? user : null;
20
- const hashedPassword = typeof pass === 'string' ? yield this.hashUtils.hashString(pass, Algorithm.SHA256) : null;
21
- return {
22
- rawUsername,
23
- hashedUsername: rawUsername,
24
- hashedPassword,
25
- ciVersion: CredentialIntelligenceVersion.MULTI_STEP,
26
- ssoStep: user ? SsoStep.USER : SsoStep.PASS,
27
- };
28
- });
9
+ async hashCredentials({ user, pass }) {
10
+ const rawUsername = user ?? null;
11
+ const hashedPassword = typeof pass === 'string' ? await this.hashUtils.hashString(pass, Algorithm.SHA256) : null;
12
+ return {
13
+ rawUsername,
14
+ hashedUsername: rawUsername,
15
+ hashedPassword,
16
+ ciVersion: CredentialIntelligenceVersion.MULTI_STEP,
17
+ ssoStep: user ? SsoStep.USER : SsoStep.PASS,
18
+ };
29
19
  }
30
20
  }
@@ -1,25 +1,16 @@
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 class SingleStepAndMultistepHashProtocol {
2
+ singleStepHashProtocol;
3
+ multistepHashProtocol;
11
4
  constructor(singleStepHashProtocol, multistepHashProtocol) {
12
5
  this.singleStepHashProtocol = singleStepHashProtocol;
13
6
  this.multistepHashProtocol = multistepHashProtocol;
14
7
  }
15
- hashCredentials(credentials) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- if (credentials.user && credentials.pass) {
18
- return this.singleStepHashProtocol.hashCredentials(credentials);
19
- }
20
- else {
21
- return this.multistepHashProtocol.hashCredentials(credentials);
22
- }
23
- });
8
+ async hashCredentials(credentials) {
9
+ if (credentials.user && credentials.pass) {
10
+ return this.singleStepHashProtocol.hashCredentials(credentials);
11
+ }
12
+ else {
13
+ return this.multistepHashProtocol.hashCredentials(credentials);
14
+ }
24
15
  }
25
16
  }
@@ -1,30 +1,20 @@
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 { Algorithm, isEmailAddress } from '../../../../utils';
11
2
  import { CredentialIntelligenceVersion } from './CredentialIntelligenceVersion';
12
3
  export class SingleStepHashProtocol {
4
+ hashUtils;
13
5
  constructor(hashUtils) {
14
6
  this.hashUtils = hashUtils;
15
7
  }
16
- hashCredentials({ user, pass }) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const normalizedUsername = isEmailAddress(user) ? this.normalizeEmailAddress(user) : user;
19
- const hashedUsername = yield this.sha256(normalizedUsername);
20
- const hashedPassword = yield this.sha256(hashedUsername + (yield this.sha256(pass)));
21
- return {
22
- ciVersion: CredentialIntelligenceVersion.SINGLE_STEP,
23
- rawUsername: user,
24
- hashedUsername,
25
- hashedPassword,
26
- };
27
- });
8
+ async hashCredentials({ user, pass }) {
9
+ const normalizedUsername = isEmailAddress(user) ? this.normalizeEmailAddress(user) : user;
10
+ const hashedUsername = await this.sha256(normalizedUsername);
11
+ const hashedPassword = await this.sha256(hashedUsername + (await this.sha256(pass)));
12
+ return {
13
+ ciVersion: CredentialIntelligenceVersion.SINGLE_STEP,
14
+ rawUsername: user,
15
+ hashedUsername,
16
+ hashedPassword,
17
+ };
28
18
  }
29
19
  normalizeEmailAddress(emailAddress) {
30
20
  const lowercaseEmail = emailAddress.trim().toLowerCase();
@@ -41,9 +31,7 @@ export class SingleStepHashProtocol {
41
31
  }
42
32
  return `${normalizedUsername}${domain}`;
43
33
  }
44
- sha256(text) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- return yield this.hashUtils.hashString(text, Algorithm.SHA256);
47
- });
34
+ async sha256(text) {
35
+ return await this.hashUtils.hashString(text, Algorithm.SHA256);
48
36
  }
49
37
  }
@@ -1,20 +1,10 @@
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 class BodyLoginSuccessfulParser {
2
+ bodyRegex;
11
3
  constructor(regex) {
12
4
  this.bodyRegex = new RegExp(regex);
13
5
  }
14
- isLoginSuccessful(response) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- // TODO: Possibly add IBody methods to IOutgoingResponse interface?
17
- return this.bodyRegex.test(response.body);
18
- });
6
+ async isLoginSuccessful(response) {
7
+ // TODO: Possibly add IBody methods to IOutgoingResponse interface?
8
+ return this.bodyRegex.test(response.body);
19
9
  }
20
10
  }
@@ -1,26 +1,16 @@
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 class CustomLoginSuccessfulParser {
2
+ callback;
11
3
  constructor(callback) {
12
4
  this.callback = callback;
13
5
  }
14
- isLoginSuccessful(response) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- try {
17
- const retVal = yield this.callback(response.getUnderlyingResponse());
18
- return typeof retVal === 'boolean' ? retVal : null;
19
- }
20
- catch (_a) {
21
- // We cannot say definitively if the login was successful or not here
22
- return null;
23
- }
24
- });
6
+ async isLoginSuccessful(response) {
7
+ try {
8
+ const retVal = await this.callback(response.getUnderlyingResponse());
9
+ return typeof retVal === 'boolean' ? retVal : null;
10
+ }
11
+ catch {
12
+ // We cannot say definitively if the login was successful or not here
13
+ return null;
14
+ }
25
15
  }
26
16
  }