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,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
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IContext } from '../../context';
|
|
2
|
+
import { IPhase } from '../IPhase';
|
|
3
|
+
import { PhaseResult } from '../PhaseResult';
|
|
4
|
+
import { IConfiguration } from '../../config';
|
|
5
|
+
import { ILogServiceClient } from '../../logger';
|
|
6
|
+
export declare class SendLogsPhase<Req, Res> implements IPhase<Req, Res> {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly logServiceClient;
|
|
9
|
+
constructor(config: IConfiguration<Req, Res>, logServiceClient: ILogServiceClient<Req, Res>);
|
|
10
|
+
execute(context: IContext<Req, Res>): Promise<PhaseResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { X_PX_ENFORCER_LOG_HEADER } from '../../logger';
|
|
2
|
+
export class SendLogsPhase {
|
|
3
|
+
config;
|
|
4
|
+
logServiceClient;
|
|
5
|
+
constructor(config, logServiceClient) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
this.logServiceClient = logServiceClient;
|
|
8
|
+
}
|
|
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 };
|
|
15
|
+
}
|
|
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
|
}
|
package/lib/phase/impl/index.js
CHANGED
|
@@ -1,48 +1,30 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { getPropertyFromObject } from '../../utils';
|
|
11
2
|
import { CROSS_TAB_SESSION_COOKIE_NAME } from './constants';
|
|
12
3
|
export class AccountDefender {
|
|
4
|
+
config;
|
|
5
|
+
base64Utils;
|
|
13
6
|
constructor(config, options) {
|
|
14
7
|
this.config = config;
|
|
15
8
|
this.base64Utils = options.base64Utils;
|
|
16
9
|
}
|
|
17
|
-
enrichContextFromRequest(context) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return Object.assign({ crossTabSession }, jwtData);
|
|
22
|
-
});
|
|
10
|
+
async enrichContextFromRequest(context) {
|
|
11
|
+
const crossTabSession = context.requestData.cookies[CROSS_TAB_SESSION_COOKIE_NAME];
|
|
12
|
+
const jwtData = this.getJwtData(context.requestData);
|
|
13
|
+
return { crossTabSession, ...jwtData };
|
|
23
14
|
}
|
|
24
|
-
enrichContextFromRiskApi(context) {
|
|
25
|
-
return
|
|
26
|
-
return;
|
|
27
|
-
});
|
|
15
|
+
async enrichContextFromRiskApi(context) {
|
|
16
|
+
return;
|
|
28
17
|
}
|
|
29
|
-
enrichContextFromResponse(context) {
|
|
30
|
-
return
|
|
31
|
-
return;
|
|
32
|
-
});
|
|
18
|
+
async enrichContextFromResponse(context) {
|
|
19
|
+
return;
|
|
33
20
|
}
|
|
34
|
-
modifyIncomingRequest(context) {
|
|
35
|
-
return
|
|
36
|
-
return;
|
|
37
|
-
});
|
|
21
|
+
async modifyIncomingRequest(context) {
|
|
22
|
+
return;
|
|
38
23
|
}
|
|
39
|
-
modifyOutgoingResponse(context) {
|
|
40
|
-
return
|
|
41
|
-
return;
|
|
42
|
-
});
|
|
24
|
+
async modifyOutgoingResponse(context) {
|
|
25
|
+
return;
|
|
43
26
|
}
|
|
44
27
|
getJwtData(requestData) {
|
|
45
|
-
var _a;
|
|
46
28
|
let jwtToken;
|
|
47
29
|
let userIdFieldName;
|
|
48
30
|
let additionalFieldNames;
|
|
@@ -54,7 +36,7 @@ export class AccountDefender {
|
|
|
54
36
|
}
|
|
55
37
|
}
|
|
56
38
|
if (!jwtToken && this.config.jwtHeaderName) {
|
|
57
|
-
jwtToken =
|
|
39
|
+
jwtToken = requestData.headers[this.config.jwtHeaderName]?.[0];
|
|
58
40
|
if (jwtToken) {
|
|
59
41
|
userIdFieldName = this.config.jwtHeaderUserIdFieldName;
|
|
60
42
|
additionalFieldNames = this.config.jwtHeaderAdditionalFieldNames;
|
|
@@ -84,9 +66,8 @@ export class AccountDefender {
|
|
|
84
66
|
return null;
|
|
85
67
|
}
|
|
86
68
|
getDecodedJwt(jwt) {
|
|
87
|
-
var _a;
|
|
88
69
|
try {
|
|
89
|
-
const encodedPayload =
|
|
70
|
+
const encodedPayload = jwt.split('.')?.[1];
|
|
90
71
|
const base64 = encodedPayload.replace('-', '+').replace('_', '/');
|
|
91
72
|
return JSON.parse(this.base64Utils.base64Decode(base64));
|
|
92
73
|
}
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Action } from '../../action';
|
|
11
2
|
import { TokenParseResult } from '../../risk_token';
|
|
12
3
|
import { RiskApiCallResult } from '../../risk_api';
|
|
@@ -18,30 +9,31 @@ import { BotDefenderBlockReason, BotDefenderPassReason, BotDefenderS2SCallReason
|
|
|
18
9
|
import { BotDefenderUtils } from './BotDefenderUtils';
|
|
19
10
|
import { DefaultBotDefenderBlocker } from './block';
|
|
20
11
|
export class BotDefender {
|
|
12
|
+
config;
|
|
13
|
+
firstParty;
|
|
14
|
+
filter;
|
|
15
|
+
blocker;
|
|
21
16
|
constructor(config, options) {
|
|
22
|
-
var _a, _b, _c;
|
|
23
17
|
this.config = config;
|
|
24
|
-
this.firstParty =
|
|
25
|
-
this.filter =
|
|
26
|
-
this.blocker =
|
|
18
|
+
this.firstParty = options.firstParty ?? new DefaultBotDefenderFirstParty(config);
|
|
19
|
+
this.filter = options.filter ?? new DefaultBotDefenderFilter(config, options.ipRangeChecker);
|
|
20
|
+
this.blocker = options.blocker ?? new DefaultBotDefenderBlocker(config, options.base64Utils);
|
|
27
21
|
}
|
|
28
|
-
handleFirstPartyRequest(context) {
|
|
29
|
-
return
|
|
30
|
-
return this.firstParty.handleFirstPartyRequest(context);
|
|
31
|
-
});
|
|
22
|
+
async handleFirstPartyRequest(context) {
|
|
23
|
+
return this.firstParty.handleFirstPartyRequest(context);
|
|
32
24
|
}
|
|
33
25
|
shouldFilter(context) {
|
|
34
26
|
return this.filter.shouldFilter(context);
|
|
35
27
|
}
|
|
36
|
-
enrichContextFromRequest(context) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
28
|
+
async enrichContextFromRequest(context) {
|
|
29
|
+
const isMonitoredRequest = this.isMonitoredRoute(context);
|
|
30
|
+
const isSensitiveRequest = this.isSensitiveRequest(context) || context.graphqlData?.some((operation) => operation.sensitive);
|
|
31
|
+
const actionData = await this.getTokenAction(context, isMonitoredRequest, isSensitiveRequest);
|
|
32
|
+
return {
|
|
33
|
+
...actionData,
|
|
34
|
+
isMonitoredRequest,
|
|
35
|
+
isSensitiveRequest,
|
|
36
|
+
};
|
|
45
37
|
}
|
|
46
38
|
isMonitoredRoute(context) {
|
|
47
39
|
return isMonitoredRequest(this.config, context);
|
|
@@ -50,28 +42,23 @@ export class BotDefender {
|
|
|
50
42
|
// TODO: Include custom sensitive request function
|
|
51
43
|
return isRouteInPatterns(url.pathname, this.config.sensitiveRoutes);
|
|
52
44
|
}
|
|
53
|
-
enrichContextFromResponse(context) {
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
case TokenParseResult.SUCCESSFUL:
|
|
68
|
-
return this.getActionForSuccessfulTokenParse(context, isMonitoredRequest, isSensitiveRequest);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
45
|
+
async enrichContextFromResponse(context) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
async getTokenAction(context, isMonitoredRequest, isSensitiveRequest) {
|
|
49
|
+
switch (context.tokenData.tokenParseResult) {
|
|
50
|
+
case TokenParseResult.NONE:
|
|
51
|
+
return new BotDefenderActionData(Action.TRIGGER_RISK_API, this.getNoTokenS2SCallReason(context));
|
|
52
|
+
case TokenParseResult.DECRYPTION_FAILED:
|
|
53
|
+
return new BotDefenderActionData(Action.TRIGGER_RISK_API, BotDefenderS2SCallReason.COOKIE_DECRYPTION_FAILED);
|
|
54
|
+
case TokenParseResult.VALIDATION_FAILED:
|
|
55
|
+
return new BotDefenderActionData(Action.TRIGGER_RISK_API, BotDefenderS2SCallReason.COOKIE_VALIDATION_FAILED);
|
|
56
|
+
case TokenParseResult.SUCCESSFUL:
|
|
57
|
+
return this.getActionForSuccessfulTokenParse(context, isMonitoredRequest, isSensitiveRequest);
|
|
58
|
+
}
|
|
71
59
|
}
|
|
72
60
|
getNoTokenS2SCallReason({ pxhd, isMobile, tokenData, }) {
|
|
73
|
-
|
|
74
|
-
if (isMobile && ((_a = tokenData.mobileData) === null || _a === void 0 ? void 0 : _a.mobileError)) {
|
|
61
|
+
if (isMobile && tokenData.mobileData?.mobileError) {
|
|
75
62
|
return BotDefenderUtils.getS2SCallReasonFromMobileError(tokenData.mobileData.mobileError);
|
|
76
63
|
}
|
|
77
64
|
if (pxhd) {
|
|
@@ -91,24 +78,20 @@ export class BotDefender {
|
|
|
91
78
|
}
|
|
92
79
|
return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.COOKIE);
|
|
93
80
|
}
|
|
94
|
-
enrichContextFromRiskApi(context) {
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
case RiskApiCallResult.SUCCESSFUL:
|
|
109
|
-
return this.getSuccessfulRiskApiAction(riskApiData.riskResponse, bd.isMonitoredRequest);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
81
|
+
async enrichContextFromRiskApi(context) {
|
|
82
|
+
return await this.getRiskApiActionData(context);
|
|
83
|
+
}
|
|
84
|
+
async getRiskApiActionData({ riskApiData, productData: { bd }, }) {
|
|
85
|
+
switch (riskApiData.riskApiCallResult) {
|
|
86
|
+
case RiskApiCallResult.NONE:
|
|
87
|
+
throw new EnforcerError('risk api call result should not be none!');
|
|
88
|
+
case RiskApiCallResult.ERROR:
|
|
89
|
+
return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_ERROR);
|
|
90
|
+
case RiskApiCallResult.TIMEOUT:
|
|
91
|
+
return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_TIMEOUT);
|
|
92
|
+
case RiskApiCallResult.SUCCESSFUL:
|
|
93
|
+
return this.getSuccessfulRiskApiAction(riskApiData.riskResponse, bd.isMonitoredRequest);
|
|
94
|
+
}
|
|
112
95
|
}
|
|
113
96
|
getSuccessfulRiskApiAction(riskResponse, isMonitored) {
|
|
114
97
|
if (riskResponse.score >= this.config.blockingScore) {
|
|
@@ -122,14 +105,10 @@ export class BotDefender {
|
|
|
122
105
|
createBlockResponse(context) {
|
|
123
106
|
return this.blocker.createBlockResponse(context);
|
|
124
107
|
}
|
|
125
|
-
modifyIncomingRequest(context) {
|
|
126
|
-
|
|
127
|
-
// intentionally left blank
|
|
128
|
-
});
|
|
108
|
+
async modifyIncomingRequest(context) {
|
|
109
|
+
// intentionally left blank
|
|
129
110
|
}
|
|
130
|
-
modifyOutgoingResponse(context) {
|
|
131
|
-
|
|
132
|
-
// intentionally left blank
|
|
133
|
-
});
|
|
111
|
+
async modifyOutgoingResponse(context) {
|
|
112
|
+
// intentionally left blank
|
|
134
113
|
}
|
|
135
114
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { ReadonlyContext } from '../../../context';
|
|
2
2
|
import { IConfiguration } from '../../../config';
|
|
3
3
|
import { IBase64Utils } from '../../../utils';
|
|
4
|
-
import { IConditionalBlocker } from '../../../blocker';
|
|
4
|
+
import { IBlocker, IConditionalBlocker } from '../../../blocker';
|
|
5
5
|
import { IMinimalResponse } from '../../../http';
|
|
6
6
|
export declare class DefaultBotDefenderBlocker<Req, Res> implements IConditionalBlocker<Req, Res> {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
protected readonly config: IConfiguration<Req, Res>;
|
|
8
|
+
protected readonly captchaBlocker: IBlocker<Req, Res>;
|
|
9
9
|
constructor(config: IConfiguration<Req, Res>, base64Utils: IBase64Utils);
|
|
10
10
|
shouldBlock({ action, reasons, productData }: ReadonlyContext<Req, Res>): boolean;
|
|
11
11
|
createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
|
|
12
|
-
|
|
12
|
+
protected createRateLimitResponse(): IMinimalResponse;
|
|
13
13
|
private createCaptchaResponse;
|
|
14
14
|
}
|
|
@@ -5,12 +5,14 @@ import { ProductName } from '../../utils';
|
|
|
5
5
|
import { CaptchaBlocker } from './captcha';
|
|
6
6
|
import { RATE_LIMIT_TEMPLATE } from './templates';
|
|
7
7
|
export class DefaultBotDefenderBlocker {
|
|
8
|
+
config;
|
|
9
|
+
captchaBlocker;
|
|
8
10
|
constructor(config, base64Utils) {
|
|
9
11
|
this.config = config;
|
|
10
|
-
this.
|
|
12
|
+
this.captchaBlocker = new CaptchaBlocker(config, base64Utils);
|
|
11
13
|
}
|
|
12
14
|
shouldBlock({ action, reasons, productData }) {
|
|
13
|
-
return action === Action.BLOCK && !!
|
|
15
|
+
return action === Action.BLOCK && !!reasons?.[ProductName.BOT_DEFENDER];
|
|
14
16
|
}
|
|
15
17
|
createBlockResponse(context) {
|
|
16
18
|
switch (context.blockAction) {
|
|
@@ -34,6 +36,6 @@ export class DefaultBotDefenderBlocker {
|
|
|
34
36
|
});
|
|
35
37
|
}
|
|
36
38
|
createCaptchaResponse(context) {
|
|
37
|
-
return this.
|
|
39
|
+
return this.captchaBlocker.createBlockResponse(context);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -3,11 +3,14 @@ import { ReadonlyContext } from '../../../../context';
|
|
|
3
3
|
import { IBase64Utils } from '../../../../utils';
|
|
4
4
|
import { IBlocker } from '../../../../blocker';
|
|
5
5
|
import { IMinimalResponse } from '../../../../http';
|
|
6
|
+
import { JsonCaptchaBlocker } from './JsonCaptchaBlocker';
|
|
7
|
+
import { MobileCaptchaBlocker } from './MobileCaptchaBlocker';
|
|
8
|
+
import { HtmlCaptchaBlocker } from './HtmlCaptchaBlocker';
|
|
6
9
|
export declare class CaptchaBlocker<Req, Res> implements IBlocker<Req, Res> {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
protected readonly config: IConfiguration<Req, Res>;
|
|
11
|
+
protected readonly jsonCaptchaBlocker: JsonCaptchaBlocker<Req, Res>;
|
|
12
|
+
protected readonly mobileCaptchaBlocker: MobileCaptchaBlocker<Req, Res>;
|
|
13
|
+
protected readonly htmlCaptchaBlocker: HtmlCaptchaBlocker<Req, Res>;
|
|
11
14
|
constructor(config: IConfiguration<Req, Res>, base64Utils: IBase64Utils);
|
|
12
15
|
createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
|
|
13
16
|
}
|
|
@@ -2,19 +2,23 @@ import { JsonCaptchaBlocker } from './JsonCaptchaBlocker';
|
|
|
2
2
|
import { MobileCaptchaBlocker } from './MobileCaptchaBlocker';
|
|
3
3
|
import { HtmlCaptchaBlocker } from './HtmlCaptchaBlocker';
|
|
4
4
|
export class CaptchaBlocker {
|
|
5
|
+
config;
|
|
6
|
+
jsonCaptchaBlocker;
|
|
7
|
+
mobileCaptchaBlocker;
|
|
8
|
+
htmlCaptchaBlocker;
|
|
5
9
|
constructor(config, base64Utils) {
|
|
6
10
|
this.config = config;
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
11
|
+
this.jsonCaptchaBlocker = new JsonCaptchaBlocker(config);
|
|
12
|
+
this.mobileCaptchaBlocker = new MobileCaptchaBlocker(config, base64Utils);
|
|
13
|
+
this.htmlCaptchaBlocker = new HtmlCaptchaBlocker(config);
|
|
10
14
|
}
|
|
11
15
|
createBlockResponse(context) {
|
|
12
|
-
if (this.
|
|
13
|
-
return this.
|
|
16
|
+
if (this.mobileCaptchaBlocker.shouldBlock(context)) {
|
|
17
|
+
return this.mobileCaptchaBlocker.createBlockResponse(context);
|
|
14
18
|
}
|
|
15
|
-
if (this.
|
|
16
|
-
return this.
|
|
19
|
+
if (this.jsonCaptchaBlocker.shouldBlock(context)) {
|
|
20
|
+
return this.jsonCaptchaBlocker.createBlockResponse(context);
|
|
17
21
|
}
|
|
18
|
-
return this.
|
|
22
|
+
return this.htmlCaptchaBlocker.createBlockResponse(context);
|
|
19
23
|
}
|
|
20
24
|
}
|
|
@@ -3,7 +3,7 @@ import { ReadonlyContext } from '../../../../context';
|
|
|
3
3
|
import { IBlocker } from '../../../../blocker';
|
|
4
4
|
import { IMinimalResponse } from '../../../../http';
|
|
5
5
|
export declare class HtmlCaptchaBlocker<Req, Res> implements IBlocker<Req, Res> {
|
|
6
|
-
|
|
6
|
+
protected readonly config: IConfiguration<Req, Res>;
|
|
7
7
|
constructor(config: IConfiguration<Req, Res>);
|
|
8
8
|
createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
|
|
9
9
|
}
|