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.
- 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 +1 -1
- package/lib/config/IConfiguration.d.ts +1 -1
- package/lib/config/StaticConfigurationBase.d.ts +1 -1
- package/lib/config/StaticConfigurationBase.js +3 -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.js +51 -62
- 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.js +27 -35
- package/lib/logger/LoggerBase.js +2 -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.js +8 -18
- package/lib/phase/impl/TelemetryPhase.js +9 -21
- 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 +2 -0
- 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,60 +1,43 @@
|
|
|
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 { CustomParametersUtils } from '../../custom_parameters';
|
|
11
2
|
import { DecideActionPhase } from './DecideActionPhase';
|
|
12
3
|
export class EnrichContextFromRequestPhase extends DecideActionPhase {
|
|
4
|
+
products;
|
|
5
|
+
dataEnrichment;
|
|
6
|
+
graphQLParser;
|
|
13
7
|
constructor(config, products, dataEnrichment, graphQLParser) {
|
|
14
8
|
super(config);
|
|
15
9
|
this.products = products;
|
|
16
10
|
this.dataEnrichment = dataEnrichment;
|
|
17
11
|
this.graphQLParser = graphQLParser;
|
|
18
12
|
}
|
|
19
|
-
execute(context) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return { done: false };
|
|
28
|
-
});
|
|
13
|
+
async execute(context) {
|
|
14
|
+
this.config.logger.debug('enrich context from request phase');
|
|
15
|
+
await this.addPxdeToContext(context);
|
|
16
|
+
await this.addGraphQLDataToContext(context);
|
|
17
|
+
await this.addProductDataToContext(context);
|
|
18
|
+
await this.addCustomParametersToContext(context);
|
|
19
|
+
await this.updateContextDecision(context);
|
|
20
|
+
return { done: false };
|
|
29
21
|
}
|
|
30
|
-
addPxdeToContext(context) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
});
|
|
22
|
+
async addPxdeToContext(context) {
|
|
23
|
+
const pxdeData = await this.dataEnrichment.handlePxde(context);
|
|
24
|
+
if (pxdeData) {
|
|
25
|
+
context.pxde = pxdeData.pxde;
|
|
26
|
+
context.pxdeVerified = pxdeData.pxdeVerified;
|
|
27
|
+
}
|
|
38
28
|
}
|
|
39
|
-
addGraphQLDataToContext(context) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
context.graphqlData = yield this.graphQLParser.parseGraphQLRequest(context);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
29
|
+
async addGraphQLDataToContext(context) {
|
|
30
|
+
if (this.graphQLParser?.isGraphQLRequest(context)) {
|
|
31
|
+
context.graphqlData = await this.graphQLParser.parseGraphQLRequest(context);
|
|
32
|
+
}
|
|
46
33
|
}
|
|
47
|
-
addProductDataToContext(context) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})));
|
|
53
|
-
});
|
|
34
|
+
async addProductDataToContext(context) {
|
|
35
|
+
await Promise.all(Object.entries(this.products).map(async ([name, product]) => {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
context.productData[name] = await product?.enrichContextFromRequest(context);
|
|
38
|
+
}));
|
|
54
39
|
}
|
|
55
|
-
addCustomParametersToContext(context) {
|
|
56
|
-
|
|
57
|
-
context.customParameters = yield CustomParametersUtils.createCustomParameters(this.config, context);
|
|
58
|
-
});
|
|
40
|
+
async addCustomParametersToContext(context) {
|
|
41
|
+
context.customParameters = await CustomParametersUtils.createCustomParameters(this.config, context);
|
|
59
42
|
}
|
|
60
43
|
}
|
|
@@ -1,31 +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
|
export class EnrichContextFromResponsePhase {
|
|
2
|
+
config;
|
|
3
|
+
products;
|
|
11
4
|
constructor(config, products) {
|
|
12
5
|
this.config = config;
|
|
13
6
|
this.products = products;
|
|
14
7
|
}
|
|
15
|
-
execute(context) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return { done: false };
|
|
20
|
-
});
|
|
8
|
+
async execute(context) {
|
|
9
|
+
this.config.logger.debug('enrich context from response phase');
|
|
10
|
+
await this.addProductDataToContext(context);
|
|
11
|
+
return { done: false };
|
|
21
12
|
}
|
|
22
|
-
addProductDataToContext(context) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})));
|
|
29
|
-
});
|
|
13
|
+
async addProductDataToContext(context) {
|
|
14
|
+
await Promise.all(Object.entries(this.products)
|
|
15
|
+
.filter(([name, _]) => !!context.productData[name])
|
|
16
|
+
.map(async ([name, product]) => {
|
|
17
|
+
Object.assign(context.productData[name], await product?.enrichContextFromResponse(context));
|
|
18
|
+
}));
|
|
30
19
|
}
|
|
31
20
|
}
|
|
@@ -1,19 +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 FilterPhase {
|
|
2
|
+
filters;
|
|
11
3
|
constructor(filters) {
|
|
12
4
|
this.filters = filters;
|
|
13
5
|
}
|
|
14
|
-
execute(context) {
|
|
15
|
-
return
|
|
16
|
-
return { done: this.filters.some((filter) => filter.shouldFilter(context)) };
|
|
17
|
-
});
|
|
6
|
+
async execute(context) {
|
|
7
|
+
return { done: this.filters.some((filter) => filter.shouldFilter(context)) };
|
|
18
8
|
}
|
|
19
9
|
}
|
|
@@ -1,42 +1,31 @@
|
|
|
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 { MinimalResponseUtils } from '../../http';
|
|
11
2
|
export class FirstPartyPhase {
|
|
3
|
+
httpClient;
|
|
4
|
+
firstParties;
|
|
12
5
|
constructor(httpClient, firstParties) {
|
|
13
6
|
this.httpClient = httpClient;
|
|
14
7
|
this.firstParties = firstParties;
|
|
15
8
|
}
|
|
16
|
-
execute(context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return { done: true, response };
|
|
23
|
-
}
|
|
9
|
+
async execute(context) {
|
|
10
|
+
for (const firstParty of this.firstParties) {
|
|
11
|
+
const firstPartyData = await firstParty.handleFirstPartyRequest(context);
|
|
12
|
+
if (firstPartyData) {
|
|
13
|
+
const response = await this.sendFirstPartyRequest(firstPartyData);
|
|
14
|
+
return { done: true, response };
|
|
24
15
|
}
|
|
25
|
-
|
|
26
|
-
}
|
|
16
|
+
}
|
|
17
|
+
return { done: false };
|
|
27
18
|
}
|
|
28
|
-
sendFirstPartyRequest({ request, defaultResponse }) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
});
|
|
19
|
+
async sendFirstPartyRequest({ request, defaultResponse }) {
|
|
20
|
+
if (!request) {
|
|
21
|
+
return defaultResponse;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const response = await this.httpClient.send(request);
|
|
25
|
+
return MinimalResponseUtils.from(response);
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
return defaultResponse;
|
|
29
|
+
}
|
|
41
30
|
}
|
|
42
31
|
}
|
|
@@ -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 ModifyIncomingRequestPhase {
|
|
2
|
+
products;
|
|
11
3
|
constructor(products) {
|
|
12
4
|
this.products = products;
|
|
13
5
|
}
|
|
14
|
-
execute(context) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return { done: false };
|
|
18
|
-
});
|
|
6
|
+
async execute(context) {
|
|
7
|
+
await Promise.all(this.products.map((product) => product?.modifyIncomingRequest(context)));
|
|
8
|
+
return { done: false };
|
|
19
9
|
}
|
|
20
10
|
}
|
|
@@ -1,25 +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
|
import { PXHDSource, PXHDUtils } from '../../pxhd';
|
|
11
2
|
export class ModifyOutgoingResponsePhase {
|
|
3
|
+
products;
|
|
12
4
|
constructor(products) {
|
|
13
5
|
this.products = products;
|
|
14
6
|
}
|
|
15
|
-
execute(context) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return { done: false };
|
|
23
|
-
});
|
|
7
|
+
async execute(context) {
|
|
8
|
+
await Promise.all(this.products.map((product) => product?.modifyOutgoingResponse(context)));
|
|
9
|
+
if (context.pxhd?.source === PXHDSource.RISK) {
|
|
10
|
+
PXHDUtils.addPxhdToOutgoingResponse(context, context.response);
|
|
11
|
+
}
|
|
12
|
+
return { done: false };
|
|
24
13
|
}
|
|
25
14
|
}
|
|
@@ -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
|
import { TokenParseResult } from '../../risk_token';
|
|
11
2
|
import { transferExistingProperties, VidSource } from '../../utils';
|
|
12
3
|
export class ParseTokenPhase {
|
|
4
|
+
tokenParser;
|
|
13
5
|
constructor(tokenParser) {
|
|
14
6
|
this.tokenParser = tokenParser;
|
|
15
7
|
}
|
|
16
|
-
execute(context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return { done: false };
|
|
21
|
-
});
|
|
8
|
+
async execute(context) {
|
|
9
|
+
const tokenData = await this.tokenParser.parseToken(context);
|
|
10
|
+
this.addTokenDataToContext(context, tokenData);
|
|
11
|
+
return { done: false };
|
|
22
12
|
}
|
|
23
13
|
addTokenDataToContext(context, tokenData) {
|
|
24
14
|
Object.assign(context.tokenData, tokenData);
|
|
@@ -1,28 +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
|
export class PreflightPhase {
|
|
2
|
+
corsSupportEnabled;
|
|
3
|
+
filterPreflightRequestsEnabled;
|
|
4
|
+
cors;
|
|
11
5
|
constructor(config, cors) {
|
|
12
6
|
this.corsSupportEnabled = config.corsSupportEnabled;
|
|
13
7
|
this.filterPreflightRequestsEnabled = config.corsPreflightRequestFilterEnabled;
|
|
14
8
|
this.cors = cors;
|
|
15
9
|
}
|
|
16
|
-
execute(context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return { done: this.filterPreflightRequestsEnabled };
|
|
26
|
-
});
|
|
10
|
+
async execute(context) {
|
|
11
|
+
if (!this.corsSupportEnabled || !this.cors.isPreflightRequest(context)) {
|
|
12
|
+
return { done: false };
|
|
13
|
+
}
|
|
14
|
+
const response = await this.cors.runPreflightCustomHandler(context);
|
|
15
|
+
if (response) {
|
|
16
|
+
return { done: true, response };
|
|
17
|
+
}
|
|
18
|
+
return { done: this.filterPreflightRequestsEnabled };
|
|
27
19
|
}
|
|
28
20
|
}
|
|
@@ -1,46 +1,36 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Action } from '../../action';
|
|
11
2
|
import { transferExistingProperties } from '../../utils';
|
|
12
3
|
import { DecideActionPhase } from './DecideActionPhase';
|
|
4
|
+
import { ProductName } from '../../products';
|
|
13
5
|
import { PXHDSource } from '../../pxhd';
|
|
14
6
|
export class RiskApiPhase extends DecideActionPhase {
|
|
7
|
+
products;
|
|
8
|
+
riskApiClient;
|
|
15
9
|
constructor(config, products, riskApiClient) {
|
|
16
10
|
super(config);
|
|
17
11
|
this.products = products;
|
|
18
12
|
this.riskApiClient = riskApiClient;
|
|
19
13
|
}
|
|
20
|
-
execute(context) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return { done: false };
|
|
28
|
-
});
|
|
14
|
+
async execute(context) {
|
|
15
|
+
if (this.shouldTriggerRiskApi(context)) {
|
|
16
|
+
await this.triggerRiskApi(context);
|
|
17
|
+
await this.enrichContextFromRiskApi(context);
|
|
18
|
+
await this.updateContextDecision(context);
|
|
19
|
+
}
|
|
20
|
+
return { done: false };
|
|
29
21
|
}
|
|
30
22
|
shouldTriggerRiskApi(context) {
|
|
31
23
|
return context.action === Action.TRIGGER_RISK_API;
|
|
32
24
|
}
|
|
33
|
-
triggerRiskApi(context) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
async triggerRiskApi(context) {
|
|
26
|
+
context.riskApiData.s2sCallReason =
|
|
27
|
+
context.reasons?.[ProductName.BOT_DEFENDER] || context.reasons?.[ProductName.CREDENTIAL_INTELLIGENCE];
|
|
28
|
+
const riskApiData = await this.riskApiClient.executeRiskApi(context);
|
|
29
|
+
Object.assign(context.riskApiData, riskApiData);
|
|
38
30
|
}
|
|
39
|
-
enrichContextFromRiskApi(context) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
yield this.enrichContextWithProductDataFromRiskApi(context);
|
|
43
|
-
});
|
|
31
|
+
async enrichContextFromRiskApi(context) {
|
|
32
|
+
this.addRiskApiDataToContext(context);
|
|
33
|
+
await this.enrichContextWithProductDataFromRiskApi(context);
|
|
44
34
|
}
|
|
45
35
|
addRiskApiDataToContext(context) {
|
|
46
36
|
const { riskResponse } = context.riskApiData;
|
|
@@ -64,13 +54,11 @@ export class RiskApiPhase extends DecideActionPhase {
|
|
|
64
54
|
};
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
|
-
enrichContextWithProductDataFromRiskApi(context) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})));
|
|
74
|
-
});
|
|
57
|
+
async enrichContextWithProductDataFromRiskApi(context) {
|
|
58
|
+
await Promise.all(Object.entries(this.products).map(async ([name, product]) => {
|
|
59
|
+
if (context.productData[name]) {
|
|
60
|
+
Object.assign(context.productData[name], await product?.enrichContextFromRiskApi(context));
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
75
63
|
}
|
|
76
64
|
}
|
|
@@ -1,28 +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
|
import { Action } from '../../action';
|
|
11
2
|
export class SendAsyncActivitiesOnRequestPhase {
|
|
3
|
+
activityClient;
|
|
12
4
|
constructor(activityClient) {
|
|
13
5
|
this.activityClient = activityClient;
|
|
14
6
|
}
|
|
15
|
-
execute(context) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return { done: false };
|
|
21
|
-
});
|
|
7
|
+
async execute(context) {
|
|
8
|
+
if (context.action === Action.BLOCK) {
|
|
9
|
+
await this.sendAsyncActivity(context);
|
|
10
|
+
}
|
|
11
|
+
return { done: false };
|
|
22
12
|
}
|
|
23
|
-
sendAsyncActivity(context) {
|
|
24
|
-
|
|
25
|
-
yield this.activityClient.sendActivities(context);
|
|
26
|
-
});
|
|
13
|
+
async sendAsyncActivity(context) {
|
|
14
|
+
await this.activityClient.sendActivities(context);
|
|
27
15
|
}
|
|
28
16
|
}
|
|
@@ -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 SendAsyncActivitiesOnResponsePhase {
|
|
2
|
+
activityClient;
|
|
11
3
|
constructor(activityClient) {
|
|
12
4
|
this.activityClient = activityClient;
|
|
13
5
|
}
|
|
14
|
-
execute(context) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return { done: false };
|
|
18
|
-
});
|
|
6
|
+
async execute(context) {
|
|
7
|
+
await this.activityClient.sendActivities(context);
|
|
8
|
+
return { done: false };
|
|
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
|
import { X_PX_ENFORCER_LOG_HEADER } from '../../logger';
|
|
11
2
|
export class SendLogsPhase {
|
|
3
|
+
config;
|
|
4
|
+
logServiceClient;
|
|
12
5
|
constructor(config, logServiceClient) {
|
|
13
6
|
this.config = config;
|
|
14
7
|
this.logServiceClient = logServiceClient;
|
|
15
8
|
}
|
|
16
|
-
execute(context) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return { done: false };
|
|
24
|
-
});
|
|
9
|
+
async execute(context) {
|
|
10
|
+
const headerValue = context.requestData.headers[X_PX_ENFORCER_LOG_HEADER]?.[0];
|
|
11
|
+
if (headerValue == this.config.loggerAuthToken) {
|
|
12
|
+
await this.logServiceClient.sendLogs(context, this.config.logger.getLogs());
|
|
13
|
+
}
|
|
14
|
+
return { done: false };
|
|
25
15
|
}
|
|
26
16
|
}
|
|
@@ -1,29 +1,17 @@
|
|
|
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 TelemetryPhase {
|
|
2
|
+
telemetry;
|
|
11
3
|
constructor(telemetry) {
|
|
12
4
|
this.telemetry = telemetry;
|
|
13
5
|
}
|
|
14
|
-
execute(context) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return { done: false };
|
|
21
|
-
});
|
|
6
|
+
async execute(context) {
|
|
7
|
+
if (await this.telemetry.isValidTelemetryRequest(context)) {
|
|
8
|
+
await this.sendTelemetry(context);
|
|
9
|
+
return { done: true };
|
|
10
|
+
}
|
|
11
|
+
return { done: false };
|
|
22
12
|
}
|
|
23
13
|
// Note: If await is not necessary, can be overridden
|
|
24
|
-
sendTelemetry(context) {
|
|
25
|
-
|
|
26
|
-
yield this.telemetry.sendTelemetry(context);
|
|
27
|
-
});
|
|
14
|
+
async sendTelemetry(context) {
|
|
15
|
+
await this.telemetry.sendTelemetry(context);
|
|
28
16
|
}
|
|
29
17
|
}
|