perimeterx-js-core 1.0.1 → 1.2.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 +8 -0
- package/lib/cjs/action/ActionPriorityOrder.js +2 -0
- package/lib/cjs/activities/ActivityType.js +1 -0
- package/lib/cjs/activities/HttpActivityClient.js +28 -7
- package/lib/cjs/activities/utils.js +20 -1
- package/lib/cjs/blocker/model/BlockAction.js +1 -0
- package/lib/cjs/config/ConfigurationBase.js +7 -0
- package/lib/cjs/config/defaults/DefaultConfigurationParams.js +1 -0
- package/lib/cjs/flow/EnforceFlow.js +1 -0
- package/lib/cjs/phase/impl/CreateRedirectResponsePhase.js +100 -0
- package/lib/cjs/phase/impl/RiskApiPhase.js +4 -0
- package/lib/cjs/phase/impl/SendAsyncActivitiesPhase.js +7 -1
- package/lib/cjs/phase/impl/index.js +1 -0
- package/lib/cjs/products/bot_defender/BotDefender.js +16 -3
- package/lib/cjs/products/bot_defender/filter/DefaultBotDefenderFilter.js +8 -1
- package/lib/cjs/products/bot_defender/reasons/BotDefenderRedirectReason.js +7 -0
- package/lib/cjs/products/bot_defender/reasons/index.js +1 -0
- package/lib/cjs/risk_api/model/GetRiskResponseHeaders.js +3 -0
- package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +27 -0
- package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +3 -0
- package/lib/cjs/risk_api/risk_response/v2/GetRiskResponseV2.js +6 -0
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/utils.js +19 -1
- package/lib/esm/action/Action.js +8 -0
- package/lib/esm/action/ActionPriorityOrder.js +2 -0
- package/lib/esm/activities/ActivityType.js +1 -0
- package/lib/esm/activities/HttpActivityClient.js +28 -7
- package/lib/esm/activities/utils.js +18 -0
- package/lib/esm/blocker/model/BlockAction.js +1 -0
- package/lib/esm/config/ConfigurationBase.js +3 -0
- package/lib/esm/config/defaults/DefaultConfigurationParams.js +1 -0
- package/lib/esm/context/DefaultContext.js +1 -0
- package/lib/esm/flow/EnforceFlow.js +2 -1
- package/lib/esm/phase/impl/CreateRedirectResponsePhase.js +40 -0
- package/lib/esm/phase/impl/RiskApiPhase.js +4 -0
- package/lib/esm/phase/impl/SendAsyncActivitiesPhase.js +7 -1
- package/lib/esm/phase/impl/index.js +1 -0
- package/lib/esm/products/bot_defender/BotDefender.js +16 -4
- package/lib/esm/products/bot_defender/filter/DefaultBotDefenderFilter.js +8 -2
- package/lib/esm/products/bot_defender/reasons/BotDefenderRedirectReason.js +4 -0
- package/lib/esm/products/bot_defender/reasons/index.js +1 -0
- package/lib/esm/risk_api/model/GetRiskResponseHeaders.js +3 -0
- package/lib/esm/risk_api/risk_response/RiskResponseBase.js +12 -0
- package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +6 -0
- package/lib/esm/risk_api/risk_response/v2/GetRiskResponseV2.js +6 -0
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/utils.js +17 -0
- package/lib/types/action/Action.d.ts +9 -1
- package/lib/types/activities/ActivityType.d.ts +2 -1
- package/lib/types/activities/HttpActivityClient.d.ts +12 -0
- package/lib/types/activities/model/AsyncActivityDetails.d.ts +11 -1
- package/lib/types/activities/utils.d.ts +2 -1
- package/lib/types/blocker/model/BlockAction.d.ts +2 -1
- package/lib/types/config/ConfigurationBase.d.ts +1 -0
- package/lib/types/config/IConfiguration.d.ts +4 -0
- package/lib/types/config/params/CoreConfigurationParams.d.ts +1 -0
- package/lib/types/context/DefaultContext.d.ts +1 -0
- package/lib/types/context/interfaces/IContext.d.ts +4 -0
- package/lib/types/phase/impl/CreateRedirectResponsePhase.d.ts +17 -0
- package/lib/types/phase/impl/index.d.ts +1 -0
- package/lib/types/products/bot_defender/BotDefender.d.ts +1 -1
- package/lib/types/products/bot_defender/filter/DefaultBotDefenderFilter.d.ts +1 -0
- package/lib/types/products/bot_defender/reasons/BotDefenderReasonType.d.ts +2 -1
- package/lib/types/products/bot_defender/reasons/BotDefenderRedirectReason.d.ts +3 -0
- package/lib/types/products/bot_defender/reasons/index.d.ts +1 -0
- package/lib/types/risk_api/risk_response/CommonRiskResponsePayload.d.ts +3 -0
- package/lib/types/risk_api/risk_response/IRiskResponse.d.ts +3 -0
- package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +3 -0
- package/lib/types/risk_api/risk_response/serialize/RiskResponseJson.d.ts +3 -0
- package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +3 -0
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/utils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -170,6 +170,9 @@ export class ConfigurationBase {
|
|
|
170
170
|
get filteredExtensions() {
|
|
171
171
|
return this.configParams.px_filter_by_extension;
|
|
172
172
|
}
|
|
173
|
+
get matrixParamsEnabled() {
|
|
174
|
+
return this.configParams.px_matrix_params_enabled;
|
|
175
|
+
}
|
|
173
176
|
get filteredHttpMethods() {
|
|
174
177
|
return this.configParams.px_filter_by_http_method;
|
|
175
178
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdditionalActivityHandlerPhase, CreateBlockResponsePhase, EnrichContextFromRequestPhase, ModifyIncomingRequestPhase, ParseTokenPhase, RiskApiPhase, } from '../phase/index.js';
|
|
1
|
+
import { AdditionalActivityHandlerPhase, CreateBlockResponsePhase, CreateRedirectResponsePhase, EnrichContextFromRequestPhase, ModifyIncomingRequestPhase, ParseTokenPhase, RiskApiPhase, } from '../phase/index.js';
|
|
2
2
|
import { Flow } from './Flow.js';
|
|
3
3
|
export class EnforceFlow extends Flow {
|
|
4
4
|
constructor(config, { dataEnrichment, tokenParser, riskApiClient, cors, products, graphQLParser, }) {
|
|
@@ -7,6 +7,7 @@ export class EnforceFlow extends Flow {
|
|
|
7
7
|
new EnrichContextFromRequestPhase(config, products, dataEnrichment, graphQLParser),
|
|
8
8
|
new RiskApiPhase(products, riskApiClient),
|
|
9
9
|
new AdditionalActivityHandlerPhase(config),
|
|
10
|
+
new CreateRedirectResponsePhase(config, cors),
|
|
10
11
|
new CreateBlockResponsePhase(config, CreateBlockResponsePhase.getBlockers(products), cors),
|
|
11
12
|
new ModifyIncomingRequestPhase(Object.values(products)),
|
|
12
13
|
]);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MinimalResponseImpl, MinimalResponseUtils } from '../../http/index.js';
|
|
2
|
+
import { Action } from '../../action/index.js';
|
|
3
|
+
import { PXHDSource, PXHDUtils } from '../../pxhd/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* `CreateRedirectResponsePhase` is a phase that creates a 302 redirect response when the enforcer
|
|
6
|
+
* action is REDIRECT. It mirrors the structure of `CreateBlockResponsePhase`.
|
|
7
|
+
*/
|
|
8
|
+
export class CreateRedirectResponsePhase {
|
|
9
|
+
config;
|
|
10
|
+
cors;
|
|
11
|
+
constructor(config, cors) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
if (cors) {
|
|
14
|
+
this.cors = cors;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async execute(context) {
|
|
18
|
+
if (context.action !== Action.REDIRECT) {
|
|
19
|
+
return { done: false };
|
|
20
|
+
}
|
|
21
|
+
context.logger.debug('create redirect response phase');
|
|
22
|
+
let response = new MinimalResponseImpl({
|
|
23
|
+
status: 302,
|
|
24
|
+
headers: { location: [context.redirectUrl] },
|
|
25
|
+
body: '',
|
|
26
|
+
});
|
|
27
|
+
response = await this.addHeadersToResponse(response, context);
|
|
28
|
+
return { done: true, response };
|
|
29
|
+
}
|
|
30
|
+
async addHeadersToResponse(response, context) {
|
|
31
|
+
if (!context.isMobile && context.pxhd?.source === PXHDSource.RISK) {
|
|
32
|
+
response = PXHDUtils.addPxhdToMinimalResponse(this.config, context, response);
|
|
33
|
+
}
|
|
34
|
+
if (this.config.corsSupportEnabled && this.cors && this.cors.isCorsRequest(context)) {
|
|
35
|
+
const corsHeaders = await this.cors.getCorsBlockHeaders(context);
|
|
36
|
+
response = MinimalResponseUtils.appendHeaders(response, corsHeaders);
|
|
37
|
+
}
|
|
38
|
+
return response;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Action, getReasonForHighestPriorityProduct } from '../../action/index.js';
|
|
2
2
|
import { isNullOrUndefined } from '../../utils/index.js';
|
|
3
3
|
import { PXHDSource } from '../../pxhd/index.js';
|
|
4
|
+
import { BlockAction } from '../../blocker/index.js';
|
|
4
5
|
import { DecideActionPhase } from './DecideActionPhase.js';
|
|
5
6
|
/**
|
|
6
7
|
* The `RiskApiPhase` class is responsible for making the synchronous Risk API request when necessary. If a Risk API call
|
|
@@ -64,6 +65,9 @@ export class RiskApiPhase extends DecideActionPhase {
|
|
|
64
65
|
source: PXHDSource.RISK,
|
|
65
66
|
};
|
|
66
67
|
}
|
|
68
|
+
if (riskResponse.action === BlockAction.REDIRECT && riskResponse.redirectUrl) {
|
|
69
|
+
context.redirectUrl = riskResponse.redirectUrl;
|
|
70
|
+
}
|
|
67
71
|
}
|
|
68
72
|
async enrichContextWithProductDataFromRiskApi(context) {
|
|
69
73
|
await Promise.all(Object.entries(this.products).map(async ([name, product]) => {
|
|
@@ -10,7 +10,13 @@ export class SendAsyncActivitiesPhase {
|
|
|
10
10
|
this.activityClient = activityClient;
|
|
11
11
|
}
|
|
12
12
|
async execute(context) {
|
|
13
|
-
if ([
|
|
13
|
+
if ([
|
|
14
|
+
Action.PASS_REQUEST,
|
|
15
|
+
Action.BLOCK,
|
|
16
|
+
Action.SIMULATED_BLOCK,
|
|
17
|
+
Action.REDIRECT,
|
|
18
|
+
Action.SIMULATED_REDIRECT,
|
|
19
|
+
].includes(context.action)) {
|
|
14
20
|
// ensure error handling is done in the sendActivities method
|
|
15
21
|
const promise = this.activityClient.sendActivities(context);
|
|
16
22
|
if (this.config.awaitAsyncHttpRequests) {
|
|
@@ -6,6 +6,7 @@ export * from './ParseTokenPhase.js';
|
|
|
6
6
|
export * from './DecideActionPhase.js';
|
|
7
7
|
export * from './RiskApiPhase.js';
|
|
8
8
|
export * from './CreateBlockResponsePhase.js';
|
|
9
|
+
export * from './CreateRedirectResponsePhase.js';
|
|
9
10
|
export * from './ModifyIncomingRequestPhase.js';
|
|
10
11
|
export * from './EnrichContextFromResponsePhase.js';
|
|
11
12
|
export * from './ModifyOutgoingResponsePhase.js';
|
|
@@ -7,7 +7,8 @@ import { MonitoredRequestUtils } from '../../monitored_request/index.js';
|
|
|
7
7
|
import { DefaultBotDefenderBlocker } from './block/index.js';
|
|
8
8
|
import { DefaultBotDefenderFilter } from './filter/index.js';
|
|
9
9
|
import { DefaultBotDefenderFirstParty } from './first_party/index.js';
|
|
10
|
-
import { BotDefenderBlockReason, BotDefenderPassReason, BotDefenderS2SCallReason } from './reasons/index.js';
|
|
10
|
+
import { BotDefenderBlockReason, BotDefenderPassReason, BotDefenderRedirectReason, BotDefenderS2SCallReason, } from './reasons/index.js';
|
|
11
|
+
import { BlockAction } from '../../blocker/index.js';
|
|
11
12
|
import { BotDefenderActionData } from './BotDefenderActionData.js';
|
|
12
13
|
import { BotDefenderUtils } from './BotDefenderUtils.js';
|
|
13
14
|
export class BotDefender {
|
|
@@ -77,7 +78,7 @@ export class BotDefender {
|
|
|
77
78
|
async enrichContextFromRiskApi(context) {
|
|
78
79
|
return await this.getRiskApiActionData(context);
|
|
79
80
|
}
|
|
80
|
-
async getRiskApiActionData({ riskApiData, productData: { bd }, }) {
|
|
81
|
+
async getRiskApiActionData({ riskApiData, productData: { bd }, logger, }) {
|
|
81
82
|
switch (riskApiData.riskApiCallResult) {
|
|
82
83
|
case RiskApiCallResult.NONE:
|
|
83
84
|
throw new EnforcerError('risk api call result should not be none!');
|
|
@@ -85,11 +86,22 @@ export class BotDefender {
|
|
|
85
86
|
return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_ERROR);
|
|
86
87
|
case RiskApiCallResult.TIMEOUT:
|
|
87
88
|
return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_TIMEOUT);
|
|
88
|
-
case RiskApiCallResult.SUCCESSFUL:
|
|
89
|
-
|
|
89
|
+
case RiskApiCallResult.SUCCESSFUL: {
|
|
90
|
+
const riskResponse = riskApiData.riskResponse;
|
|
91
|
+
const isMonitored = !!bd?.isMonitoredRequest;
|
|
92
|
+
const actionData = this.getSuccessfulRiskApiAction(riskResponse, isMonitored);
|
|
93
|
+
logger.debug(`bot defender action: ${actionData.action}, risk action: ${riskResponse.action}, redirect url: ${riskResponse.redirectUrl}, score: ${riskResponse.score}, monitored: ${isMonitored}`);
|
|
94
|
+
return actionData;
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
}
|
|
92
98
|
getSuccessfulRiskApiAction(riskResponse, isMonitored) {
|
|
99
|
+
if (riskResponse.action === BlockAction.REDIRECT) {
|
|
100
|
+
if (!riskResponse.redirectUrl) {
|
|
101
|
+
return new BotDefenderActionData(Action.PASS_REQUEST, BotDefenderPassReason.S2S_ERROR);
|
|
102
|
+
}
|
|
103
|
+
return new BotDefenderActionData(isMonitored ? Action.SIMULATED_REDIRECT : Action.REDIRECT, BotDefenderRedirectReason.S2S);
|
|
104
|
+
}
|
|
93
105
|
if (riskResponse.score >= this.config.blockingScore) {
|
|
94
106
|
return new BotDefenderActionData(isMonitored ? Action.SIMULATED_BLOCK : Action.BLOCK, BotDefenderBlockReason.S2S_HIGH_SCORE);
|
|
95
107
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod } from '../../../http/index.js';
|
|
2
2
|
import { FilterReason } from '../../../filter/index.js';
|
|
3
|
-
import { getExtension, isStringInPatterns } from '../../../utils/index.js';
|
|
3
|
+
import { getExtension, isStringInPatterns, stripMatrixParams } from '../../../utils/index.js';
|
|
4
4
|
export class DefaultBotDefenderFilter {
|
|
5
5
|
config;
|
|
6
6
|
ipRangeChecker;
|
|
@@ -42,9 +42,15 @@ export class DefaultBotDefenderFilter {
|
|
|
42
42
|
if (requestData.method !== HttpMethod.GET && requestData.method !== HttpMethod.HEAD) {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
-
const ext = getExtension(requestData.url.href);
|
|
45
|
+
const ext = getExtension(this.getExtensionFilterPath(requestData.url.href));
|
|
46
46
|
return !!ext && this.config.filteredExtensions.includes(ext);
|
|
47
47
|
}
|
|
48
|
+
getExtensionFilterPath(url) {
|
|
49
|
+
if (!this.config.matrixParamsEnabled) {
|
|
50
|
+
return url;
|
|
51
|
+
}
|
|
52
|
+
return stripMatrixParams(url.split('?', 1)[0]?.split('#', 1)[0] ?? url);
|
|
53
|
+
}
|
|
48
54
|
shouldFilterByHttpMethod(method) {
|
|
49
55
|
return this.config.filteredHttpMethods.some((filteredMethod) => filteredMethod.toUpperCase() === method);
|
|
50
56
|
}
|
|
@@ -10,4 +10,7 @@ export const GetRiskResponseHeaders = {
|
|
|
10
10
|
Status: 'x-px-status',
|
|
11
11
|
TelemetryRequested: 'x-px-telemetry-requested',
|
|
12
12
|
Uuid: 'x-px-uuid',
|
|
13
|
+
RedirectUrl: 'x-px-redirect-url',
|
|
14
|
+
RedirectRuleId: 'x-px-redirect-rule-id',
|
|
15
|
+
RedirectRuleName: 'x-px-redirect-rule-name',
|
|
13
16
|
};
|
|
@@ -48,6 +48,15 @@ export class RiskResponseBase {
|
|
|
48
48
|
get drc() {
|
|
49
49
|
return this.riskResponse?.drc;
|
|
50
50
|
}
|
|
51
|
+
get redirectUrl() {
|
|
52
|
+
return this.riskResponse?.redirect_url;
|
|
53
|
+
}
|
|
54
|
+
get redirectRuleId() {
|
|
55
|
+
return this.riskResponse?.redirect_rule_id;
|
|
56
|
+
}
|
|
57
|
+
get redirectRuleName() {
|
|
58
|
+
return this.riskResponse?.redirect_rule_name;
|
|
59
|
+
}
|
|
51
60
|
toJSON() {
|
|
52
61
|
return {
|
|
53
62
|
status: this.status,
|
|
@@ -61,6 +70,9 @@ export class RiskResponseBase {
|
|
|
61
70
|
additionalRiskInfo: this.additionalRiskInfo,
|
|
62
71
|
telemetryRequested: this.telemetryRequested,
|
|
63
72
|
uuid: this.uuid,
|
|
73
|
+
redirectUrl: this.redirectUrl,
|
|
74
|
+
redirectRuleId: this.redirectRuleId,
|
|
75
|
+
redirectRuleName: this.redirectRuleName,
|
|
64
76
|
};
|
|
65
77
|
}
|
|
66
78
|
}
|
|
@@ -11,6 +11,9 @@ export class SerializedRiskResponse {
|
|
|
11
11
|
score;
|
|
12
12
|
status;
|
|
13
13
|
uuid;
|
|
14
|
+
redirectUrl;
|
|
15
|
+
redirectRuleId;
|
|
16
|
+
redirectRuleName;
|
|
14
17
|
constructor(riskResponseJson) {
|
|
15
18
|
this.action = riskResponseJson.action;
|
|
16
19
|
this.additionalRiskInfo = riskResponseJson.additionalRiskInfo;
|
|
@@ -23,6 +26,9 @@ export class SerializedRiskResponse {
|
|
|
23
26
|
this.score = riskResponseJson.score;
|
|
24
27
|
this.status = riskResponseJson.status;
|
|
25
28
|
this.uuid = riskResponseJson.uuid;
|
|
29
|
+
this.redirectUrl = riskResponseJson.redirectUrl;
|
|
30
|
+
this.redirectRuleId = riskResponseJson.redirectRuleId;
|
|
31
|
+
this.redirectRuleName = riskResponseJson.redirectRuleName;
|
|
26
32
|
}
|
|
27
33
|
validate() {
|
|
28
34
|
throw new EnforcerError('SerializedRiskResponse.validate() should not be invoked');
|
|
@@ -20,6 +20,9 @@ export class GetRiskResponseV2 extends RiskResponseBase {
|
|
|
20
20
|
const telemetryRequested = this.getHeader(response, GetRiskResponseHeaders.TelemetryRequested);
|
|
21
21
|
const uuid = this.getHeader(response, GetRiskResponseHeaders.Uuid);
|
|
22
22
|
const action = this.getHeader(response, GetRiskResponseHeaders.Action);
|
|
23
|
+
const redirectUrl = this.getHeader(response, GetRiskResponseHeaders.RedirectUrl);
|
|
24
|
+
const redirectRuleId = this.getHeader(response, GetRiskResponseHeaders.RedirectRuleId);
|
|
25
|
+
const redirectRuleName = this.getHeader(response, GetRiskResponseHeaders.RedirectRuleName);
|
|
23
26
|
return {
|
|
24
27
|
status,
|
|
25
28
|
action,
|
|
@@ -32,6 +35,9 @@ export class GetRiskResponseV2 extends RiskResponseBase {
|
|
|
32
35
|
telemetry_requested: telemetryRequested === 'true',
|
|
33
36
|
drc: drc ? parseInt(drc) : undefined,
|
|
34
37
|
cookie_cfg_block_result: blockResult,
|
|
38
|
+
redirect_url: redirectUrl,
|
|
39
|
+
redirect_rule_id: redirectRuleId,
|
|
40
|
+
redirect_rule_name: redirectRuleName,
|
|
35
41
|
};
|
|
36
42
|
}
|
|
37
43
|
getHeader(response, header) {
|
|
@@ -12,4 +12,4 @@ export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
12
12
|
export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
13
13
|
export const URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
14
14
|
export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
15
|
-
export const CORE_MODULE_VERSION = 'JS Core 1.0
|
|
15
|
+
export const CORE_MODULE_VERSION = 'JS Core 1.2.0';
|
package/lib/esm/utils/utils.js
CHANGED
|
@@ -32,6 +32,23 @@ export const getExtension = (route) => {
|
|
|
32
32
|
}
|
|
33
33
|
return endOfPath.substring(extensionIndex);
|
|
34
34
|
};
|
|
35
|
+
export const stripMatrixParams = (path) => {
|
|
36
|
+
if (path.indexOf(';') === -1) {
|
|
37
|
+
return path;
|
|
38
|
+
}
|
|
39
|
+
const segments = path.split('/');
|
|
40
|
+
const stripped = [];
|
|
41
|
+
segments.forEach((segment, i) => {
|
|
42
|
+
const semicolonIndex = segment.indexOf(';');
|
|
43
|
+
if (semicolonIndex === -1) {
|
|
44
|
+
stripped.push(segment);
|
|
45
|
+
}
|
|
46
|
+
else if (semicolonIndex !== 0 || i === segments.length - 1) {
|
|
47
|
+
stripped.push(segment.substring(0, semicolonIndex));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return stripped.join('/');
|
|
51
|
+
};
|
|
35
52
|
export const redactSensitiveFields = (object, sensitiveFields) => {
|
|
36
53
|
const newObj = Object.assign({}, object);
|
|
37
54
|
sensitiveFields.forEach((fieldName) => {
|
|
@@ -17,5 +17,13 @@ export declare enum Action {
|
|
|
17
17
|
/**
|
|
18
18
|
* Indicates that the request should be blocked and a block response should be returned.
|
|
19
19
|
*/
|
|
20
|
-
BLOCK = "block"
|
|
20
|
+
BLOCK = "block",
|
|
21
|
+
/**
|
|
22
|
+
* Indicates that the client should be redirected to a specified URL with a 302 response.
|
|
23
|
+
*/
|
|
24
|
+
REDIRECT = "redirect",
|
|
25
|
+
/**
|
|
26
|
+
* Indicates that the client would be redirected, but no redirect response will be returned (monitor mode).
|
|
27
|
+
*/
|
|
28
|
+
SIMULATED_REDIRECT = "simulated_redirect"
|
|
21
29
|
}
|
|
@@ -29,6 +29,12 @@ export declare class HttpActivityClient<Req, Res, Supported extends string, Adde
|
|
|
29
29
|
* @protected
|
|
30
30
|
*/
|
|
31
31
|
protected createActivities(context: ReadonlyContext<Req, Res>): AsyncActivity[];
|
|
32
|
+
/**
|
|
33
|
+
* Whether to create a page_redirected activity based on the context.
|
|
34
|
+
* @param context
|
|
35
|
+
* @protected
|
|
36
|
+
*/
|
|
37
|
+
protected shouldCreatePageRedirectedActivity(context: ReadonlyContext<Req, Res>): boolean;
|
|
32
38
|
/**
|
|
33
39
|
* Whether to create a block activity based on the context.
|
|
34
40
|
* @param context
|
|
@@ -47,6 +53,12 @@ export declare class HttpActivityClient<Req, Res, Supported extends string, Adde
|
|
|
47
53
|
* @protected
|
|
48
54
|
*/
|
|
49
55
|
protected shouldCreateAdditionalS2SActivity(context: ReadonlyContext<Req, Res>): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Creates a page_redirected activity based on the context.
|
|
58
|
+
* @param context
|
|
59
|
+
* @protected
|
|
60
|
+
*/
|
|
61
|
+
protected createPageRedirectedActivity(context: ReadonlyContext<Req, Res>): AsyncActivity;
|
|
50
62
|
/**
|
|
51
63
|
* Creates a block activity based on the context.
|
|
52
64
|
* @param context
|
|
@@ -12,7 +12,7 @@ export type AsyncActivityCommonDetails = Partial<RiskAdditionalData> & {
|
|
|
12
12
|
http_status_code?: number;
|
|
13
13
|
credentials_compromised?: boolean;
|
|
14
14
|
};
|
|
15
|
-
export type ActivityTypeDetails = PageRequestedActivityDetails | BlockActivityDetails | AdditionalS2SActivityDetails;
|
|
15
|
+
export type ActivityTypeDetails = PageRequestedActivityDetails | BlockActivityDetails | AdditionalS2SActivityDetails | PageRedirectedActivityDetails;
|
|
16
16
|
/**
|
|
17
17
|
* Activity details that should be included in page_requested activities.
|
|
18
18
|
*/
|
|
@@ -39,3 +39,13 @@ export type AdditionalS2SActivityDetails = {
|
|
|
39
39
|
login_successful: boolean;
|
|
40
40
|
raw_username?: string;
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Activity details that should be included in page_redirected activities.
|
|
44
|
+
*/
|
|
45
|
+
export type PageRedirectedActivityDetails = {
|
|
46
|
+
redirect_url: string;
|
|
47
|
+
redirect_reason: 's2s';
|
|
48
|
+
simulated_redirect: boolean;
|
|
49
|
+
redirect_rule_id?: string;
|
|
50
|
+
redirect_rule_name?: string;
|
|
51
|
+
};
|
|
@@ -3,7 +3,7 @@ import { ReadonlyContext, RequestData, ServerData, TlsData, TokenData } from '..
|
|
|
3
3
|
import { IConfiguration } from '../config';
|
|
4
4
|
import { ProductData } from '../products';
|
|
5
5
|
import { ActivityType } from './ActivityType';
|
|
6
|
-
import { AdditionalS2SActivityDetails, AsyncActivity, AsyncActivityCommonDetails, AsyncActivityDetails, BlockActivityDetails, CommonActivityDetails, HeaderEntry, PageRequestedActivityDetails } from './model';
|
|
6
|
+
import { AdditionalS2SActivityDetails, AsyncActivity, AsyncActivityCommonDetails, AsyncActivityDetails, BlockActivityDetails, CommonActivityDetails, HeaderEntry, PageRedirectedActivityDetails, PageRequestedActivityDetails } from './model';
|
|
7
7
|
import { CustomParameters, ResponseCustomParameters } from '../custom_parameters';
|
|
8
8
|
/**
|
|
9
9
|
* Creates an async activity object based on the provided parameters.
|
|
@@ -37,4 +37,5 @@ export declare const addResponseDataToAsyncActivityCommonDetails: <Req, Res>(det
|
|
|
37
37
|
export declare const createPageRequestedActivityDetails: <Req, Res>(context: ReadonlyContext<Req, Res>) => PageRequestedActivityDetails;
|
|
38
38
|
export declare const createBlockActivityDetails: <Req, Res>(context: ReadonlyContext<Req, Res>) => BlockActivityDetails;
|
|
39
39
|
export declare const createAdditionalS2SActivityDetails: <Req, Res, Supported extends string, Added>({ ciSendRawUsernameOnAdditionalS2SActivity }: IConfiguration<Req, Res, Supported, Added>, { productData }: ReadonlyContext<Req, Res>) => AdditionalS2SActivityDetails;
|
|
40
|
+
export declare const createPageRedirectedActivityDetails: <Req, Res>(context: ReadonlyContext<Req, Res>) => PageRedirectedActivityDetails;
|
|
40
41
|
export declare const toHeaderEntryArray: (headers: Record<string, string[]>) => HeaderEntry[];
|
|
@@ -70,6 +70,7 @@ export declare abstract class ConfigurationBase<Req, Res, Supported extends stri
|
|
|
70
70
|
get enforcedRoutes(): Array<string | RegExp>;
|
|
71
71
|
get customIsEnforcedRequest(): CustomRequestFunction<Req> | null;
|
|
72
72
|
get filteredExtensions(): string[];
|
|
73
|
+
get matrixParamsEnabled(): boolean;
|
|
73
74
|
get filteredHttpMethods(): string[];
|
|
74
75
|
get filteredIps(): string[];
|
|
75
76
|
get filteredRoutes(): Array<string | RegExp>;
|
|
@@ -63,6 +63,10 @@ export interface IConfiguration<Req, Res, Supported extends string, Added> {
|
|
|
63
63
|
* An array of extensions that should not go through the enforcer flow.
|
|
64
64
|
*/
|
|
65
65
|
readonly filteredExtensions: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Whether matrix parameters (;...) should be stripped from all path segments before filtering by extension.
|
|
68
|
+
*/
|
|
69
|
+
readonly matrixParamsEnabled: boolean;
|
|
66
70
|
/**
|
|
67
71
|
* An array of IP addresses that should not go through the enforcer flow.
|
|
68
72
|
*/
|
|
@@ -95,6 +95,7 @@ export type CommonConfigurationParams<Req, Res, Supported extends string, Added>
|
|
|
95
95
|
px_sensitive_headers?: string[];
|
|
96
96
|
px_sensitive_routes?: Array<string | RegExp>;
|
|
97
97
|
px_filter_by_extension?: string[];
|
|
98
|
+
px_matrix_params_enabled?: boolean;
|
|
98
99
|
px_filter_by_http_method?: string[];
|
|
99
100
|
px_filter_by_ip?: string[];
|
|
100
101
|
px_filter_by_route?: Array<string | RegExp>;
|
|
@@ -40,6 +40,7 @@ export declare class DefaultContext<Req, Res, Supported extends string, Added> i
|
|
|
40
40
|
reasons: Partial<Record<ProductName, string>>;
|
|
41
41
|
score?: number;
|
|
42
42
|
blockAction: BlockAction;
|
|
43
|
+
redirectUrl?: string;
|
|
43
44
|
pxhd?: PXHD;
|
|
44
45
|
pxde?: PXDE;
|
|
45
46
|
pxdeVerified?: boolean;
|
|
@@ -95,6 +95,10 @@ export interface IContext<Req, Res> {
|
|
|
95
95
|
* The type of block page to present in case of a block.
|
|
96
96
|
*/
|
|
97
97
|
blockAction: BlockAction;
|
|
98
|
+
/**
|
|
99
|
+
* The URL to redirect the client to when the action is REDIRECT.
|
|
100
|
+
*/
|
|
101
|
+
redirectUrl?: string;
|
|
98
102
|
/**
|
|
99
103
|
* The PXHD (PerimeterX Hashed Data) cookie value, if it exists on the request.
|
|
100
104
|
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IConfiguration } from '../../config';
|
|
2
|
+
import { IContext, ReadonlyContext } from '../../context';
|
|
3
|
+
import { IMinimalResponse } from '../../http';
|
|
4
|
+
import { ICors } from '../../cors';
|
|
5
|
+
import { IPhase } from '../IPhase';
|
|
6
|
+
import { PhaseResult } from '../PhaseResult';
|
|
7
|
+
/**
|
|
8
|
+
* `CreateRedirectResponsePhase` is a phase that creates a 302 redirect response when the enforcer
|
|
9
|
+
* action is REDIRECT. It mirrors the structure of `CreateBlockResponsePhase`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CreateRedirectResponsePhase<Req, Res, Supported extends string, Added> implements IPhase<Req, Res> {
|
|
12
|
+
protected readonly config: IConfiguration<Req, Res, Supported, Added>;
|
|
13
|
+
protected readonly cors?: ICors<Req, Res>;
|
|
14
|
+
constructor(config: IConfiguration<Req, Res, Supported, Added>, cors?: ICors<Req, Res>);
|
|
15
|
+
execute(context: IContext<Req, Res>): Promise<PhaseResult>;
|
|
16
|
+
protected addHeadersToResponse(response: IMinimalResponse, context: ReadonlyContext<Req, Res>): Promise<IMinimalResponse>;
|
|
17
|
+
}
|
|
@@ -6,6 +6,7 @@ export * from './ParseTokenPhase';
|
|
|
6
6
|
export * from './DecideActionPhase';
|
|
7
7
|
export * from './RiskApiPhase';
|
|
8
8
|
export * from './CreateBlockResponsePhase';
|
|
9
|
+
export * from './CreateRedirectResponsePhase';
|
|
9
10
|
export * from './ModifyIncomingRequestPhase';
|
|
10
11
|
export * from './EnrichContextFromResponsePhase';
|
|
11
12
|
export * from './ModifyOutgoingResponsePhase';
|
|
@@ -42,7 +42,7 @@ export declare class BotDefender<Req, Res, Supported extends string, Added> impl
|
|
|
42
42
|
protected getNoTokenS2SCallReason({ pxhd, isMobile, tokenData, }: ReadonlyContext<Req, Res>): BotDefenderS2SCallReason;
|
|
43
43
|
protected getActionForSuccessfulTokenParse(token: IToken<Req, Res>, isMonitoredRequest: boolean, isSensitiveRequest: boolean): ActionData;
|
|
44
44
|
enrichContextFromRiskApi(context: ReadonlyContext<Req, Res>): Promise<Partial<BotDefenderData>>;
|
|
45
|
-
protected getRiskApiActionData({ riskApiData, productData: { bd }, }: ReadonlyContext<Req, Res>): Promise<ActionData>;
|
|
45
|
+
protected getRiskApiActionData({ riskApiData, productData: { bd }, logger, }: ReadonlyContext<Req, Res>): Promise<ActionData>;
|
|
46
46
|
protected getSuccessfulRiskApiAction(riskResponse: DeepReadonly<IRiskResponse>, isMonitored: boolean): ActionData;
|
|
47
47
|
shouldBlock(context: ReadonlyContext<Req, Res>): boolean;
|
|
48
48
|
createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
|
|
@@ -10,6 +10,7 @@ export declare class DefaultBotDefenderFilter<Req, Res, Supported extends string
|
|
|
10
10
|
shouldFilter(context: ReadonlyContext<Req, Res>): Promise<boolean>;
|
|
11
11
|
protected getFilterReason(context: ReadonlyContext<Req, Res>): Promise<FilterReason>;
|
|
12
12
|
protected shouldFilterByExtension(requestData: DeepReadonly<RequestData<Req>>): boolean;
|
|
13
|
+
private getExtensionFilterPath;
|
|
13
14
|
protected shouldFilterByHttpMethod(method: string): boolean;
|
|
14
15
|
protected shouldFilterByIp(ip: string): boolean;
|
|
15
16
|
protected shouldFilterByRoute(route: string): boolean;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Action } from '../../../action';
|
|
2
2
|
import { BotDefenderBlockReason } from './BotDefenderBlockReason';
|
|
3
3
|
import { BotDefenderPassReason } from './BotDefenderPassReason';
|
|
4
|
+
import { BotDefenderRedirectReason } from './BotDefenderRedirectReason';
|
|
4
5
|
import { BotDefenderS2SCallReason } from './BotDefenderS2SCallReason';
|
|
5
|
-
export type BotDefenderReasonType<A extends Action> = A extends Action.BLOCK ? BotDefenderBlockReason : A extends Action.SIMULATED_BLOCK ? BotDefenderBlockReason : A extends Action.PASS_REQUEST ? BotDefenderPassReason : A extends Action.TRIGGER_RISK_API ? BotDefenderS2SCallReason : never;
|
|
6
|
+
export type BotDefenderReasonType<A extends Action> = A extends Action.BLOCK ? BotDefenderBlockReason : A extends Action.SIMULATED_BLOCK ? BotDefenderBlockReason : A extends Action.PASS_REQUEST ? BotDefenderPassReason : A extends Action.TRIGGER_RISK_API ? BotDefenderS2SCallReason : A extends Action.REDIRECT ? BotDefenderRedirectReason : never;
|
|
@@ -15,6 +15,9 @@ export interface IRiskResponse {
|
|
|
15
15
|
readonly drc?: number;
|
|
16
16
|
readonly additionalRiskInfo?: string;
|
|
17
17
|
readonly telemetryRequested?: boolean;
|
|
18
|
+
readonly redirectUrl?: string;
|
|
19
|
+
readonly redirectRuleId?: string;
|
|
20
|
+
readonly redirectRuleName?: string;
|
|
18
21
|
validate(): AsyncOrSync<boolean>;
|
|
19
22
|
toJSON(): RiskResponseJson;
|
|
20
23
|
}
|
|
@@ -25,5 +25,8 @@ export declare abstract class RiskResponseBase<TokenV extends TokenVersion> impl
|
|
|
25
25
|
get additionalRiskInfo(): string | undefined;
|
|
26
26
|
get telemetryRequested(): boolean | undefined;
|
|
27
27
|
get drc(): number | undefined;
|
|
28
|
+
get redirectUrl(): string | undefined;
|
|
29
|
+
get redirectRuleId(): string | undefined;
|
|
30
|
+
get redirectRuleName(): string | undefined;
|
|
28
31
|
toJSON(): RiskResponseJson;
|
|
29
32
|
}
|
|
@@ -15,6 +15,9 @@ export declare class SerializedRiskResponse implements IRiskResponse {
|
|
|
15
15
|
readonly score: number | undefined;
|
|
16
16
|
readonly status?: RiskStatus;
|
|
17
17
|
readonly uuid: string | undefined;
|
|
18
|
+
readonly redirectUrl: string | undefined;
|
|
19
|
+
readonly redirectRuleId: string | undefined;
|
|
20
|
+
readonly redirectRuleName: string | undefined;
|
|
18
21
|
constructor(riskResponseJson: RiskResponseJson);
|
|
19
22
|
validate(): boolean;
|
|
20
23
|
toJSON(): RiskResponseJson;
|
|
@@ -12,4 +12,4 @@ export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
|
|
|
12
12
|
export declare const EMAIL_ADDRESS_REGEX: RegExp;
|
|
13
13
|
export declare const URL_REGEX: RegExp;
|
|
14
14
|
export declare const REGEX_STRUCTURE: RegExp;
|
|
15
|
-
export declare const CORE_MODULE_VERSION = "JS Core 1.0
|
|
15
|
+
export declare const CORE_MODULE_VERSION = "JS Core 1.2.0";
|
|
@@ -9,6 +9,7 @@ export declare const getScoreApiDomain: (appId: string) => string;
|
|
|
9
9
|
export declare const getCollectorDomain: (appId: string) => string;
|
|
10
10
|
export declare const getAuthorizationHeader: (authToken: string) => string;
|
|
11
11
|
export declare const getExtension: (route: string) => string;
|
|
12
|
+
export declare const stripMatrixParams: (path: string) => string;
|
|
12
13
|
export declare const redactSensitiveFields: <T extends Record<string, any>>(object: T, sensitiveFields: Array<keyof T | string>) => T;
|
|
13
14
|
export declare const removeSensitiveHeaders: (headers: ReadonlyHeaders, sensitiveHeaderNames: string[]) => Record<string, string[]>;
|
|
14
15
|
export declare const isStringInPatterns: (str: string, patterns: Array<string | RegExp>) => boolean;
|