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.
- package/lib/action/utils.js +1 -1
- package/lib/activities/HttpActivityClient.d.ts +5 -5
- package/lib/activities/HttpActivityClient.js +28 -39
- package/lib/activities/HttpBatchedActivityClient.d.ts +2 -2
- package/lib/activities/HttpBatchedActivityClient.js +19 -32
- package/lib/activities/model/AsyncActivity.d.ts +14 -0
- package/lib/activities/model/{ActivityDetails.d.ts → AsyncActivityDetails.d.ts} +6 -23
- package/lib/activities/model/CommonActivityDetails.d.ts +40 -0
- package/lib/activities/model/CommonActivityDetails.js +1 -0
- package/lib/activities/model/HeaderEntry.d.ts +4 -0
- package/lib/activities/model/HeaderEntry.js +1 -0
- package/lib/activities/model/index.d.ts +4 -2
- package/lib/activities/model/index.js +4 -2
- package/lib/activities/utils.d.ts +6071 -9
- package/lib/activities/utils.js +111 -35
- package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +1 -1
- package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +4 -12
- package/lib/config/ConfigurationParams.d.ts +2 -1
- package/lib/config/DefaultConfigurations.js +1 -0
- package/lib/config/IConfiguration.d.ts +5 -1
- package/lib/config/StaticConfigurationBase.d.ts +2 -1
- package/lib/config/StaticConfigurationBase.js +6 -1
- package/lib/context/DefaultContext.d.ts +1 -1
- package/lib/context/DefaultContext.js +40 -8
- package/lib/context/interfaces/RiskApiData.d.ts +4 -0
- package/lib/cors/DefaultCors.js +21 -31
- package/lib/custom_parameters/CustomParametersUtils.js +3 -12
- package/lib/enforcer/EnforcerBase.d.ts +2 -1
- package/lib/enforcer/EnforcerBase.js +56 -57
- package/lib/enforcer/options/EnforcerBaseOptions.d.ts +2 -0
- package/lib/graphql/DefaultGraphQLParser.js +30 -39
- package/lib/http/index.d.ts +0 -1
- package/lib/http/index.js +0 -1
- package/lib/http/interfaces/IBody.d.ts +3 -2
- package/lib/http/interfaces/IIncomingRequest.d.ts +4 -0
- package/lib/http/interfaces/IURL.d.ts +3 -0
- package/lib/http/interfaces/IURLSearchParams.d.ts +9 -0
- package/lib/http/interfaces/IURLSearchParams.js +1 -0
- package/lib/http/interfaces/index.d.ts +1 -0
- package/lib/http/interfaces/index.js +1 -0
- package/lib/http/{impl → utils}/FormDataImpl.js +4 -4
- package/lib/http/{impl → utils}/MinimalResponseImpl.js +3 -0
- package/lib/http/utils/MinimalResponseUtils.js +5 -7
- package/lib/http/utils/MultipartFormDataUtils.js +4 -5
- package/lib/http/{impl → utils}/OutgoingRequestImpl.d.ts +1 -1
- package/lib/http/{impl → utils}/OutgoingRequestImpl.js +5 -1
- package/lib/http/utils/URLUtils.d.ts +7 -0
- package/lib/http/utils/URLUtils.js +62 -0
- package/lib/http/utils/UrlImpl.d.ts +18 -0
- package/lib/http/utils/UrlImpl.js +54 -0
- package/lib/http/utils/UrlSearchParamsImpl.d.ts +19 -0
- package/lib/http/utils/UrlSearchParamsImpl.js +116 -0
- package/lib/http/utils/index.d.ts +6 -0
- package/lib/http/utils/index.js +6 -0
- package/lib/{utils → impl}/base64/AtobBase64Utils.d.ts +1 -1
- package/lib/{utils → impl}/base64/BufferBase64Utils.d.ts +1 -1
- package/lib/{utils → impl}/base64/BufferBase64Utils.js +1 -1
- package/lib/{utils → impl}/base64/JSBase64Base64Utils.d.ts +1 -1
- package/lib/{utils → impl}/cipher/CryptoCipherUtils.d.ts +1 -1
- package/lib/impl/cipher/CryptoCipherUtils.js +18 -0
- package/lib/{utils → impl}/cipher/SubtleCryptoCipherUtils.d.ts +1 -2
- package/lib/impl/cipher/SubtleCryptoCipherUtils.js +38 -0
- package/lib/{utils → impl}/hash/CryptoHashUtils.d.ts +1 -2
- package/lib/impl/hash/CryptoHashUtils.js +10 -0
- package/lib/{utils → impl}/hash/CryptoJSHashUtils.d.ts +1 -2
- package/lib/{utils → impl}/hash/CryptoJSHashUtils.js +1 -1
- package/lib/{utils → impl}/hash/SubtleCryptoHashUtils.d.ts +1 -2
- package/lib/impl/hash/SubtleCryptoHashUtils.js +21 -0
- package/lib/{utils → impl}/hmac/CryptoHmacUtils.d.ts +1 -2
- package/lib/{utils → impl}/hmac/CryptoHmacUtils.js +2 -1
- package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.d.ts +1 -2
- package/lib/{utils → impl}/hmac/CryptoJSHmacUtils.js +1 -1
- package/lib/{http/impl → impl/http}/phin/PhinHttpClient.d.ts +1 -1
- package/lib/impl/http/phin/PhinHttpClient.js +31 -0
- package/lib/{http/impl → impl/http}/phin/PhinIncomingResponse.d.ts +2 -2
- package/lib/impl/http/phin/PhinIncomingResponse.js +23 -0
- package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.d.ts +1 -1
- package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.d.ts +1 -1
- package/lib/{utils → impl}/url_parser/DefaultUrlParser.d.ts +4 -4
- package/lib/{utils → impl}/url_parser/DefaultUrlParser.js +9 -2
- package/lib/logger/HttpLogServiceClient.d.ts +17 -0
- package/lib/logger/HttpLogServiceClient.js +52 -0
- package/lib/logger/ILogServiceClient.d.ts +6 -0
- package/lib/logger/ILogServiceClient.js +1 -0
- package/lib/logger/ILogger.d.ts +6 -0
- package/lib/logger/LoggerBase.d.ts +6 -2
- package/lib/logger/LoggerBase.js +14 -1
- package/lib/logger/constants.d.ts +2 -0
- package/lib/logger/constants.js +2 -0
- package/lib/logger/index.d.ts +4 -0
- package/lib/logger/index.js +3 -0
- package/lib/logger/model/EnrichedLogRecord.d.ts +3 -0
- package/lib/logger/model/EnrichedLogRecord.js +1 -0
- package/lib/logger/model/LogMetadata.d.ts +9 -0
- package/lib/logger/model/LogMetadata.js +1 -0
- package/lib/logger/model/LogRecord.d.ts +6 -0
- package/lib/logger/model/LogRecord.js +1 -0
- package/lib/logger/model/index.d.ts +3 -0
- package/lib/logger/model/index.js +3 -0
- package/lib/phase/flow/EndEnforcerFlow.d.ts +6 -0
- package/lib/phase/flow/EndEnforcerFlow.js +10 -0
- package/lib/phase/flow/index.d.ts +1 -0
- package/lib/phase/flow/index.js +1 -0
- package/lib/phase/impl/AdditionalActivityHandlerPhase.js +4 -15
- package/lib/phase/impl/CompositePhase.js +9 -19
- package/lib/phase/impl/CreateBlockResponsePhase.js +24 -35
- package/lib/phase/impl/DecideActionPhase.js +11 -21
- package/lib/phase/impl/EnrichContextFromRequestPhase.js +28 -45
- package/lib/phase/impl/EnrichContextFromResponsePhase.js +12 -23
- package/lib/phase/impl/FilterPhase.js +3 -13
- package/lib/phase/impl/FirstPartyPhase.js +21 -32
- package/lib/phase/impl/ModifyIncomingRequestPhase.js +4 -14
- package/lib/phase/impl/ModifyOutgoingResponsePhase.js +7 -18
- package/lib/phase/impl/ParseTokenPhase.js +5 -15
- package/lib/phase/impl/PreflightPhase.js +12 -20
- package/lib/phase/impl/RiskApiPhase.js +24 -36
- package/lib/phase/impl/SendAsyncActivitiesOnRequestPhase.js +8 -20
- package/lib/phase/impl/SendAsyncActivitiesOnResponsePhase.js +4 -14
- package/lib/phase/impl/SendLogsPhase.d.ts +11 -0
- package/lib/phase/impl/SendLogsPhase.js +16 -0
- package/lib/phase/impl/TelemetryPhase.js +9 -21
- package/lib/phase/impl/index.d.ts +1 -0
- package/lib/phase/impl/index.js +1 -0
- package/lib/products/account_defender/AccountDefender.js +16 -35
- package/lib/products/bot_defender/BotDefender.js +51 -72
- package/lib/products/bot_defender/BotDefenderActionData.js +2 -0
- package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.d.ts +4 -4
- package/lib/products/bot_defender/block/DefaultBotDefenderBlocker.js +5 -3
- package/lib/products/bot_defender/block/captcha/CaptchaBlocker.d.ts +7 -4
- package/lib/products/bot_defender/block/captcha/CaptchaBlocker.js +12 -8
- package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.d.ts +1 -1
- package/lib/products/bot_defender/block/captcha/HtmlCaptchaBlocker.js +1 -0
- package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.d.ts +1 -1
- package/lib/products/bot_defender/block/captcha/JsonCaptchaBlocker.js +5 -4
- package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.d.ts +2 -2
- package/lib/products/bot_defender/block/captcha/MobileCaptchaBlocker.js +2 -0
- package/lib/products/bot_defender/block/utils.js +1 -2
- package/lib/products/bot_defender/filter/DefaultBotDefenderFilter.js +7 -1
- package/lib/products/bot_defender/first_party/DefaultBotDefenderFirstParty.js +51 -68
- package/lib/products/bot_defender/first_party/constants.d.ts +0 -4
- package/lib/products/bot_defender/first_party/constants.js +0 -7
- package/lib/products/credential_intelligence/CredentialIntelligence.js +42 -63
- package/lib/products/credential_intelligence/endpoint/CredentialEndpoint.js +15 -23
- package/lib/products/credential_intelligence/endpoint/CredentialEndpointManager.js +9 -22
- package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.d.ts +5 -5
- package/lib/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +22 -33
- package/lib/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +8 -18
- package/lib/products/credential_intelligence/endpoint/extractor/HeaderCredentialExtractor.js +2 -0
- package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.d.ts +1 -1
- package/lib/products/credential_intelligence/endpoint/extractor/QueryParamCredentialExtractor.js +11 -16
- package/lib/products/credential_intelligence/endpoint/hash_protocol/MultistepHashProtocol.js +11 -21
- package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepAndMultistepHashProtocol.js +9 -18
- package/lib/products/credential_intelligence/endpoint/hash_protocol/SingleStepHashProtocol.js +13 -25
- package/lib/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +4 -14
- package/lib/products/credential_intelligence/endpoint/login_successful/CustomLoginSuccessfulParser.js +10 -20
- package/lib/products/credential_intelligence/endpoint/login_successful/HeaderLoginSuccessfulParser.js +7 -16
- package/lib/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +7 -6
- package/lib/products/credential_intelligence/endpoint/login_successful/StatusLoginSuccessfulParser.js +3 -13
- package/lib/products/credential_intelligence/endpoint/matcher/ExactPathEndpointMatcher.js +2 -0
- package/lib/products/credential_intelligence/endpoint/matcher/RegexPathEndpointMatcher.js +2 -0
- package/lib/pxde/DefaultDataEnrichment.js +47 -61
- package/lib/pxhd/PXHDUtils.js +2 -2
- package/lib/risk_api/client/PostRiskApiClientBase.d.ts +7 -12
- package/lib/risk_api/client/PostRiskApiClientBase.js +70 -171
- package/lib/risk_api/model/RiskActivity.d.ts +5 -45
- package/lib/risk_api/risk_response/IRiskResponse.d.ts +1 -0
- package/lib/risk_api/risk_response/RiskResponseBase.d.ts +1 -0
- package/lib/risk_api/risk_response/RiskResponseBase.js +20 -33
- package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.d.ts +1 -1
- package/lib/risk_api/risk_response/v2/DefaultRiskResponseV2.js +3 -5
- package/lib/risk_api/risk_response/v2/RiskResponseV2Payload.d.ts +1 -0
- package/lib/risk_api/risk_response/v3/DefaultRiskResponseV3.js +2 -4
- package/lib/risk_api/risk_response/v3/RiskResponseV3Payload.d.ts +1 -0
- package/lib/risk_token/parser/TokenParserBase.js +25 -36
- package/lib/risk_token/token/TokenBase.js +24 -29
- package/lib/risk_token/token/v2/DefaultTokenV2.js +34 -49
- package/lib/risk_token/token/v3/DefaultTokenV3.js +63 -77
- package/lib/telemetry/DefaultTelemetry.js +46 -58
- package/lib/utils/base64/index.d.ts +0 -3
- package/lib/utils/base64/index.js +0 -3
- package/lib/utils/cipher/index.d.ts +1 -3
- package/lib/utils/cipher/index.js +1 -2
- package/lib/utils/constants.d.ts +2 -1
- package/lib/utils/constants.js +2 -1
- package/lib/utils/hash/index.d.ts +0 -3
- package/lib/utils/hash/index.js +0 -3
- package/lib/utils/hmac/index.d.ts +0 -2
- package/lib/utils/hmac/index.js +0 -2
- package/lib/utils/ip_range_checker/index.d.ts +1 -2
- package/lib/utils/ip_range_checker/index.js +1 -1
- package/lib/utils/request_id_generator/index.d.ts +1 -2
- package/lib/utils/request_id_generator/index.js +1 -1
- package/lib/utils/url_parser/index.d.ts +0 -1
- package/lib/utils/url_parser/index.js +0 -1
- package/lib/utils/utils.d.ts +1 -7
- package/lib/utils/utils.js +3 -25
- package/package.json +12 -6
- package/lib/activities/model/Activity.d.ts +0 -13
- package/lib/http/impl/index.d.ts +0 -4
- package/lib/http/impl/index.js +0 -4
- package/lib/http/impl/phin/PhinHttpClient.js +0 -41
- package/lib/http/impl/phin/PhinIncomingResponse.js +0 -38
- package/lib/utils/cipher/CryptoCipherUtils.js +0 -28
- package/lib/utils/cipher/SubtleCryptoCipherUtils.js +0 -47
- package/lib/utils/hash/CryptoHashUtils.js +0 -20
- package/lib/utils/hash/SubtleCryptoHashUtils.js +0 -31
- /package/lib/activities/model/{Activity.js → AsyncActivity.js} +0 -0
- /package/lib/activities/model/{ActivityDetails.js → AsyncActivityDetails.js} +0 -0
- /package/lib/http/{impl → utils}/FormDataImpl.d.ts +0 -0
- /package/lib/http/{impl → utils}/MinimalResponseImpl.d.ts +0 -0
- /package/lib/{utils → impl}/base64/AtobBase64Utils.js +0 -0
- /package/lib/{utils → impl}/base64/JSBase64Base64Utils.js +0 -0
- /package/lib/{http/impl → impl/http}/phin/index.d.ts +0 -0
- /package/lib/{http/impl → impl/http}/phin/index.js +0 -0
- /package/lib/{utils → impl}/ip_range_checker/DefaultIpRangeChecker.js +0 -0
- /package/lib/{utils → impl}/request_id_generator/UuidRequestIdGenerator.js +0 -0
|
@@ -1,19 +1,11 @@
|
|
|
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
|
-
import { ProductName } from '../../products';
|
|
11
1
|
import { AUTHORIZATION_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, ContentType, HttpMethod, OutgoingRequestImpl, } from '../../http';
|
|
12
|
-
import { EnforcerErrorName, getAuthorizationHeader,
|
|
2
|
+
import { EnforcerErrorName, getAuthorizationHeader, removeSensitiveHeaders, } from '../../utils';
|
|
3
|
+
import { createCommonActivityDetails, toHeaderEntryArray } from '../../activities';
|
|
13
4
|
import { RISK_API_ENDPOINT } from '../constants';
|
|
14
5
|
import { RiskApiCallResult, RiskStatus, S2SErrorReason } from '../model';
|
|
15
|
-
import { TokenParseResult } from '../../risk_token';
|
|
16
6
|
export class PostRiskApiClientBase {
|
|
7
|
+
config;
|
|
8
|
+
httpClient;
|
|
17
9
|
constructor(config, httpClient) {
|
|
18
10
|
this.config = config;
|
|
19
11
|
this.httpClient = httpClient;
|
|
@@ -23,32 +15,30 @@ export class PostRiskApiClientBase {
|
|
|
23
15
|
* @param context
|
|
24
16
|
* @returns Promise<RiskApiData>
|
|
25
17
|
*/
|
|
26
|
-
executeRiskApi(context) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return yield this.handleS2SError(riskApiData, response);
|
|
35
|
-
}
|
|
36
|
-
riskResponse = this.createRiskResponse(response);
|
|
37
|
-
riskApiData.riskResponse = riskResponse;
|
|
38
|
-
if (!(yield riskResponse.validate())) {
|
|
39
|
-
return yield this.handleS2SError(riskApiData, response);
|
|
40
|
-
}
|
|
41
|
-
this.config.logger.debug(`received risk response, score: ${riskResponse.score}, rtt: ${riskApiData.riskRtt}`);
|
|
42
|
-
return riskApiData;
|
|
18
|
+
async executeRiskApi(context) {
|
|
19
|
+
let response, riskResponse;
|
|
20
|
+
const riskApiData = { riskApiCallResult: RiskApiCallResult.NONE };
|
|
21
|
+
try {
|
|
22
|
+
const riskActivity = this.createRiskActivity(context);
|
|
23
|
+
response = await this.sendRiskActivity(riskActivity, riskApiData);
|
|
24
|
+
if (response?.status !== 200) {
|
|
25
|
+
return await this.handleS2SError(riskApiData, response);
|
|
43
26
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
this.config.logger.error(`caught error in risk api: ${err} - ${JSON.stringify(context.requestData.url)}`);
|
|
49
|
-
return yield this.handleS2SError(riskApiData, response, err);
|
|
27
|
+
riskResponse = this.createRiskResponse(response);
|
|
28
|
+
riskApiData.riskResponse = riskResponse;
|
|
29
|
+
if (!(await riskResponse.validate())) {
|
|
30
|
+
return await this.handleS2SError(riskApiData, response);
|
|
50
31
|
}
|
|
51
|
-
|
|
32
|
+
this.config.logger.debug(`received risk response, score: ${riskResponse.score}, rtt: ${riskApiData.riskRtt}`);
|
|
33
|
+
return riskApiData;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err.name === EnforcerErrorName.ENFORCER_TIMEOUT_ERROR) {
|
|
37
|
+
return this.handleS2STimeout(riskApiData);
|
|
38
|
+
}
|
|
39
|
+
this.config.logger.error(`caught error in risk api: ${err} - ${JSON.stringify(context.requestData.url)}`);
|
|
40
|
+
return await this.handleS2SError(riskApiData, response, err);
|
|
41
|
+
}
|
|
52
42
|
}
|
|
53
43
|
/**
|
|
54
44
|
* Creates the RiskActivity payload
|
|
@@ -57,26 +47,20 @@ export class PostRiskApiClientBase {
|
|
|
57
47
|
* @protected
|
|
58
48
|
*/
|
|
59
49
|
createRiskActivity(context) {
|
|
60
|
-
var _a, _b, _c;
|
|
61
50
|
const riskActivity = {
|
|
51
|
+
vid: context.vid,
|
|
52
|
+
client_uuid: context.uuid,
|
|
53
|
+
pxhd: context.pxhd?.value,
|
|
62
54
|
request: {
|
|
63
|
-
|
|
55
|
+
socket_ip: context.requestData.ip,
|
|
64
56
|
headers: this.formatRiskHeadersField(context.requestData.headers),
|
|
65
57
|
url: context.requestData.rawUrl,
|
|
66
58
|
},
|
|
67
59
|
additional: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
module_version: this.config.moduleVersion,
|
|
71
|
-
http_method: context.requestData.method,
|
|
72
|
-
http_version: context.requestData.httpVersion,
|
|
73
|
-
risk_mode: ((_c = context.productData.bd) === null || _c === void 0 ? void 0 : _c.isMonitoredRequest) ? ModuleMode.MONITOR : ModuleMode.ACTIVE_BLOCKING,
|
|
74
|
-
cookie_origin: context.tokenOrigin,
|
|
75
|
-
request_cookie_names: context.requestData.requestCookieNames.concat(),
|
|
76
|
-
request_id: context.requestId,
|
|
60
|
+
...createCommonActivityDetails(this.config, context),
|
|
61
|
+
s2s_call_reason: context.riskApiData.s2sCallReason,
|
|
77
62
|
},
|
|
78
63
|
};
|
|
79
|
-
this.addOptionalRiskFields(riskActivity, context);
|
|
80
64
|
return this.finalizeRiskActivity(riskActivity);
|
|
81
65
|
}
|
|
82
66
|
/**
|
|
@@ -88,105 +72,23 @@ export class PostRiskApiClientBase {
|
|
|
88
72
|
finalizeRiskActivity(riskActivity) {
|
|
89
73
|
return riskActivity;
|
|
90
74
|
}
|
|
91
|
-
addOptionalRiskFields(riskActivity, context) {
|
|
92
|
-
this.addOptionalRiskFieldsToRoot(riskActivity, context);
|
|
93
|
-
this.addOptionalRiskFieldsToAdditional(riskActivity, context);
|
|
94
|
-
this.addProductDataToAdditional(riskActivity, context.productData);
|
|
95
|
-
this.addTokenDataToAdditional(riskActivity, context.tokenData);
|
|
96
|
-
this.addCustomParamsToAdditional(riskActivity, context);
|
|
97
|
-
}
|
|
98
|
-
addOptionalRiskFieldsToRoot(riskActivity, context) {
|
|
99
|
-
var _a;
|
|
100
|
-
transferExistingProperties(context, riskActivity, {
|
|
101
|
-
vid: 'vid',
|
|
102
|
-
uuid: 'uuid',
|
|
103
|
-
});
|
|
104
|
-
if ((_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.value) {
|
|
105
|
-
riskActivity.pxhd = context.pxhd.value;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
addOptionalRiskFieldsToAdditional(riskActivity, context) {
|
|
109
|
-
transferExistingProperties(context, riskActivity.additional, {
|
|
110
|
-
vidSource: 'enforcer_vid_source',
|
|
111
|
-
graphqlData: 'graphql_operations',
|
|
112
|
-
});
|
|
113
|
-
transferExistingProperties(context.serverData, riskActivity.additional, {
|
|
114
|
-
region: 'server_info_region',
|
|
115
|
-
datacenter: 'server_info_datacenter',
|
|
116
|
-
});
|
|
117
|
-
transferExistingProperties(context.tlsData, riskActivity.additional, {
|
|
118
|
-
tlsProtocol: 'tls_protocol',
|
|
119
|
-
tlsServer: 'tls_server',
|
|
120
|
-
tlsCipher: 'tls_cipher',
|
|
121
|
-
tlsCiphersSha: 'tls_ciphers_sha',
|
|
122
|
-
tlsExtensionSha: 'tls_extension_sha',
|
|
123
|
-
tlsPreferredCiphers: 'tls_preferred_ciphers',
|
|
124
|
-
tlsJa3Fingerprint: 'tls_ja3_fingerprint',
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
addProductDataToAdditional(riskActivity, productData) {
|
|
128
|
-
transferExistingProperties(productData.ad, riskActivity.additional, {
|
|
129
|
-
appUserId: 'app_user_id',
|
|
130
|
-
additionalFields: 'jwt_additional_fields',
|
|
131
|
-
crossTabSession: 'cross_tab_session',
|
|
132
|
-
});
|
|
133
|
-
transferExistingProperties(productData.ci, riskActivity.additional, {
|
|
134
|
-
hashedUsername: 'user',
|
|
135
|
-
hashedPassword: 'pass',
|
|
136
|
-
ciVersion: 'ci_version',
|
|
137
|
-
ssoStep: 'sso_step',
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
addCustomParamsToAdditional(riskActivity, context) {
|
|
141
|
-
if (context.customParameters) {
|
|
142
|
-
Object.assign(riskActivity.additional, context.customParameters);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
addTokenDataToAdditional(riskActivity, { token, mobileData }) {
|
|
146
|
-
if (token) {
|
|
147
|
-
if (token.isValid()) {
|
|
148
|
-
riskActivity.additional.px_cookie = token.getPayloadString();
|
|
149
|
-
riskActivity.additional.px_cookie_hmac = token.hmac;
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
riskActivity.additional.px_orig_cookie = token.getTokenString();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (mobileData) {
|
|
156
|
-
transferExistingProperties(mobileData, riskActivity.additional, {
|
|
157
|
-
originalToken: 'original_token',
|
|
158
|
-
decodedOriginalToken: 'px_decoded_original_token',
|
|
159
|
-
});
|
|
160
|
-
if (mobileData.originalTokenParseResult === TokenParseResult.DECRYPTION_FAILED) {
|
|
161
|
-
riskActivity.additional.original_token_error = 'cookie_decryption_failed';
|
|
162
|
-
}
|
|
163
|
-
else if (mobileData.originalTokenParseResult === TokenParseResult.VALIDATION_FAILED) {
|
|
164
|
-
riskActivity.additional.original_token_error = 'cookie_validation_failed';
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
75
|
formatRiskHeadersField(headers) {
|
|
169
76
|
const headersWithoutSensitive = removeSensitiveHeaders(headers, this.config.sensitiveHeaders);
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const endTime = Date.now();
|
|
186
|
-
riskApiData.riskApiCallResult = RiskApiCallResult.SUCCESSFUL;
|
|
187
|
-
riskApiData.riskRtt = endTime - startTime;
|
|
188
|
-
return response;
|
|
189
|
-
});
|
|
77
|
+
return toHeaderEntryArray(headersWithoutSensitive);
|
|
78
|
+
}
|
|
79
|
+
async sendRiskActivity(riskActivity, riskApiData) {
|
|
80
|
+
const url = this.getRiskUrl();
|
|
81
|
+
const headers = this.getRiskHeaders();
|
|
82
|
+
const body = JSON.stringify(riskActivity);
|
|
83
|
+
const method = HttpMethod.POST;
|
|
84
|
+
const riskRequest = new OutgoingRequestImpl({ url, method, headers, body });
|
|
85
|
+
this.config.logger.debug(`sending risk api to ${url}`);
|
|
86
|
+
const startTime = Date.now();
|
|
87
|
+
const response = await this.httpClient.send(riskRequest, { timeoutMs: this.config.s2sTimeout });
|
|
88
|
+
const endTime = Date.now();
|
|
89
|
+
riskApiData.riskApiCallResult = RiskApiCallResult.SUCCESSFUL;
|
|
90
|
+
riskApiData.riskRtt = endTime - startTime;
|
|
91
|
+
return response;
|
|
190
92
|
}
|
|
191
93
|
getRiskUrl() {
|
|
192
94
|
return `${this.config.backendScoreApiUrl}${RISK_API_ENDPOINT}`;
|
|
@@ -201,35 +103,32 @@ export class PostRiskApiClientBase {
|
|
|
201
103
|
riskApiData.riskApiCallResult = RiskApiCallResult.TIMEOUT;
|
|
202
104
|
return riskApiData;
|
|
203
105
|
}
|
|
204
|
-
handleS2SError(riskApiData, response, error) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
riskApiData.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (((_b = riskApiData.riskResponse) === null || _b === void 0 ? void 0 : _b.status) === RiskStatus.FAILURE) {
|
|
214
|
-
riskApiData.errorReason = S2SErrorReason.REQUEST_FAILED_ON_SERVER;
|
|
215
|
-
}
|
|
216
|
-
else if (!(yield ((_c = riskApiData.riskResponse) === null || _c === void 0 ? void 0 : _c.validate()))) {
|
|
217
|
-
riskApiData.errorReason = S2SErrorReason.INVALID_RESPONSE;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else if (response.status >= 400 && response.status < 500) {
|
|
221
|
-
riskApiData.errorReason = S2SErrorReason.BAD_REQUEST;
|
|
106
|
+
async handleS2SError(riskApiData, response, error) {
|
|
107
|
+
riskApiData.riskApiCallResult = RiskApiCallResult.ERROR;
|
|
108
|
+
riskApiData.errorReason = S2SErrorReason.UNKNOWN_ERROR;
|
|
109
|
+
if (response || riskApiData.riskResponse) {
|
|
110
|
+
riskApiData.errorHttpStatus = response.status;
|
|
111
|
+
riskApiData.errorMessage = riskApiData.riskResponse?.message || `response body: ${await response.text()}`;
|
|
112
|
+
if (response.status === 200) {
|
|
113
|
+
if (riskApiData.riskResponse?.status === RiskStatus.FAILURE) {
|
|
114
|
+
riskApiData.errorReason = S2SErrorReason.REQUEST_FAILED_ON_SERVER;
|
|
222
115
|
}
|
|
223
|
-
else if (
|
|
224
|
-
riskApiData.errorReason = S2SErrorReason.
|
|
116
|
+
else if (!(await riskApiData.riskResponse?.validate())) {
|
|
117
|
+
riskApiData.errorReason = S2SErrorReason.INVALID_RESPONSE;
|
|
225
118
|
}
|
|
226
119
|
}
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
const existingMessage = riskApiData.errorMessage;
|
|
230
|
-
riskApiData.errorMessage = existingMessage ? `${existingMessage}, ${errorMessage}` : errorMessage;
|
|
120
|
+
else if (response.status >= 400 && response.status < 500) {
|
|
121
|
+
riskApiData.errorReason = S2SErrorReason.BAD_REQUEST;
|
|
231
122
|
}
|
|
232
|
-
|
|
233
|
-
|
|
123
|
+
else if (response.status >= 500 && response.status < 600) {
|
|
124
|
+
riskApiData.errorReason = S2SErrorReason.SERVER_ERROR;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (error) {
|
|
128
|
+
const errorMessage = `${error}`;
|
|
129
|
+
const existingMessage = riskApiData.errorMessage;
|
|
130
|
+
riskApiData.errorMessage = existingMessage ? `${existingMessage}, ${errorMessage}` : errorMessage;
|
|
131
|
+
}
|
|
132
|
+
return riskApiData;
|
|
234
133
|
}
|
|
235
134
|
}
|
|
@@ -1,56 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TokenOrigin } from '../../risk_token';
|
|
3
|
-
import { CustomParameters } from '../../custom_parameters';
|
|
4
|
-
import { GraphQLData } from '../../graphql/';
|
|
5
|
-
import { CredentialIntelligenceVersion, SsoStep } from '../../products';
|
|
6
|
-
export type HeaderEntry = {
|
|
7
|
-
name: string;
|
|
8
|
-
value: string;
|
|
9
|
-
};
|
|
1
|
+
import { HeaderEntry, CommonActivityDetails } from '../../activities';
|
|
10
2
|
export type RiskRequestData = {
|
|
11
|
-
|
|
3
|
+
socket_ip: string;
|
|
12
4
|
url: string;
|
|
13
5
|
headers: HeaderEntry[];
|
|
14
6
|
};
|
|
15
7
|
export type RiskAdditionalData = {
|
|
16
|
-
request_id: string;
|
|
17
|
-
module_version: string;
|
|
18
8
|
s2s_call_reason: string;
|
|
19
|
-
|
|
20
|
-
http_method: string;
|
|
21
|
-
http_version?: string;
|
|
22
|
-
px_orig_cookie?: string;
|
|
23
|
-
px_cookie?: string;
|
|
24
|
-
px_cookie_hmac?: string;
|
|
25
|
-
tls_protocol?: string;
|
|
26
|
-
tls_server?: string;
|
|
27
|
-
tls_cipher?: string;
|
|
28
|
-
tls_ciphers_sha?: string;
|
|
29
|
-
tls_extension_sha?: string;
|
|
30
|
-
tls_preferred_ciphers?: string;
|
|
31
|
-
tls_ja3_fingerprint?: string;
|
|
32
|
-
enforcer_vid_source?: VidSource;
|
|
33
|
-
original_uuid?: string;
|
|
34
|
-
original_token_error?: string;
|
|
35
|
-
original_token?: string;
|
|
36
|
-
px_decoded_original_token?: string;
|
|
37
|
-
cookie_origin?: TokenOrigin;
|
|
38
|
-
request_cookie_names?: string[];
|
|
39
|
-
server_info_region?: string;
|
|
40
|
-
server_info_datacenter?: string;
|
|
41
|
-
cross_tab_session?: string;
|
|
42
|
-
app_user_id?: string;
|
|
43
|
-
jwt_additional_fields?: Record<string, any>;
|
|
44
|
-
graphql_operations?: GraphQLData[];
|
|
45
|
-
user?: string;
|
|
46
|
-
pass?: string;
|
|
47
|
-
ci_version?: CredentialIntelligenceVersion;
|
|
48
|
-
sso_step?: SsoStep;
|
|
49
|
-
} & CustomParameters;
|
|
9
|
+
};
|
|
50
10
|
export type RiskActivity = {
|
|
51
11
|
vid?: string;
|
|
52
|
-
|
|
12
|
+
client_uuid?: string;
|
|
53
13
|
pxhd?: string;
|
|
54
14
|
request: RiskRequestData;
|
|
55
|
-
additional: RiskAdditionalData;
|
|
15
|
+
additional: RiskAdditionalData & CommonActivityDetails;
|
|
56
16
|
};
|
|
@@ -1,54 +1,41 @@
|
|
|
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 { RiskStatus } from '../model';
|
|
11
2
|
export class RiskResponseBase {
|
|
3
|
+
response;
|
|
4
|
+
riskResponse;
|
|
12
5
|
constructor(response) {
|
|
13
6
|
this.response = response;
|
|
14
7
|
}
|
|
15
|
-
validate() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
});
|
|
8
|
+
async validate() {
|
|
9
|
+
try {
|
|
10
|
+
this.riskResponse = (await this.response.json());
|
|
11
|
+
return this.status === RiskStatus.SUCCESS && this.validateRiskResponseScore();
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
25
16
|
}
|
|
26
17
|
get status() {
|
|
27
|
-
|
|
28
|
-
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.status;
|
|
18
|
+
return this.riskResponse?.status;
|
|
29
19
|
}
|
|
30
20
|
get action() {
|
|
31
|
-
|
|
32
|
-
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.action;
|
|
21
|
+
return this.riskResponse?.action;
|
|
33
22
|
}
|
|
34
23
|
get message() {
|
|
35
|
-
|
|
36
|
-
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.message;
|
|
24
|
+
return this.riskResponse?.message;
|
|
37
25
|
}
|
|
38
26
|
get pxhd() {
|
|
39
|
-
|
|
40
|
-
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.pxhd;
|
|
27
|
+
return this.riskResponse?.pxhd;
|
|
41
28
|
}
|
|
42
29
|
get uuid() {
|
|
43
|
-
|
|
44
|
-
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.uuid;
|
|
30
|
+
return this.riskResponse?.uuid;
|
|
45
31
|
}
|
|
46
32
|
get dataEnrichment() {
|
|
47
|
-
|
|
48
|
-
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.data_enrichment;
|
|
33
|
+
return this.riskResponse?.data_enrichment;
|
|
49
34
|
}
|
|
50
35
|
get pxhdDomain() {
|
|
51
|
-
|
|
52
|
-
|
|
36
|
+
return this.riskResponse?.pxhdDomain;
|
|
37
|
+
}
|
|
38
|
+
get additionalRiskInfo() {
|
|
39
|
+
return this.riskResponse?.additional_risk_info;
|
|
53
40
|
}
|
|
54
41
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IIncomingResponse } from '../../../http';
|
|
2
|
-
import { RiskResponseBase } from '../RiskResponseBase';
|
|
3
2
|
import { TokenVersion } from '../../../risk_token';
|
|
3
|
+
import { RiskResponseBase } from '../RiskResponseBase';
|
|
4
4
|
export declare class DefaultRiskResponseV2 extends RiskResponseBase<TokenVersion.V2> {
|
|
5
5
|
constructor(response: IIncomingResponse);
|
|
6
6
|
get score(): number;
|
|
@@ -4,15 +4,13 @@ export class DefaultRiskResponseV2 extends RiskResponseBase {
|
|
|
4
4
|
super(response);
|
|
5
5
|
}
|
|
6
6
|
get score() {
|
|
7
|
-
|
|
8
|
-
return typeof ((_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.cookie_cfg_block_result) === 'undefined'
|
|
7
|
+
return typeof this.riskResponse?.cookie_cfg_block_result === 'undefined'
|
|
9
8
|
? undefined
|
|
10
|
-
:
|
|
9
|
+
: this.riskResponse?.cookie_cfg_block_result === '1'
|
|
11
10
|
? 100
|
|
12
11
|
: 0;
|
|
13
12
|
}
|
|
14
13
|
validateRiskResponseScore() {
|
|
15
|
-
|
|
16
|
-
return ['0', '1'].includes((_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.cookie_cfg_block_result);
|
|
14
|
+
return ['0', '1'].includes(this.riskResponse?.cookie_cfg_block_result);
|
|
17
15
|
}
|
|
18
16
|
}
|
|
@@ -4,11 +4,9 @@ export class DefaultRiskResponseV3 extends RiskResponseBase {
|
|
|
4
4
|
super(response);
|
|
5
5
|
}
|
|
6
6
|
get score() {
|
|
7
|
-
|
|
8
|
-
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.score;
|
|
7
|
+
return this.riskResponse?.score;
|
|
9
8
|
}
|
|
10
9
|
validateRiskResponseScore() {
|
|
11
|
-
|
|
12
|
-
return typeof ((_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.score) === 'number';
|
|
10
|
+
return typeof this.riskResponse?.score === 'number';
|
|
13
11
|
}
|
|
14
12
|
}
|
|
@@ -1,38 +1,29 @@
|
|
|
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 { X_PX_AUTHORIZATION_HEADER_NAME, X_PX_BYPASS_REASON_HEADER_NAME, X_PX_ORIGINAL_TOKEN_HEADER_NAME, } from '../../utils';
|
|
11
2
|
import { TokenParseResult } from '../TokenParseResult';
|
|
12
3
|
import { COOKIE_SPLIT_DELIMITER } from '../constants';
|
|
13
4
|
import { convertMobileTokenVersionToCookieName } from '../utils';
|
|
14
5
|
export class TokenParserBase {
|
|
6
|
+
config;
|
|
7
|
+
options;
|
|
15
8
|
constructor(config, options) {
|
|
16
9
|
this.config = config;
|
|
17
10
|
this.options = options;
|
|
18
11
|
}
|
|
19
|
-
parseToken(context) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return tokenData;
|
|
27
|
-
}
|
|
28
|
-
tokenData.tokenParseResult = yield tokenData.token.verify(context);
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
this.config.logger.debug(`could not parse token - ${e}`);
|
|
32
|
-
tokenData.tokenParseResult = tokenData.token ? TokenParseResult.DECRYPTION_FAILED : TokenParseResult.NONE;
|
|
12
|
+
async parseToken(context) {
|
|
13
|
+
const tokenData = this.initializeToken(context);
|
|
14
|
+
try {
|
|
15
|
+
if (!tokenData.token) {
|
|
16
|
+
this.config.logger.debug('no token found');
|
|
17
|
+
await this.handleMobileErrorIfNeeded(context, tokenData);
|
|
18
|
+
return tokenData;
|
|
33
19
|
}
|
|
34
|
-
|
|
35
|
-
}
|
|
20
|
+
tokenData.tokenParseResult = await tokenData.token.verify(context);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
this.config.logger.debug(`could not parse token - ${e}`);
|
|
24
|
+
tokenData.tokenParseResult = tokenData.token ? TokenParseResult.DECRYPTION_FAILED : TokenParseResult.NONE;
|
|
25
|
+
}
|
|
26
|
+
return tokenData;
|
|
36
27
|
}
|
|
37
28
|
initializeToken({ requestData, isMobile }) {
|
|
38
29
|
if (isMobile) {
|
|
@@ -59,7 +50,7 @@ export class TokenParserBase {
|
|
|
59
50
|
}
|
|
60
51
|
getMobileToken(mobileToken) {
|
|
61
52
|
try {
|
|
62
|
-
if (!mobileToken ||
|
|
53
|
+
if (!mobileToken || mobileToken?.indexOf(COOKIE_SPLIT_DELIMITER) === -1) {
|
|
63
54
|
return null;
|
|
64
55
|
}
|
|
65
56
|
const [tokenVersion, ...cookieString] = mobileToken.split(COOKIE_SPLIT_DELIMITER);
|
|
@@ -80,15 +71,13 @@ export class TokenParserBase {
|
|
|
80
71
|
token: this.createToken(this.config, cookies, this.options),
|
|
81
72
|
};
|
|
82
73
|
}
|
|
83
|
-
handleMobileErrorIfNeeded(context, { mobileData }) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
});
|
|
74
|
+
async handleMobileErrorIfNeeded(context, { mobileData }) {
|
|
75
|
+
if (!mobileData || !mobileData.mobileError || !mobileData.originalToken) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
mobileData.originalTokenParseResult = await mobileData.originalToken.verify(context);
|
|
79
|
+
if (mobileData.originalTokenParseResult === TokenParseResult.SUCCESSFUL) {
|
|
80
|
+
mobileData.decodedOriginalToken = mobileData.originalToken.getPayloadString();
|
|
81
|
+
}
|
|
93
82
|
}
|
|
94
83
|
}
|
|
@@ -1,14 +1,11 @@
|
|
|
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 { TokenParseResult } from '../TokenParseResult';
|
|
11
2
|
export class TokenBase {
|
|
3
|
+
logger;
|
|
4
|
+
payload;
|
|
5
|
+
cookieString;
|
|
6
|
+
cookieSecret;
|
|
7
|
+
cookieMaxLength;
|
|
8
|
+
isValidated;
|
|
12
9
|
constructor(config, cookieString) {
|
|
13
10
|
this.logger = config.logger;
|
|
14
11
|
this.cookieSecret = config.cookieSecret;
|
|
@@ -16,27 +13,25 @@ export class TokenBase {
|
|
|
16
13
|
this.cookieString = cookieString;
|
|
17
14
|
this.isValidated = false;
|
|
18
15
|
}
|
|
19
|
-
verify(context) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (this.isValid()) {
|
|
25
|
-
return TokenParseResult.SUCCESSFUL;
|
|
26
|
-
}
|
|
27
|
-
if (this.cookieString.length > this.cookieMaxLength) {
|
|
28
|
-
return TokenParseResult.DECRYPTION_FAILED;
|
|
29
|
-
}
|
|
30
|
-
this.payload = this.payload || (yield this.decrypt(context));
|
|
31
|
-
if (!this.payload) {
|
|
32
|
-
return TokenParseResult.DECRYPTION_FAILED;
|
|
33
|
-
}
|
|
34
|
-
if (!(yield this.validate(context))) {
|
|
35
|
-
return TokenParseResult.VALIDATION_FAILED;
|
|
36
|
-
}
|
|
37
|
-
this.isValidated = true;
|
|
16
|
+
async verify(context) {
|
|
17
|
+
if (!this.cookieString) {
|
|
18
|
+
return TokenParseResult.NONE;
|
|
19
|
+
}
|
|
20
|
+
if (this.isValid()) {
|
|
38
21
|
return TokenParseResult.SUCCESSFUL;
|
|
39
|
-
}
|
|
22
|
+
}
|
|
23
|
+
if (this.cookieString.length > this.cookieMaxLength) {
|
|
24
|
+
return TokenParseResult.DECRYPTION_FAILED;
|
|
25
|
+
}
|
|
26
|
+
this.payload = this.payload || (await this.decrypt(context));
|
|
27
|
+
if (!this.payload) {
|
|
28
|
+
return TokenParseResult.DECRYPTION_FAILED;
|
|
29
|
+
}
|
|
30
|
+
if (!(await this.validate(context))) {
|
|
31
|
+
return TokenParseResult.VALIDATION_FAILED;
|
|
32
|
+
}
|
|
33
|
+
this.isValidated = true;
|
|
34
|
+
return TokenParseResult.SUCCESSFUL;
|
|
40
35
|
}
|
|
41
36
|
isValid() {
|
|
42
37
|
return this.isValidated;
|