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,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
|
}
|
|
@@ -2,6 +2,7 @@ import { ContentType, CONTENT_TYPE_HEADER_NAME, MinimalResponseImpl } from '../.
|
|
|
2
2
|
import { createBlockData, renderHtml } from '../utils';
|
|
3
3
|
import { CAPTCHA_TEMPLATE } from '../templates';
|
|
4
4
|
export class HtmlCaptchaBlocker {
|
|
5
|
+
config;
|
|
5
6
|
constructor(config) {
|
|
6
7
|
this.config = config;
|
|
7
8
|
}
|
|
@@ -3,7 +3,7 @@ import { ReadonlyContext } from '../../../../context';
|
|
|
3
3
|
import { IConditionalBlocker } from '../../../../blocker';
|
|
4
4
|
import { IMinimalResponse } from '../../../../http';
|
|
5
5
|
export declare class JsonCaptchaBlocker<Req, Res> implements IConditionalBlocker<Req, Res> {
|
|
6
|
-
|
|
6
|
+
protected readonly config: IConfiguration<Req, Res>;
|
|
7
7
|
constructor(config: IConfiguration<Req, Res>);
|
|
8
8
|
shouldBlock(context: ReadonlyContext<Req, Res>): boolean;
|
|
9
9
|
createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
|
|
@@ -2,6 +2,7 @@ import { BlockAction } from '../../../../blocker';
|
|
|
2
2
|
import { ContentType, CONTENT_TYPE_HEADER_NAME, ACCEPT_HEADER_NAME, MinimalResponseImpl, } from '../../../../http';
|
|
3
3
|
import { createBlockData } from '../utils';
|
|
4
4
|
export class JsonCaptchaBlocker {
|
|
5
|
+
config;
|
|
5
6
|
constructor(config) {
|
|
6
7
|
this.config = config;
|
|
7
8
|
}
|
|
@@ -9,10 +10,10 @@ export class JsonCaptchaBlocker {
|
|
|
9
10
|
if (!this.config.advancedBlockingResponseEnabled) {
|
|
10
11
|
return false;
|
|
11
12
|
}
|
|
12
|
-
const acceptHeaderValue = context.requestData.request.headers.get(ACCEPT_HEADER_NAME) ||
|
|
13
|
-
|
|
14
|
-
''
|
|
15
|
-
|
|
13
|
+
const acceptHeaderValue = context.requestData.request.headers.get(ACCEPT_HEADER_NAME) || '';
|
|
14
|
+
const acceptHeaderContainsJson = acceptHeaderValue
|
|
15
|
+
?.split(',')
|
|
16
|
+
.some((value) => value.toLowerCase() === ContentType.APPLICATION_JSON);
|
|
16
17
|
return !context.isMobile && context.blockAction !== BlockAction.RATE_LIMIT && acceptHeaderContainsJson;
|
|
17
18
|
}
|
|
18
19
|
createBlockResponse(context) {
|
|
@@ -4,8 +4,8 @@ import { IBase64Utils } from '../../../../utils';
|
|
|
4
4
|
import { IConditionalBlocker } from '../../../../blocker';
|
|
5
5
|
import { IMinimalResponse } from '../../../../http';
|
|
6
6
|
export declare class MobileCaptchaBlocker<Req, Res> implements IConditionalBlocker<Req, Res> {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
protected readonly config: IConfiguration<Req, Res>;
|
|
8
|
+
protected readonly base64Utils: IBase64Utils;
|
|
9
9
|
constructor(config: IConfiguration<Req, Res>, base64Utils: IBase64Utils);
|
|
10
10
|
shouldBlock(context: ReadonlyContext<Req, Res>): boolean;
|
|
11
11
|
createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
|
|
@@ -3,6 +3,8 @@ import { ContentType, CONTENT_TYPE_HEADER_NAME, MinimalResponseImpl } from '../.
|
|
|
3
3
|
import { createBlockData, renderHtml } from '../utils';
|
|
4
4
|
import { CAPTCHA_TEMPLATE } from '../templates';
|
|
5
5
|
export class MobileCaptchaBlocker {
|
|
6
|
+
config;
|
|
7
|
+
base64Utils;
|
|
6
8
|
constructor(config, base64Utils) {
|
|
7
9
|
this.config = config;
|
|
8
10
|
this.base64Utils = base64Utils;
|
|
@@ -12,7 +12,6 @@ export const renderHtml = (htmlTemplate, blockData) => {
|
|
|
12
12
|
return htmlTemplate;
|
|
13
13
|
};
|
|
14
14
|
export const createBlockData = (config, context) => {
|
|
15
|
-
var _a, _b;
|
|
16
15
|
const captchaScriptSuffix = '/captcha.js';
|
|
17
16
|
const captchaParams = `?a=${context.blockAction}&u=${context.uuid}&v=${context.vid || ''}&m=${context.isMobile ? '1' : '0'}`;
|
|
18
17
|
let jsClientSrc = `${config.backendClientUrl}/${config.appId}/main.min.js`;
|
|
@@ -28,7 +27,7 @@ export const createBlockData = (config, context) => {
|
|
|
28
27
|
const altBlockScript = `${config.altBackendCaptchaUrl}/${config.appId}${captchaScriptSuffix}${captchaParams}`;
|
|
29
28
|
return {
|
|
30
29
|
appId: config.appId,
|
|
31
|
-
vid: context.vid ||
|
|
30
|
+
vid: context.vid || context.requestData?.cookies?.[PXVID_COOKIE_NAME] || '',
|
|
32
31
|
uuid: context.uuid || '',
|
|
33
32
|
isMobile: context.isMobile,
|
|
34
33
|
customLogo: config.customLogo || '',
|
|
@@ -2,6 +2,8 @@ import { HttpMethod } from '../../../http';
|
|
|
2
2
|
import { FilterReason } from '../../../filter';
|
|
3
3
|
import { getExtension, isRouteInPatterns } from '../../../utils';
|
|
4
4
|
export class DefaultBotDefenderFilter {
|
|
5
|
+
config;
|
|
6
|
+
ipRangeChecker;
|
|
5
7
|
constructor(config, ipRangeChecker) {
|
|
6
8
|
this.config = config;
|
|
7
9
|
this.ipRangeChecker = ipRangeChecker;
|
|
@@ -1,61 +1,47 @@
|
|
|
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 { removeSensitiveHeaders } from '../../../utils';
|
|
11
|
-
import { COOKIE_HEADER_NAME, HOST_HEADER_NAME, X_FORWARDED_FOR_HEADER_NAME, OutgoingRequestImpl, MinimalResponseImpl, toMutableHeaders, } from '../../../http';
|
|
2
|
+
import { COOKIE_HEADER_NAME, HOST_HEADER_NAME, X_FORWARDED_FOR_HEADER_NAME, OutgoingRequestImpl, MinimalResponseImpl, toMutableHeaders, URLUtils, } from '../../../http';
|
|
12
3
|
import { getFirstPartyCaptchaScriptPathPrefixes, getFirstPartySensorScriptPaths, getFirstPartyXhrPathPrefixes, } from './utils';
|
|
13
4
|
import { DEFAULT_CLIENT_RESPONSE_OPTIONS, DEFAULT_GIF_RESPONSE, DEFAULT_XHR_RESPONSE, FIRST_PARTY_HEADER_NAME, FIRST_PARTY_HEADER_VALUE, X_PX_ENFORCER_TRUE_IP_HEADER_NAME, } from './constants';
|
|
14
5
|
import { FirstPartySuffix } from './FirstPartySuffix';
|
|
15
6
|
export class DefaultBotDefenderFirstParty {
|
|
7
|
+
config;
|
|
16
8
|
constructor(config) {
|
|
17
9
|
this.config = config;
|
|
18
10
|
}
|
|
19
|
-
handleFirstPartyRequest(context) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return null;
|
|
34
|
-
});
|
|
11
|
+
async handleFirstPartyRequest(context) {
|
|
12
|
+
const { pathname } = context.requestData.url;
|
|
13
|
+
if (getFirstPartySensorScriptPaths(this.config).includes(pathname)) {
|
|
14
|
+
return await this.proxySensorScriptRequest(context);
|
|
15
|
+
}
|
|
16
|
+
const xhrPrefix = getFirstPartyXhrPathPrefixes(this.config).find((prefix) => pathname.startsWith(prefix));
|
|
17
|
+
if (xhrPrefix) {
|
|
18
|
+
return await this.proxyXhrRequest(context, xhrPrefix);
|
|
19
|
+
}
|
|
20
|
+
const captchaPrefix = getFirstPartyCaptchaScriptPathPrefixes(this.config).find((prefix) => pathname.startsWith(prefix));
|
|
21
|
+
if (captchaPrefix) {
|
|
22
|
+
return await this.proxyCaptchaScriptRequest(context);
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
35
25
|
}
|
|
36
|
-
proxySensorScriptRequest(context) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return { request, defaultResponse };
|
|
46
|
-
});
|
|
26
|
+
async proxySensorScriptRequest(context) {
|
|
27
|
+
const defaultResponse = new MinimalResponseImpl(DEFAULT_CLIENT_RESPONSE_OPTIONS);
|
|
28
|
+
if (!this.config.firstPartyEnabled) {
|
|
29
|
+
return { defaultResponse };
|
|
30
|
+
}
|
|
31
|
+
const url = this.getThirdPartySensorScriptUrl();
|
|
32
|
+
const request = await this.getOutgoingRequest(url, context);
|
|
33
|
+
this.config.logger.debug(`proxying first party sensor script ${context.requestData.url.pathname} to ${url}`);
|
|
34
|
+
return { request, defaultResponse };
|
|
47
35
|
}
|
|
48
|
-
proxyXhrRequest(context, prefix) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return { request, defaultResponse };
|
|
58
|
-
});
|
|
36
|
+
async proxyXhrRequest(context, prefix) {
|
|
37
|
+
const defaultResponse = DefaultBotDefenderFirstParty.getDefaultXhrResponse(context.requestData.url.pathname);
|
|
38
|
+
if (!this.config.firstPartyEnabled) {
|
|
39
|
+
return { defaultResponse };
|
|
40
|
+
}
|
|
41
|
+
const url = this.getThirdPartyXhrUrl(context, prefix);
|
|
42
|
+
const request = await this.getOutgoingRequest(url, context);
|
|
43
|
+
this.config.logger.debug(`proxying first party XHR request ${context.requestData.url.pathname} to ${url}`);
|
|
44
|
+
return { request, defaultResponse };
|
|
59
45
|
}
|
|
60
46
|
static getDefaultXhrResponse(path) {
|
|
61
47
|
const { content, options } = path.endsWith('.gif') ? DEFAULT_GIF_RESPONSE : DEFAULT_XHR_RESPONSE;
|
|
@@ -65,26 +51,22 @@ export class DefaultBotDefenderFirstParty {
|
|
|
65
51
|
headers: options.headers,
|
|
66
52
|
});
|
|
67
53
|
}
|
|
68
|
-
proxyCaptchaScriptRequest(context) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return { request, defaultResponse };
|
|
78
|
-
});
|
|
54
|
+
async proxyCaptchaScriptRequest(context) {
|
|
55
|
+
const defaultResponse = new MinimalResponseImpl(DEFAULT_CLIENT_RESPONSE_OPTIONS);
|
|
56
|
+
if (!this.config.firstPartyEnabled) {
|
|
57
|
+
return { defaultResponse };
|
|
58
|
+
}
|
|
59
|
+
const url = this.getThirdPartyCaptchaScriptUrl(context);
|
|
60
|
+
const request = await this.getOutgoingRequest(url, context);
|
|
61
|
+
this.config.logger.debug(`proxying first party captcha script ${context.requestData.url.pathname} to ${url}`);
|
|
62
|
+
return { request, defaultResponse };
|
|
79
63
|
}
|
|
80
|
-
getOutgoingRequest(url, { requestData, vid }) {
|
|
81
|
-
return
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
body: requestData.request.body,
|
|
87
|
-
});
|
|
64
|
+
async getOutgoingRequest(url, { requestData, vid }) {
|
|
65
|
+
return new OutgoingRequestImpl({
|
|
66
|
+
url: url,
|
|
67
|
+
method: requestData.method,
|
|
68
|
+
headers: this.prepareFirstPartyHeaders(url, requestData, vid),
|
|
69
|
+
body: requestData.request.body,
|
|
88
70
|
});
|
|
89
71
|
}
|
|
90
72
|
prepareFirstPartyHeaders(url, requestData, vid) {
|
|
@@ -105,7 +87,8 @@ export class DefaultBotDefenderFirstParty {
|
|
|
105
87
|
return headers;
|
|
106
88
|
}
|
|
107
89
|
setHostHeader(headers, url) {
|
|
108
|
-
|
|
90
|
+
const { host } = URLUtils.parseURL(url);
|
|
91
|
+
headers[HOST_HEADER_NAME] = [host];
|
|
109
92
|
}
|
|
110
93
|
setXffHeader(headers, ip) {
|
|
111
94
|
const xffValue = headers[X_FORWARDED_FOR_HEADER_NAME] || [];
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { ContentType } from '../../../http';
|
|
2
2
|
import { MinimalResponseOptions } from '../../../http';
|
|
3
|
-
export declare const EMPTY_GIF: number[];
|
|
4
3
|
export declare const X_PX_ENFORCER_TRUE_IP_HEADER_NAME = "x-px-enforcer-true-ip";
|
|
5
4
|
export declare const FIRST_PARTY_HEADER_NAME = "x-px-first-party";
|
|
6
5
|
export declare const FIRST_PARTY_HEADER_VALUE = "1";
|
|
7
|
-
export declare const FIRST_PARTY_SENSOR_SUFFIX = "/init.js";
|
|
8
|
-
export declare const FIRST_PARTY_CAPTCHA_SUFFIX = "/captcha";
|
|
9
|
-
export declare const FIRST_PARTY_XHR_SUFFIX = "/xhr";
|
|
10
6
|
export declare const DEFAULT_CLIENT_RESPONSE_OPTIONS: MinimalResponseOptions;
|
|
11
7
|
export declare const DEFAULT_XHR_RESPONSE: {
|
|
12
8
|
content: string;
|