perimeterx-js-core 0.25.0 → 0.26.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/cjs/action/Action.js +15 -0
- package/lib/cjs/action/ActionPriorityOrder.js +4 -0
- package/lib/cjs/action/utils.js +20 -0
- package/lib/cjs/activities/HttpActivityClient.js +61 -1
- package/lib/cjs/activities/HttpBatchedActivityClient.js +7 -0
- package/lib/cjs/activities/utils.js +128 -62
- package/lib/cjs/additional_activity_handler/AdditionalActivityHandlerUtils.js +6 -0
- package/lib/cjs/blocker/BlockerBase.js +14 -0
- package/lib/cjs/blocker/JsonBlockerBase.js +5 -0
- package/lib/cjs/blocker/utils.js +13 -0
- package/lib/cjs/config/ConfigurationBase.js +17 -0
- package/lib/cjs/context/DefaultContext.js +4 -0
- package/lib/cjs/context/SerializedContext.js +5 -0
- package/lib/cjs/enforcer/EnforcerBase.js +61 -22
- package/lib/cjs/enforcer/index.js +1 -0
- package/lib/cjs/{phase/flow → flow}/EndEnforcerFlow.js +11 -7
- package/lib/cjs/{phase/flow → flow}/EnforceFlow.js +10 -15
- package/lib/cjs/{phase/flow → flow}/FilterFlow.js +10 -9
- package/lib/cjs/flow/Flow.js +60 -0
- package/lib/cjs/flow/IFlow.js +2 -0
- package/lib/cjs/{phase/flow → flow}/PostEnforceFlow.js +6 -6
- package/lib/cjs/{phase/flow → flow}/index.js +2 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
- package/lib/cjs/phase/impl/ClearLogsPhase.js +3 -0
- package/lib/cjs/phase/impl/CompositePhase.js +9 -0
- package/lib/cjs/phase/impl/CreateBlockResponsePhase.js +16 -0
- package/lib/cjs/phase/impl/DecideActionPhase.js +11 -0
- package/lib/cjs/phase/impl/EnrichContextFromRequestPhase.js +13 -9
- package/lib/cjs/phase/impl/EnrichContextFromResponsePhase.js +4 -0
- package/lib/cjs/phase/impl/FilterPhase.js +4 -0
- package/lib/cjs/phase/impl/FirstPartyPhase.js +5 -0
- package/lib/cjs/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +5 -0
- package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
- package/lib/cjs/phase/impl/ModifyIncomingRequestPhase.js +5 -0
- package/lib/cjs/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
- package/lib/cjs/phase/impl/ParseTokenPhase.js +14 -7
- package/lib/cjs/phase/impl/PreflightPhase.js +4 -0
- package/lib/cjs/phase/impl/RiskApiPhase.js +18 -7
- package/lib/cjs/phase/impl/{SendAsyncActivitiesOnResponsePhase.js → SendAsyncActivitiesPhase.js} +15 -8
- package/lib/cjs/phase/impl/SendLogsPhase.js +3 -0
- package/lib/cjs/phase/impl/SendTelemetryActivityPhase.js +3 -0
- package/lib/cjs/phase/impl/UpdateRemoteConfigPhase.js +3 -0
- package/lib/cjs/phase/impl/index.js +1 -2
- package/lib/cjs/phase/index.js +0 -1
- package/lib/cjs/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
- package/lib/cjs/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
- package/lib/cjs/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +3 -1
- package/lib/cjs/risk_api/client/GetRiskApiClientV2.js +80 -0
- package/lib/cjs/risk_api/client/PostRiskApiClientV2.js +3 -3
- package/lib/cjs/risk_api/client/PostRiskApiClientV3.js +3 -3
- package/lib/cjs/risk_api/client/abstract/IRiskApiClient.js +2 -0
- package/lib/cjs/risk_api/client/abstract/PostRiskApiClientBase.js +43 -0
- package/lib/cjs/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +22 -69
- package/lib/cjs/risk_api/client/abstract/index.js +19 -0
- package/lib/cjs/risk_api/client/index.js +2 -2
- package/lib/cjs/risk_api/index.js +1 -0
- package/lib/cjs/risk_api/model/GetRiskRequestHeaders.js +185 -0
- package/lib/cjs/risk_api/model/GetRiskResponseHeaders.js +16 -0
- package/lib/cjs/risk_api/model/index.js +2 -0
- package/lib/cjs/{phase/impl/SendAsyncActivitiesOnRequestPhase.js → risk_api/risk_response/PostRiskResponseBase.js} +26 -30
- package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +11 -8
- package/lib/cjs/risk_api/risk_response/index.js +1 -0
- package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
- package/lib/cjs/risk_api/risk_response/v2/GetRiskResponseV2.js +80 -0
- package/lib/cjs/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +10 -10
- package/lib/cjs/risk_api/risk_response/v2/index.js +2 -1
- package/lib/cjs/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +10 -10
- package/lib/cjs/risk_api/risk_response/v3/index.js +1 -1
- package/lib/cjs/risk_api/utils.js +36 -0
- package/lib/cjs/telemetry/DefaultTelemetry.js +12 -9
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/utils.js +1 -19
- package/lib/esm/action/Action.js +15 -0
- package/lib/esm/action/ActionPriorityOrder.js +4 -0
- package/lib/esm/action/utils.js +20 -0
- package/lib/esm/activities/HttpActivityClient.js +61 -1
- package/lib/esm/activities/HttpBatchedActivityClient.js +7 -0
- package/lib/esm/activities/utils.js +128 -63
- package/lib/esm/additional_activity_handler/AdditionalActivityHandlerUtils.js +6 -0
- package/lib/esm/blocker/BlockerBase.js +14 -0
- package/lib/esm/blocker/JsonBlockerBase.js +5 -0
- package/lib/esm/blocker/utils.js +13 -0
- package/lib/esm/config/ConfigurationBase.js +13 -0
- package/lib/esm/context/DefaultContext.js +4 -0
- package/lib/esm/context/SerializedContext.js +5 -0
- package/lib/esm/enforcer/EnforcerBase.js +43 -6
- package/lib/esm/enforcer/index.js +1 -0
- package/lib/esm/flow/EndEnforcerFlow.js +18 -0
- package/lib/esm/flow/EnforceFlow.js +14 -0
- package/lib/esm/{phase/flow → flow}/FilterFlow.js +5 -4
- package/lib/esm/flow/Flow.js +56 -0
- package/lib/esm/flow/IFlow.js +1 -0
- package/lib/esm/flow/PostEnforceFlow.js +10 -0
- package/lib/esm/{phase/flow → flow}/index.js +2 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/phase/impl/AdditionalActivityHandlerPhase.js +3 -0
- package/lib/esm/phase/impl/ClearLogsPhase.js +3 -0
- package/lib/esm/phase/impl/CompositePhase.js +9 -0
- package/lib/esm/phase/impl/CreateBlockResponsePhase.js +16 -1
- package/lib/esm/phase/impl/DecideActionPhase.js +11 -0
- package/lib/esm/phase/impl/EnrichContextFromRequestPhase.js +9 -0
- package/lib/esm/phase/impl/EnrichContextFromResponsePhase.js +4 -0
- package/lib/esm/phase/impl/FilterPhase.js +4 -0
- package/lib/esm/phase/impl/FirstPartyPhase.js +5 -0
- package/lib/esm/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.js +5 -0
- package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +5 -0
- package/lib/esm/phase/impl/ModifyIncomingRequestPhase.js +5 -0
- package/lib/esm/phase/impl/ModifyOutgoingResponsePhase.js +5 -0
- package/lib/esm/phase/impl/ParseTokenPhase.js +15 -8
- package/lib/esm/phase/impl/PreflightPhase.js +4 -0
- package/lib/esm/phase/impl/RiskApiPhase.js +19 -8
- package/lib/esm/phase/impl/SendAsyncActivitiesPhase.js +16 -0
- package/lib/esm/phase/impl/SendLogsPhase.js +3 -0
- package/lib/esm/phase/impl/SendTelemetryActivityPhase.js +3 -0
- package/lib/esm/phase/impl/UpdateRemoteConfigPhase.js +3 -0
- package/lib/esm/phase/impl/index.js +1 -2
- package/lib/esm/phase/index.js +0 -1
- package/lib/esm/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.js +1 -1
- package/lib/esm/products/credential_intelligence/endpoint/login_successful/LoginSuccessfulParserFactory.js +5 -2
- package/lib/esm/products/credential_intelligence/endpoint/matcher/CredentialIntelligenceEndpointMatcherFactory.js +2 -1
- package/lib/esm/risk_api/client/GetRiskApiClientV2.js +57 -0
- package/lib/esm/risk_api/client/PostRiskApiClientV2.js +3 -3
- package/lib/esm/risk_api/client/PostRiskApiClientV3.js +3 -3
- package/lib/esm/risk_api/client/abstract/IRiskApiClient.js +1 -0
- package/lib/esm/risk_api/client/abstract/PostRiskApiClientBase.js +18 -0
- package/lib/esm/risk_api/client/{PostRiskApiClientBase.js → abstract/RiskApiClientBase.js} +10 -49
- package/lib/esm/risk_api/client/abstract/index.js +3 -0
- package/lib/esm/risk_api/client/index.js +2 -2
- package/lib/esm/risk_api/index.js +1 -0
- package/lib/esm/risk_api/model/GetRiskRequestHeaders.js +182 -0
- package/lib/esm/risk_api/model/GetRiskResponseHeaders.js +13 -0
- package/lib/esm/risk_api/model/index.js +2 -0
- package/lib/esm/risk_api/risk_response/PostRiskResponseBase.js +6 -0
- package/lib/esm/risk_api/risk_response/RiskResponseBase.js +5 -1
- package/lib/esm/risk_api/risk_response/index.js +1 -0
- package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +5 -1
- package/lib/esm/risk_api/risk_response/v2/GetRiskResponseV2.js +52 -0
- package/lib/esm/risk_api/risk_response/v2/{DefaultRiskResponseV2.js → PostRiskResponseV2.js} +2 -2
- package/lib/esm/risk_api/risk_response/v2/index.js +2 -1
- package/lib/esm/risk_api/risk_response/v3/{DefaultRiskResponseV3.js → PostRiskResponseV3.js} +2 -2
- package/lib/esm/risk_api/risk_response/v3/index.js +1 -1
- package/lib/esm/risk_api/utils.js +23 -0
- package/lib/esm/telemetry/DefaultTelemetry.js +13 -10
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/utils.js +0 -16
- package/lib/types/action/Action.d.ts +15 -0
- package/lib/types/action/ActionData.d.ts +3 -0
- package/lib/types/action/ActionPriorityOrder.d.ts +4 -0
- package/lib/types/action/Decision.d.ts +9 -0
- package/lib/types/action/ProductAction.d.ts +3 -0
- package/lib/types/action/utils.d.ts +20 -0
- package/lib/types/activities/HttpActivityClient.d.ts +57 -1
- package/lib/types/activities/HttpBatchedActivityClient.d.ts +7 -0
- package/lib/types/activities/IActivityClient.d.ts +4 -1
- package/lib/types/activities/model/AsyncActivity.d.ts +3 -0
- package/lib/types/activities/model/AsyncActivityDetails.d.ts +12 -0
- package/lib/types/activities/model/CommonActivityDetails.d.ts +3 -0
- package/lib/types/activities/utils.d.ts +14 -0
- package/lib/types/additional_activity_handler/AdditionalActivityHandlerUtils.d.ts +6 -0
- package/lib/types/blocker/BlockerBase.d.ts +21 -0
- package/lib/types/blocker/IBlocker.d.ts +8 -0
- package/lib/types/blocker/IConditionalBlocker.d.ts +4 -0
- package/lib/types/blocker/JsonBlockerBase.d.ts +12 -0
- package/lib/types/blocker/model/BlockData.d.ts +3 -0
- package/lib/types/blocker/utils.d.ts +13 -0
- package/lib/types/config/ConfigurationBase.d.ts +22 -0
- package/lib/types/config/IConfiguration.d.ts +4 -0
- package/lib/types/config/params/CoreConfigurationParams.d.ts +21 -0
- package/lib/types/config/params/RemoteConfigurationParams.d.ts +3 -0
- package/lib/types/config/params/StaticConfigurationParams.d.ts +3 -0
- package/lib/types/context/ContextJson.d.ts +4 -0
- package/lib/types/context/DefaultContext.d.ts +4 -0
- package/lib/types/context/SerializedContext.d.ts +5 -0
- package/lib/types/custom_parameters/CustomParameters.d.ts +3 -0
- package/lib/types/enforcer/EnforcerBase.d.ts +48 -12
- package/lib/types/enforcer/IEnforcer.d.ts +1 -2
- package/lib/types/enforcer/IPostEnforcer.d.ts +3 -0
- package/lib/types/enforcer/index.d.ts +1 -0
- package/lib/types/first_party/IFirstParty.d.ts +1 -1
- package/lib/types/flow/EndEnforcerFlow.d.ts +8 -0
- package/lib/types/flow/EnforceFlow.d.ts +8 -0
- package/lib/types/{phase/flow → flow}/FilterFlow.d.ts +7 -7
- package/lib/types/flow/Flow.d.ts +13 -0
- package/lib/types/flow/IFlow.d.ts +57 -0
- package/lib/types/flow/PostEnforceFlow.d.ts +6 -0
- package/lib/types/{phase/flow → flow}/index.d.ts +2 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/phase/IPhase.d.ts +9 -0
- package/lib/types/phase/PhaseResult.d.ts +11 -0
- package/lib/types/phase/impl/AdditionalActivityHandlerPhase.d.ts +3 -0
- package/lib/types/phase/impl/ClearLogsPhase.d.ts +3 -0
- package/lib/types/phase/impl/CompositePhase.d.ts +9 -0
- package/lib/types/phase/impl/CreateBlockResponsePhase.d.ts +11 -1
- package/lib/types/phase/impl/DecideActionPhase.d.ts +11 -0
- package/lib/types/phase/impl/EnrichContextFromRequestPhase.d.ts +9 -0
- package/lib/types/phase/impl/EnrichContextFromResponsePhase.d.ts +4 -0
- package/lib/types/phase/impl/FilterPhase.d.ts +4 -0
- package/lib/types/phase/impl/FirstPartyPhase.d.ts +5 -0
- package/lib/types/phase/impl/IdentifyRemoteConfigNotifyRequestPhase.d.ts +5 -0
- package/lib/types/phase/impl/IdentifyTelemetryRequestPhase.d.ts +5 -0
- package/lib/types/phase/impl/ModifyIncomingRequestPhase.d.ts +5 -0
- package/lib/types/phase/impl/ModifyOutgoingResponsePhase.d.ts +5 -0
- package/lib/types/phase/impl/ParseTokenPhase.d.ts +3 -0
- package/lib/types/phase/impl/PreflightPhase.d.ts +4 -0
- package/lib/types/phase/impl/RiskApiPhase.d.ts +5 -0
- package/lib/types/phase/impl/{SendAsyncActivitiesOnResponsePhase.d.ts → SendAsyncActivitiesPhase.d.ts} +5 -2
- package/lib/types/phase/impl/SendLogsPhase.d.ts +3 -0
- package/lib/types/phase/impl/SendTelemetryActivityPhase.d.ts +3 -0
- package/lib/types/phase/impl/UpdateRemoteConfigPhase.d.ts +3 -0
- package/lib/types/phase/impl/index.d.ts +1 -2
- package/lib/types/phase/index.d.ts +0 -1
- package/lib/types/products/credential_intelligence/endpoint/CredentialEndpointConfiguration.d.ts +1 -1
- package/lib/types/products/credential_intelligence/endpoint/login_successful/BodyLoginSuccessfulParser.d.ts +1 -1
- package/lib/types/products/interfaces/IProduct.d.ts +28 -0
- package/lib/types/products/interfaces/ProductDataType.d.ts +1 -1
- package/lib/types/risk_api/client/GetRiskApiClientV2.d.ts +15 -0
- package/lib/types/risk_api/client/PostRiskApiClientV2.d.ts +1 -1
- package/lib/types/risk_api/client/PostRiskApiClientV3.d.ts +2 -2
- package/lib/types/risk_api/client/{IRiskApiClient.d.ts → abstract/IRiskApiClient.d.ts} +1 -1
- package/lib/types/risk_api/client/abstract/PostRiskApiClientBase.d.ts +8 -0
- package/lib/types/risk_api/client/abstract/RiskApiClientBase.d.ts +26 -0
- package/lib/types/risk_api/client/abstract/index.d.ts +3 -0
- package/lib/types/risk_api/client/index.d.ts +2 -2
- package/lib/types/risk_api/index.d.ts +1 -0
- package/lib/types/risk_api/model/GetRiskRequestHeaders.d.ts +17 -0
- package/lib/types/risk_api/model/GetRiskResponseHeaders.d.ts +3 -0
- package/lib/types/risk_api/model/index.d.ts +2 -0
- package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +2 -0
- package/lib/types/risk_api/risk_response/PostRiskResponseBase.d.ts +7 -0
- package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +3 -1
- package/lib/types/risk_api/risk_response/index.d.ts +1 -0
- package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +1 -0
- package/lib/types/risk_api/risk_response/v2/GetRiskResponseV2.d.ts +11 -0
- package/lib/types/risk_api/risk_response/{v3/DefaultRiskResponseV3.d.ts → v2/PostRiskResponseV2.d.ts} +2 -2
- package/lib/types/risk_api/risk_response/v2/index.d.ts +2 -1
- package/lib/types/risk_api/risk_response/{v2/DefaultRiskResponseV2.d.ts → v3/PostRiskResponseV3.d.ts} +2 -2
- package/lib/types/risk_api/risk_response/v3/index.d.ts +1 -1
- package/lib/types/risk_api/utils.d.ts +69 -0
- package/lib/types/telemetry/model/TelemetryActivity.d.ts +1 -1
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/utils.d.ts +0 -5
- package/package.json +1 -1
- package/lib/esm/phase/flow/EndEnforcerFlow.js +0 -14
- package/lib/esm/phase/flow/EnforceFlow.js +0 -18
- package/lib/esm/phase/flow/PostEnforceFlow.js +0 -10
- package/lib/esm/phase/impl/SendAsyncActivitiesOnRequestPhase.js +0 -16
- package/lib/esm/phase/impl/SendAsyncActivitiesOnResponsePhase.js +0 -10
- package/lib/types/phase/flow/EndEnforcerFlow.d.ts +0 -8
- package/lib/types/phase/flow/EnforceFlow.d.ts +0 -8
- package/lib/types/phase/flow/PostEnforceFlow.d.ts +0 -6
- package/lib/types/phase/impl/SendAsyncActivitiesOnRequestPhase.d.ts +0 -10
- package/lib/types/risk_api/client/PostRiskApiClientBase.d.ts +0 -40
- /package/lib/cjs/{risk_api/client/IRiskApiClient.js → enforcer/IPostEnforcer.js} +0 -0
- /package/lib/esm/{risk_api/client/IRiskApiClient.js → enforcer/IPostEnforcer.js} +0 -0
package/lib/esm/action/utils.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { Action } from './Action.js';
|
|
2
2
|
import { PRODUCT_PRIORITY_ORDER } from '../products/index.js';
|
|
3
3
|
import { ACTION_PRIORITY_ORDER } from './ActionPriorityOrder.js';
|
|
4
|
+
/**
|
|
5
|
+
* Determines the final decision from the context.
|
|
6
|
+
* @param context - The request context.
|
|
7
|
+
* @returns Decision - The final action that should be taken and the associated products and reasons responsible for the decision.
|
|
8
|
+
*/
|
|
4
9
|
export const getDecisionFromContext = (context) => {
|
|
5
10
|
return getDecisionFromActions(getProductActions(context));
|
|
6
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Determines all product recommended actions from the context.
|
|
14
|
+
* @param context - The request context.
|
|
15
|
+
* @returns ProductAction[] - An array of objects, representing the recommended action and reason of all relevant products.
|
|
16
|
+
*/
|
|
7
17
|
export const getProductActions = (context) => {
|
|
8
18
|
return Object.entries(context.productData)
|
|
9
19
|
.filter(([_, data]) => data?.action != null && data?.reason != null)
|
|
@@ -13,6 +23,11 @@ export const getProductActions = (context) => {
|
|
|
13
23
|
productName: productName,
|
|
14
24
|
}));
|
|
15
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Reduces a list of ProductActions to a single Decision, taking into consideration the ACTION_PRIORITY_ORDER.
|
|
28
|
+
* @param productActions - All possible actions from all products.
|
|
29
|
+
* @returns Decision - The final action that should be taken and the associated products and reasons responsible for the decision.
|
|
30
|
+
*/
|
|
16
31
|
export const getDecisionFromActions = (productActions) => {
|
|
17
32
|
return createDecision(reduce(productActions));
|
|
18
33
|
};
|
|
@@ -33,6 +48,11 @@ const createDecision = (tally) => {
|
|
|
33
48
|
}
|
|
34
49
|
return { action: Action.PASS_REQUEST, reasons: {} };
|
|
35
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* Provided a mapping of product names to reasons, returns the reason associated with the highest priority product in the mapping.
|
|
53
|
+
* @param reasons - An object mapping any product names to their associated reasons.
|
|
54
|
+
* @returns string - The reason for the highest priority product, or 'unknown_reason' if none is found.
|
|
55
|
+
*/
|
|
36
56
|
export const getReasonForHighestPriorityProduct = (reasons) => {
|
|
37
57
|
for (let productName of PRODUCT_PRIORITY_ORDER) {
|
|
38
58
|
const reason = reasons[productName];
|
|
@@ -4,16 +4,33 @@ import { getAuthorizationHeader } from '../utils/index.js';
|
|
|
4
4
|
import { ActivityType } from './ActivityType.js';
|
|
5
5
|
import { createAsyncActivity } from './utils.js';
|
|
6
6
|
import { ACTIVITIES_ENDPOINT } from './constants.js';
|
|
7
|
+
/**
|
|
8
|
+
* The HttpActivityClient is responsible for sending async activities to the backend via HTTP.
|
|
9
|
+
*/
|
|
7
10
|
export class HttpActivityClient {
|
|
8
11
|
config;
|
|
9
12
|
httpClient;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of HttpActivityClient.
|
|
15
|
+
* @param config
|
|
16
|
+
* @param httpClient
|
|
17
|
+
*/
|
|
10
18
|
constructor(config, httpClient) {
|
|
11
19
|
this.config = config;
|
|
12
20
|
this.httpClient = httpClient;
|
|
13
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates and sends all necessary async activities to the backend.
|
|
24
|
+
* @param context - The context containing the request (and possibly response).
|
|
25
|
+
* @returns {Promise<boolean>} - A boolean indicating if the activities were sent successfully.
|
|
26
|
+
*/
|
|
14
27
|
async sendActivities(context) {
|
|
15
28
|
try {
|
|
16
29
|
const activities = this.createActivities(context);
|
|
30
|
+
if (!activities || activities.length === 0) {
|
|
31
|
+
context.logger.debug('no activities to send');
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
17
34
|
return await this.postActivities(activities, context.logger);
|
|
18
35
|
}
|
|
19
36
|
catch (e) {
|
|
@@ -21,6 +38,12 @@ export class HttpActivityClient {
|
|
|
21
38
|
return false;
|
|
22
39
|
}
|
|
23
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates all async activities (block, page_requested, additional_s2s) that should be sent based on the context.
|
|
43
|
+
* @param context - The context containing the request (and possibly response).
|
|
44
|
+
* @returns {AsyncActivity[]} - An array of async activities to be sent.
|
|
45
|
+
* @protected
|
|
46
|
+
*/
|
|
24
47
|
createActivities(context) {
|
|
25
48
|
const activities = [];
|
|
26
49
|
if (this.shouldCreateBlockActivity(context)) {
|
|
@@ -34,28 +57,58 @@ export class HttpActivityClient {
|
|
|
34
57
|
}
|
|
35
58
|
return activities.map(this.finalizeActivity);
|
|
36
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether to create a block activity based on the context.
|
|
62
|
+
* @param context
|
|
63
|
+
* @protected
|
|
64
|
+
*/
|
|
37
65
|
shouldCreateBlockActivity(context) {
|
|
38
66
|
return context.action === Action.BLOCK || context.action === Action.SIMULATED_BLOCK;
|
|
39
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Whether to create a page_requested activity based on the context.
|
|
70
|
+
* @param context
|
|
71
|
+
* @protected
|
|
72
|
+
*/
|
|
40
73
|
shouldCreatePageRequestedActivity(context) {
|
|
41
74
|
return context.action === Action.PASS_REQUEST;
|
|
42
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Whether to create an additional_s2s activity based on the context.
|
|
78
|
+
* @param context
|
|
79
|
+
* @protected
|
|
80
|
+
*/
|
|
43
81
|
shouldCreateAdditionalS2SActivity(context) {
|
|
44
82
|
return (this.shouldCreatePageRequestedActivity(context) &&
|
|
45
83
|
!!context.productData.ci &&
|
|
46
84
|
this.config.ciAutomaticAdditionalS2SEnabled);
|
|
47
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a block activity based on the context.
|
|
88
|
+
* @param context
|
|
89
|
+
* @protected
|
|
90
|
+
*/
|
|
48
91
|
createBlockActivity(context) {
|
|
49
92
|
return createAsyncActivity(ActivityType.BLOCK, this.config, context);
|
|
50
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates a page_requested activity based on the context.
|
|
96
|
+
* @param context
|
|
97
|
+
* @protected
|
|
98
|
+
*/
|
|
51
99
|
createPageRequestedActivity(context) {
|
|
52
100
|
return createAsyncActivity(ActivityType.PAGE_REQUESTED, this.config, context);
|
|
53
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Creates an additional_s2s activity based on the context.
|
|
104
|
+
* @param context
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
54
107
|
createAdditionalS2SActivity(context) {
|
|
55
108
|
return createAsyncActivity(ActivityType.ADDITIONAL_S2S, this.config, context);
|
|
56
109
|
}
|
|
57
110
|
/**
|
|
58
|
-
* Allows for expansions or alterations to
|
|
111
|
+
* Allows for expansions or alterations to an async activity if needed. This applies to all created async activities.
|
|
59
112
|
* @param activity
|
|
60
113
|
* @returns AsyncActivity
|
|
61
114
|
* @protected
|
|
@@ -63,6 +116,13 @@ export class HttpActivityClient {
|
|
|
63
116
|
finalizeActivity(activity) {
|
|
64
117
|
return activity;
|
|
65
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Sends the async activities to the backend.
|
|
121
|
+
* @param activities - The activities to be sent.
|
|
122
|
+
* @param logger - The logger instance for logging.
|
|
123
|
+
* @returns {Promise<boolean>} - A boolean indicating if the activities were sent successfully.
|
|
124
|
+
* @protected
|
|
125
|
+
*/
|
|
66
126
|
async postActivities(activities, logger) {
|
|
67
127
|
const url = `${this.config.backendCollectorUrl}${ACTIVITIES_ENDPOINT}`;
|
|
68
128
|
const method = HttpMethod.POST;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { HttpActivityClient } from './HttpActivityClient.js';
|
|
2
|
+
/**
|
|
3
|
+
* The HttpBatchedActivityClient is responsible for sending async activities to the backend via HTTP in batches.
|
|
4
|
+
* It extends the HttpActivityClient class and adds functionality for batching activities.
|
|
5
|
+
*
|
|
6
|
+
* This class uses setTimeout and clearTimeout for managing the timeout for sending activities. It also exposes the stop()
|
|
7
|
+
* method to stop the timer and prevent further activity sending, which should be called on shutdown.
|
|
8
|
+
*/
|
|
2
9
|
export class HttpBatchedActivityClient extends HttpActivityClient {
|
|
3
10
|
batchSize;
|
|
4
11
|
timeoutMs;
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { EnforcerError, ModuleMode, removeSensitiveHeaders
|
|
1
|
+
import { EnforcerError, ModuleMode, removeSensitiveHeaders } from '../utils/index.js';
|
|
2
2
|
import { ProductName } from '../products/index.js';
|
|
3
3
|
import { Action, getReasonForHighestPriorityProduct } from '../action/index.js';
|
|
4
4
|
import { ActivityType } from './ActivityType.js';
|
|
5
5
|
import { TokenParseResult } from '../risk_token/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates an async activity object based on the provided parameters.
|
|
8
|
+
* @param activityType - The activity type to create.
|
|
9
|
+
* @param config - The enforcer configuration.
|
|
10
|
+
* @param context - The request context.
|
|
11
|
+
* @returns {AsyncActivity} - The complete async activity payload.
|
|
12
|
+
*/
|
|
6
13
|
export const createAsyncActivity = (activityType, config, context) => {
|
|
7
14
|
return {
|
|
8
15
|
type: activityType,
|
|
@@ -18,6 +25,13 @@ export const createAsyncActivity = (activityType, config, context) => {
|
|
|
18
25
|
details: createActivityDetails(activityType, config, context),
|
|
19
26
|
};
|
|
20
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Creates activity details based on the provided parameters.
|
|
30
|
+
* @param activityType - The activity type to create.
|
|
31
|
+
* @param config - The enforcer configuration.
|
|
32
|
+
* @param context - The request context.
|
|
33
|
+
* @returns {AsyncActivityDetails} - The activity details.
|
|
34
|
+
*/
|
|
21
35
|
export const createActivityDetails = (activityType, config, context) => {
|
|
22
36
|
const commonActivityDetails = createCommonActivityDetails(config, context);
|
|
23
37
|
const commonAsyncActivityDetails = createAsyncActivityCommonDetails(context);
|
|
@@ -60,13 +74,21 @@ export const createCommonActivityDetails = (config, context) => {
|
|
|
60
74
|
return details;
|
|
61
75
|
};
|
|
62
76
|
export const addRootContextDataToDetails = (details, context) => {
|
|
63
|
-
|
|
64
|
-
requestId
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
if (context.requestId) {
|
|
78
|
+
details.request_id = context.requestId;
|
|
79
|
+
}
|
|
80
|
+
if (context.tokenOrigin) {
|
|
81
|
+
details.cookie_origin = context.tokenOrigin;
|
|
82
|
+
}
|
|
83
|
+
if (context.vidSource) {
|
|
84
|
+
details.enforcer_vid_source = context.vidSource;
|
|
85
|
+
}
|
|
86
|
+
if (context.graphqlData) {
|
|
87
|
+
details.graphql_operations = context.graphqlData;
|
|
88
|
+
}
|
|
89
|
+
if (context.enforcerStartTime) {
|
|
90
|
+
details.enforcer_start_time = context.enforcerStartTime;
|
|
91
|
+
}
|
|
70
92
|
if (context.usedCookieSecret) {
|
|
71
93
|
details.used_cookie_secret = redactCookieSecret(context.usedCookieSecret);
|
|
72
94
|
}
|
|
@@ -75,10 +97,12 @@ export function redactCookieSecret(secret) {
|
|
|
75
97
|
return '***'.concat(secret.substring(secret.length - 3, secret.length));
|
|
76
98
|
}
|
|
77
99
|
export const addConfigDataToDetails = (details, config) => {
|
|
78
|
-
|
|
79
|
-
remoteConfigId
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
if (config.remoteConfigId) {
|
|
101
|
+
details.remote_config_id = config.remoteConfigId;
|
|
102
|
+
}
|
|
103
|
+
if (config.remoteConfigVersion) {
|
|
104
|
+
details.remote_config_version = config.remoteConfigVersion;
|
|
105
|
+
}
|
|
82
106
|
};
|
|
83
107
|
export const addCustomParametersToDetails = (details, customParameters) => {
|
|
84
108
|
if (customParameters) {
|
|
@@ -86,44 +110,78 @@ export const addCustomParametersToDetails = (details, customParameters) => {
|
|
|
86
110
|
}
|
|
87
111
|
};
|
|
88
112
|
export const addProductDataToDetails = (details, productData) => {
|
|
89
|
-
|
|
90
|
-
appUserId
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
if (productData.ad) {
|
|
114
|
+
if (productData.ad.appUserId) {
|
|
115
|
+
details.app_user_id = productData.ad.appUserId;
|
|
116
|
+
}
|
|
117
|
+
if (productData.ad.additionalFields) {
|
|
118
|
+
details.jwt_additional_fields = productData.ad.additionalFields;
|
|
119
|
+
}
|
|
120
|
+
if (productData.ad.crossTabSession) {
|
|
121
|
+
details.cross_tab_session = productData.ad.crossTabSession;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (productData.ci) {
|
|
125
|
+
if (productData.ci.hashedUsername) {
|
|
126
|
+
details.user = productData.ci.hashedUsername;
|
|
127
|
+
}
|
|
128
|
+
if (productData.ci.hashedPassword) {
|
|
129
|
+
details.pass = productData.ci.hashedPassword;
|
|
130
|
+
}
|
|
131
|
+
if (productData.ci.ciVersion) {
|
|
132
|
+
details.ci_version = productData.ci.ciVersion;
|
|
133
|
+
}
|
|
134
|
+
if (productData.ci.ssoStep) {
|
|
135
|
+
details.sso_step = productData.ci.ssoStep;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (productData.hsc) {
|
|
139
|
+
if (typeof productData.hsc.isTokenHscApproved === 'boolean') {
|
|
140
|
+
details.cpa = productData.hsc.isTokenHscApproved;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
103
143
|
};
|
|
104
144
|
export const addTlsDataToDetails = (details, tlsData) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
tlsCiphersSha
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
145
|
+
if (tlsData.tlsCipher) {
|
|
146
|
+
details.tls_cipher = tlsData.tlsCipher;
|
|
147
|
+
}
|
|
148
|
+
if (tlsData.tlsCiphersSha) {
|
|
149
|
+
details.tls_ciphers_sha = tlsData.tlsCiphersSha;
|
|
150
|
+
}
|
|
151
|
+
if (tlsData.tlsExtensionSha) {
|
|
152
|
+
details.tls_extension_sha = tlsData.tlsExtensionSha;
|
|
153
|
+
}
|
|
154
|
+
if (tlsData.tlsPreferredCiphers) {
|
|
155
|
+
details.tls_preferred_ciphers = tlsData.tlsPreferredCiphers;
|
|
156
|
+
}
|
|
157
|
+
if (tlsData.tlsJa3Fingerprint) {
|
|
158
|
+
details.tls_ja3_fingerprint = tlsData.tlsJa3Fingerprint;
|
|
159
|
+
}
|
|
160
|
+
if (tlsData.tlsProtocol) {
|
|
161
|
+
details.tls_protocol = tlsData.tlsProtocol;
|
|
162
|
+
}
|
|
163
|
+
if (tlsData.tlsServer) {
|
|
164
|
+
details.tls_server = tlsData.tlsServer;
|
|
165
|
+
}
|
|
114
166
|
};
|
|
115
167
|
export const addServerDataToDetails = (details, serverData) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
168
|
+
if (serverData.datacenter) {
|
|
169
|
+
details.server_info_datacenter = serverData.datacenter;
|
|
170
|
+
}
|
|
171
|
+
if (serverData.region) {
|
|
172
|
+
details.server_info_region = serverData.region;
|
|
173
|
+
}
|
|
120
174
|
};
|
|
121
175
|
export const addRequestDataToDetails = (details, requestData) => {
|
|
122
|
-
|
|
123
|
-
httpVersion
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
176
|
+
if (requestData.httpVersion) {
|
|
177
|
+
details.http_version = requestData.httpVersion;
|
|
178
|
+
}
|
|
179
|
+
if (requestData.method) {
|
|
180
|
+
details.http_method = requestData.method;
|
|
181
|
+
}
|
|
182
|
+
if (requestData.requestCookieNames) {
|
|
183
|
+
details.request_cookie_names = requestData.requestCookieNames.concat();
|
|
184
|
+
}
|
|
127
185
|
if (requestData.isUrlDifferentFromRawUrl) {
|
|
128
186
|
details.raw_url = requestData.rawUrl;
|
|
129
187
|
}
|
|
@@ -139,10 +197,12 @@ export const addTokenDataToDetails = (details, { token, mobileData }) => {
|
|
|
139
197
|
}
|
|
140
198
|
}
|
|
141
199
|
if (mobileData) {
|
|
142
|
-
|
|
143
|
-
originalToken
|
|
144
|
-
|
|
145
|
-
|
|
200
|
+
if (mobileData.originalToken) {
|
|
201
|
+
details.original_token = mobileData.originalToken.tokenString;
|
|
202
|
+
}
|
|
203
|
+
if (mobileData.decodedOriginalToken) {
|
|
204
|
+
details.px_decoded_original_token = mobileData.decodedOriginalToken;
|
|
205
|
+
}
|
|
146
206
|
if (mobileData.originalTokenParseResult === TokenParseResult.DECRYPTION_FAILED) {
|
|
147
207
|
details.original_token_error = 'cookie_decryption_failed';
|
|
148
208
|
}
|
|
@@ -152,11 +212,15 @@ export const addTokenDataToDetails = (details, { token, mobileData }) => {
|
|
|
152
212
|
}
|
|
153
213
|
};
|
|
154
214
|
export const addRiskApiDataToAsyncActivityCommonDetails = (details, context) => {
|
|
155
|
-
|
|
156
|
-
riskRtt
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
215
|
+
if (context.riskApiData.riskRtt) {
|
|
216
|
+
details.risk_rtt = context.riskApiData.riskRtt;
|
|
217
|
+
}
|
|
218
|
+
if (context.riskApiData.s2sCallReason) {
|
|
219
|
+
details.s2s_call_reason = context.riskApiData.s2sCallReason;
|
|
220
|
+
}
|
|
221
|
+
if (context.riskApiData.riskStartTime) {
|
|
222
|
+
details.risk_start_time = context.riskApiData.riskStartTime;
|
|
223
|
+
}
|
|
160
224
|
if (context.riskApiData.riskResponse?.additionalRiskInfo) {
|
|
161
225
|
details.additional_risk_info = context.riskApiData.riskResponse.additionalRiskInfo;
|
|
162
226
|
}
|
|
@@ -165,21 +229,23 @@ export const addRiskApiDataToAsyncActivityCommonDetails = (details, context) =>
|
|
|
165
229
|
}
|
|
166
230
|
};
|
|
167
231
|
export const addResponseDataToAsyncActivityCommonDetails = (details, context) => {
|
|
168
|
-
if (context.action !== Action.BLOCK) {
|
|
169
|
-
|
|
170
|
-
status: 'http_status_code',
|
|
171
|
-
});
|
|
232
|
+
if (context.action !== Action.BLOCK && context.response?.status) {
|
|
233
|
+
details.http_status_code = context.response.status;
|
|
172
234
|
}
|
|
173
235
|
};
|
|
174
236
|
export const createPageRequestedActivityDetails = (context) => {
|
|
175
237
|
const details = {
|
|
176
238
|
pass_reason: getReasonForHighestPriorityProduct(context.reasons),
|
|
177
239
|
};
|
|
178
|
-
|
|
179
|
-
errorReason
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
240
|
+
if (context.riskApiData.errorReason) {
|
|
241
|
+
details.s2s_error_reason = context.riskApiData.errorReason;
|
|
242
|
+
}
|
|
243
|
+
if (context.riskApiData.errorHttpStatus) {
|
|
244
|
+
details.s2s_error_http_status = context.riskApiData.errorHttpStatus;
|
|
245
|
+
}
|
|
246
|
+
if (context.riskApiData.errorMessage) {
|
|
247
|
+
details.error_message = context.riskApiData.errorMessage;
|
|
248
|
+
}
|
|
183
249
|
return details;
|
|
184
250
|
};
|
|
185
251
|
export const createBlockActivityDetails = (context) => {
|
|
@@ -187,7 +253,6 @@ export const createBlockActivityDetails = (context) => {
|
|
|
187
253
|
block_reason: getReasonForHighestPriorityProduct(context.reasons),
|
|
188
254
|
simulated_block: context.action === Action.SIMULATED_BLOCK,
|
|
189
255
|
block_action: context.blockAction,
|
|
190
|
-
// @ts-ignore
|
|
191
256
|
block_score: context.score,
|
|
192
257
|
};
|
|
193
258
|
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export var AdditionalActivityHandlerUtils;
|
|
2
2
|
(function (AdditionalActivityHandlerUtils) {
|
|
3
|
+
/**
|
|
4
|
+
* Invokes the additional activity handler if it is defined in the configuration.
|
|
5
|
+
* @param config - The enforcer configuration.
|
|
6
|
+
* @param context - The request context.
|
|
7
|
+
* @returns {Promise<void>} - A promise that resolves when the additional activity handler is complete.
|
|
8
|
+
*/
|
|
3
9
|
AdditionalActivityHandlerUtils.invokeAdditionalActivityHandler = async (config, context) => {
|
|
4
10
|
if (config.additionalActivityHandler && typeof config.additionalActivityHandler === 'function') {
|
|
5
11
|
try {
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { CONTENT_TYPE_HEADER_NAME, MinimalResponseImpl } from '../http/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for creating a block response.
|
|
4
|
+
*/
|
|
2
5
|
export class BlockerBase {
|
|
3
6
|
statusCode;
|
|
4
7
|
contentType;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new instance of BlockerBase.
|
|
10
|
+
* @param contentType - The Content-Type header to be included in the HTTP block response.
|
|
11
|
+
* @param statusCode - The status code of the HTTP block response.
|
|
12
|
+
* @protected
|
|
13
|
+
*/
|
|
5
14
|
constructor(contentType, statusCode = 403) {
|
|
6
15
|
this.contentType = contentType;
|
|
7
16
|
this.statusCode = statusCode;
|
|
8
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Creates the complete HTTP block response based on the given context.
|
|
20
|
+
* @param context - The request context.
|
|
21
|
+
* @returns {IMinimalResponse} - The HTTP block response.
|
|
22
|
+
*/
|
|
9
23
|
createBlockResponse(context) {
|
|
10
24
|
const status = this.statusCode;
|
|
11
25
|
const headers = this.createHeaders();
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { BlockerBase } from './BlockerBase.js';
|
|
2
2
|
import { ACCEPT_HEADER_NAME, ContentType } from '../http/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base class for creating a block response with JSON payload.
|
|
5
|
+
*
|
|
6
|
+
* The generic argument JsonPayloadT is the specific structure of the JSON payload to be returned.
|
|
7
|
+
*/
|
|
3
8
|
export class JsonBlockerBase extends BlockerBase {
|
|
4
9
|
constructor() {
|
|
5
10
|
super(ContentType.APPLICATION_JSON);
|
package/lib/esm/blocker/utils.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { FirstPartySuffix, getMostCustomizedFirstPartyPath } from '../products/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Renders the HTML template with the provided block data.
|
|
4
|
+
* @param htmlTemplate - The HTML template to be rendered. Placeholders are indicated with {{key_name}} where the key_name should be keyof BlockData.
|
|
5
|
+
* @param blockData - The block data to be used for rendering. The keys in the object should match the placeholders in the template.
|
|
6
|
+
* @returns {string} - The final HTML string. If no block data is provided, the original template is returned unchanged.
|
|
7
|
+
*/
|
|
2
8
|
export const renderHtml = (htmlTemplate, blockData) => {
|
|
3
9
|
if (!blockData) {
|
|
4
10
|
return htmlTemplate;
|
|
@@ -10,6 +16,13 @@ export const renderHtml = (htmlTemplate, blockData) => {
|
|
|
10
16
|
});
|
|
11
17
|
return htmlTemplate;
|
|
12
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Creates the block data object to be used when creating a block response.
|
|
21
|
+
* @param config - The enforcer configuration.
|
|
22
|
+
* @param context - The request context.
|
|
23
|
+
* @param base64Utils - The base64 utility functions.
|
|
24
|
+
* @returns {BlockData} - The block data object.
|
|
25
|
+
*/
|
|
13
26
|
export const createBlockData = (config, context, base64Utils) => {
|
|
14
27
|
const captchaScriptSuffix = '/captcha.js';
|
|
15
28
|
const b64EncodedUrl = config.enableBlockedUrlOnCaptchaBlockPage
|
|
@@ -3,6 +3,9 @@ import { DefaultLogger, LoggerSeverity } from '../logger/index.js';
|
|
|
3
3
|
import { CORE_MODULE_VERSION, EnforcerConfigurationError, getCollectorDomain, getScoreApiDomain, isNullOrUndefined, isValidEnumValue, ModuleMode, } from '../utils/index.js';
|
|
4
4
|
import { RemoteConfigUtils } from './remote_config/index.js';
|
|
5
5
|
import { TokenVersion } from '../risk_token/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Base class for the enforcer configuration.
|
|
8
|
+
*/
|
|
6
9
|
export class ConfigurationBase {
|
|
7
10
|
configParams;
|
|
8
11
|
staticConfigParams;
|
|
@@ -11,6 +14,13 @@ export class ConfigurationBase {
|
|
|
11
14
|
removedParams;
|
|
12
15
|
// Logger is initialized at `createActiveConfiguration`
|
|
13
16
|
internalLogger;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of the configuration base class.
|
|
19
|
+
* @param params - The configuration parameters as provided by the customer.
|
|
20
|
+
* @param defaultParams - Default parameters for added configurations or any default core configurations that should be overridden.
|
|
21
|
+
* @param removedParams - A map of all removed (unsupported) configuration parameters set to undefined. This parameter can be generated automatically by your IDE.
|
|
22
|
+
* @protected
|
|
23
|
+
*/
|
|
14
24
|
constructor(params, defaultParams, removedParams) {
|
|
15
25
|
this.defaultConfigParams = { ...defaultConfigurationParams(), ...defaultParams };
|
|
16
26
|
this.configParams = this.createActiveConfiguration(params, this.defaultConfigParams);
|
|
@@ -374,4 +384,7 @@ export class ConfigurationBase {
|
|
|
374
384
|
get enableBlockedUrlOnCaptchaBlockPage() {
|
|
375
385
|
return true;
|
|
376
386
|
}
|
|
387
|
+
get isPostEnforceEnabled() {
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
377
390
|
}
|
|
@@ -6,6 +6,10 @@ import { COOKIE_HEADER_NAME, toReadonlyHeaders, USER_AGENT_HEADER_NAME, } from '
|
|
|
6
6
|
import { isValidUuid, PXHD_COOKIE_NAME, PXVID_COOKIE_NAME, StringSplitCookieParser, X_PX_AUTHORIZATION_HEADER_NAME, } from '../utils/index.js';
|
|
7
7
|
import { Action } from '../action/index.js';
|
|
8
8
|
import { DefaultLogger, X_PX_ENFORCER_LOG_HEADER } from '../logger/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* The default implementation of the request context which uses the incoming HTTP request and enforcer configuration
|
|
11
|
+
* to populate the context with relevant data.
|
|
12
|
+
*/
|
|
9
13
|
export class DefaultContext {
|
|
10
14
|
requestId;
|
|
11
15
|
tokenOrigin;
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { DefaultLogger } from '../logger/index.js';
|
|
2
2
|
import { SerializedToken } from '../risk_token/index.js';
|
|
3
3
|
import { SerializedRiskResponse } from '../risk_api/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Implements the `IContext` interface based an already serialized `ContextJson`. This class does not extract data from the
|
|
6
|
+
* incoming request, but rather uses already-extracted data from the `ContextJson` (likely returned from the `DefaultContext.toJSON()`
|
|
7
|
+
* function) and fills in the gaps using the other parameters.
|
|
8
|
+
*/
|
|
4
9
|
export class SerializedContext {
|
|
5
10
|
isMobile;
|
|
6
11
|
remoteConfigUpdateData;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../
|
|
1
|
+
import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../flow/index.js';
|
|
2
2
|
import { createEnforcerInitializationBlock } from './utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* The base class for fundamental enforcer logic.
|
|
5
|
+
*/
|
|
3
6
|
export class EnforcerBase {
|
|
4
7
|
config;
|
|
5
8
|
filterFlow;
|
|
@@ -27,15 +30,47 @@ export class EnforcerBase {
|
|
|
27
30
|
this.config.logger.debug('HUMAN enforcer is disabled, will not enforce');
|
|
28
31
|
}
|
|
29
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Creates the filter flow for the enforcer. The filter flow is responsible for filtering out requests that should not undergo the usual enforcement flow.
|
|
35
|
+
* For example, first party, filtered, CORS preflight, and telemetry requests are filtered out.
|
|
36
|
+
* @param config - The configuration object.
|
|
37
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
38
|
+
* @protected
|
|
39
|
+
* @returns - The filter flow for the enforcer.
|
|
40
|
+
*/
|
|
30
41
|
createFilterFlow(config, initializationBlock) {
|
|
31
42
|
return new FilterFlow(config, initializationBlock);
|
|
32
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates the post enforce flow for the enforcer. The post enforce flow is responsible for any logic that requires the origin response in the case of passed requests.
|
|
46
|
+
* For example, enriching the context with response data (status, login successful information) and modifying the origin response (snippet injection, PXHD) are part of the post enforce flow.
|
|
47
|
+
* @param config - The configuration object.
|
|
48
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
49
|
+
* @protected
|
|
50
|
+
* @returns - The post enforce flow for the enforcer or null if post enforce is not enabled.
|
|
51
|
+
*/
|
|
33
52
|
createPostEnforceFlow(config, initializationBlock) {
|
|
34
|
-
return new PostEnforceFlow(config, initializationBlock);
|
|
53
|
+
return this.config.isPostEnforceEnabled ? new PostEnforceFlow(config, initializationBlock) : null;
|
|
35
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Creates the enforce flow for the enforcer. The enforce flow is responsible for the core functionality of HUMAN enforcement.
|
|
57
|
+
* For example, parsing HUMAN cookies, performing Risk API, invoking the additional activity handler, and returning a block response are part of the enforce flow.
|
|
58
|
+
* @param config - The configuration object.
|
|
59
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
60
|
+
* @protected
|
|
61
|
+
* @returns - The enforce flow for the enforcer.
|
|
62
|
+
*/
|
|
36
63
|
createEnforceFlow(config, initializationBlock) {
|
|
37
64
|
return new EnforceFlow(config, initializationBlock);
|
|
38
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates the end enforce flow for the enforcer. The end enforce flow is responsible for all actions that must be done after every incoming request.
|
|
68
|
+
* For example, sending the async activities, sending the telemetry activity, or updating the remote config, sending and clearing the enforcer logs, are parts of the end enforce flow.
|
|
69
|
+
* @param config - The configuration object.
|
|
70
|
+
* @param initializationBlock - All entities necessary for the enforcer to function.
|
|
71
|
+
* @protected
|
|
72
|
+
* @returns - The end enforce flow for the enforcer.
|
|
73
|
+
*/
|
|
39
74
|
createEndEnforcerFlow(config, initializationBlock) {
|
|
40
75
|
return new EndEnforcerFlow(config, initializationBlock);
|
|
41
76
|
}
|
|
@@ -72,12 +107,14 @@ export class EnforcerBase {
|
|
|
72
107
|
await this.endEnforcerFlow.execute(context);
|
|
73
108
|
return result.response ? this.convertToRes(result.response, ...args) : null;
|
|
74
109
|
}
|
|
75
|
-
await this.preserveContext(context, ...args);
|
|
76
110
|
result = await this.enforceFlow.execute(context);
|
|
77
|
-
if (result.done) {
|
|
111
|
+
if (result.done || !this.config.isPostEnforceEnabled) {
|
|
78
112
|
await this.endEnforcerFlow.execute(context);
|
|
79
113
|
return result.response ? this.convertToRes(result.response, ...args) : null;
|
|
80
114
|
}
|
|
115
|
+
if (this.config.isPostEnforceEnabled) {
|
|
116
|
+
await this.preserveContext(context, ...args);
|
|
117
|
+
}
|
|
81
118
|
return null;
|
|
82
119
|
}
|
|
83
120
|
/**
|
|
@@ -88,13 +125,13 @@ export class EnforcerBase {
|
|
|
88
125
|
async postEnforce(...args) {
|
|
89
126
|
let context;
|
|
90
127
|
try {
|
|
91
|
-
if (!this.config.moduleEnabled) {
|
|
128
|
+
if (!this.config.moduleEnabled || !this.config.isPostEnforceEnabled) {
|
|
92
129
|
return;
|
|
93
130
|
}
|
|
94
131
|
context = this.retrieveContext(...args);
|
|
95
132
|
if (context) {
|
|
96
133
|
context.response = await this.convertToOutgoingResponse(...args);
|
|
97
|
-
await this.postEnforceFlow
|
|
134
|
+
await this.postEnforceFlow?.execute(context);
|
|
98
135
|
await this.endEnforcerFlow.execute(context);
|
|
99
136
|
}
|
|
100
137
|
}
|