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
package/lib/cjs/action/Action.js
CHANGED
|
@@ -22,4 +22,12 @@ var Action;
|
|
|
22
22
|
* Indicates that the request should be blocked and a block response should be returned.
|
|
23
23
|
*/
|
|
24
24
|
Action["BLOCK"] = "block";
|
|
25
|
+
/**
|
|
26
|
+
* Indicates that the client should be redirected to a specified URL with a 302 response.
|
|
27
|
+
*/
|
|
28
|
+
Action["REDIRECT"] = "redirect";
|
|
29
|
+
/**
|
|
30
|
+
* Indicates that the client would be redirected, but no redirect response will be returned (monitor mode).
|
|
31
|
+
*/
|
|
32
|
+
Action["SIMULATED_REDIRECT"] = "simulated_redirect";
|
|
25
33
|
})(Action || (exports.Action = Action = {}));
|
|
@@ -7,6 +7,8 @@ var Action_1 = require("./Action.js");
|
|
|
7
7
|
* and the first action that matches a product recommendation will be taken.
|
|
8
8
|
*/
|
|
9
9
|
exports.ACTION_PRIORITY_ORDER = [
|
|
10
|
+
Action_1.Action.REDIRECT,
|
|
11
|
+
Action_1.Action.SIMULATED_REDIRECT,
|
|
10
12
|
Action_1.Action.BLOCK,
|
|
11
13
|
Action_1.Action.SIMULATED_BLOCK,
|
|
12
14
|
Action_1.Action.TRIGGER_RISK_API,
|
|
@@ -7,4 +7,5 @@ var ActivityType;
|
|
|
7
7
|
ActivityType["BLOCK"] = "block";
|
|
8
8
|
ActivityType["ADDITIONAL_S2S"] = "additional_s2s";
|
|
9
9
|
ActivityType["ENFORCER_TELEMETRY"] = "enforcer_telemetry";
|
|
10
|
+
ActivityType["PAGE_REDIRECTED"] = "page_redirected";
|
|
10
11
|
})(ActivityType || (exports.ActivityType = ActivityType = {}));
|
|
@@ -89,17 +89,30 @@ var HttpActivityClient = /** @class */ (function () {
|
|
|
89
89
|
*/
|
|
90
90
|
HttpActivityClient.prototype.createActivities = function (context) {
|
|
91
91
|
var activities = [];
|
|
92
|
-
if (this.
|
|
93
|
-
activities.push(this.
|
|
92
|
+
if (this.shouldCreatePageRedirectedActivity(context)) {
|
|
93
|
+
activities.push(this.createPageRedirectedActivity(context));
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
else {
|
|
96
|
+
if (this.shouldCreateBlockActivity(context)) {
|
|
97
|
+
activities.push(this.createBlockActivity(context));
|
|
98
|
+
}
|
|
99
|
+
if (this.shouldCreatePageRequestedActivity(context)) {
|
|
100
|
+
activities.push(this.createPageRequestedActivity(context));
|
|
101
|
+
}
|
|
102
|
+
if (this.shouldCreateAdditionalS2SActivity(context)) {
|
|
103
|
+
activities.push(this.createAdditionalS2SActivity(context));
|
|
104
|
+
}
|
|
100
105
|
}
|
|
101
106
|
return activities.map(this.finalizeActivity);
|
|
102
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Whether to create a page_redirected activity based on the context.
|
|
110
|
+
* @param context
|
|
111
|
+
* @protected
|
|
112
|
+
*/
|
|
113
|
+
HttpActivityClient.prototype.shouldCreatePageRedirectedActivity = function (context) {
|
|
114
|
+
return context.action === action_1.Action.REDIRECT || context.action === action_1.Action.SIMULATED_REDIRECT;
|
|
115
|
+
};
|
|
103
116
|
/**
|
|
104
117
|
* Whether to create a block activity based on the context.
|
|
105
118
|
* @param context
|
|
@@ -126,6 +139,14 @@ var HttpActivityClient = /** @class */ (function () {
|
|
|
126
139
|
!!context.productData.ci &&
|
|
127
140
|
this.config.ciAutomaticAdditionalS2SEnabled);
|
|
128
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Creates a page_redirected activity based on the context.
|
|
144
|
+
* @param context
|
|
145
|
+
* @protected
|
|
146
|
+
*/
|
|
147
|
+
HttpActivityClient.prototype.createPageRedirectedActivity = function (context) {
|
|
148
|
+
return (0, utils_2.createAsyncActivity)(ActivityType_1.ActivityType.PAGE_REDIRECTED, this.config, context);
|
|
149
|
+
};
|
|
129
150
|
/**
|
|
130
151
|
* Creates a block activity based on the context.
|
|
131
152
|
* @param context
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toHeaderEntryArray = exports.createAdditionalS2SActivityDetails = exports.createBlockActivityDetails = exports.createPageRequestedActivityDetails = exports.addResponseDataToAsyncActivityCommonDetails = exports.addRiskApiDataToAsyncActivityCommonDetails = exports.addTokenDataToDetails = exports.addRequestDataToDetails = exports.addServerDataToDetails = exports.addTlsDataToDetails = exports.addProductDataToDetails = exports.addCustomParametersToDetails = exports.addConfigDataToDetails = exports.addRootContextDataToDetails = exports.createCommonActivityDetails = exports.createAsyncActivityCommonDetails = exports.createActivityDetails = exports.createAsyncActivity = void 0;
|
|
3
|
+
exports.toHeaderEntryArray = exports.createPageRedirectedActivityDetails = exports.createAdditionalS2SActivityDetails = exports.createBlockActivityDetails = exports.createPageRequestedActivityDetails = exports.addResponseDataToAsyncActivityCommonDetails = exports.addRiskApiDataToAsyncActivityCommonDetails = exports.addTokenDataToDetails = exports.addRequestDataToDetails = exports.addServerDataToDetails = exports.addTlsDataToDetails = exports.addProductDataToDetails = exports.addCustomParametersToDetails = exports.addConfigDataToDetails = exports.addRootContextDataToDetails = exports.createCommonActivityDetails = exports.createAsyncActivityCommonDetails = exports.createActivityDetails = exports.createAsyncActivity = void 0;
|
|
4
4
|
exports.redactCookieSecret = redactCookieSecret;
|
|
5
5
|
var utils_1 = require("../utils/index.js");
|
|
6
6
|
var products_1 = require("../products/index.js");
|
|
@@ -52,6 +52,9 @@ var createActivityDetails = function (activityType, config, context) {
|
|
|
52
52
|
case ActivityType_1.ActivityType.ADDITIONAL_S2S:
|
|
53
53
|
specificActivityDetails = (0, exports.createAdditionalS2SActivityDetails)(config, context);
|
|
54
54
|
break;
|
|
55
|
+
case ActivityType_1.ActivityType.PAGE_REDIRECTED:
|
|
56
|
+
specificActivityDetails = (0, exports.createPageRedirectedActivityDetails)(context);
|
|
57
|
+
break;
|
|
55
58
|
}
|
|
56
59
|
return Object.assign(commonActivityDetails, commonAsyncActivityDetails, specificActivityDetails);
|
|
57
60
|
};
|
|
@@ -325,6 +328,22 @@ var createAdditionalS2SActivityDetails = function (_a, _b) {
|
|
|
325
328
|
return details;
|
|
326
329
|
};
|
|
327
330
|
exports.createAdditionalS2SActivityDetails = createAdditionalS2SActivityDetails;
|
|
331
|
+
var createPageRedirectedActivityDetails = function (context) {
|
|
332
|
+
var details = {
|
|
333
|
+
redirect_url: context.redirectUrl,
|
|
334
|
+
redirect_reason: 's2s',
|
|
335
|
+
simulated_redirect: context.action === action_1.Action.SIMULATED_REDIRECT,
|
|
336
|
+
};
|
|
337
|
+
var riskResponse = context.riskApiData.riskResponse;
|
|
338
|
+
if (riskResponse === null || riskResponse === void 0 ? void 0 : riskResponse.redirectRuleId) {
|
|
339
|
+
details.redirect_rule_id = riskResponse.redirectRuleId;
|
|
340
|
+
}
|
|
341
|
+
if (riskResponse === null || riskResponse === void 0 ? void 0 : riskResponse.redirectRuleName) {
|
|
342
|
+
details.redirect_rule_name = riskResponse.redirectRuleName;
|
|
343
|
+
}
|
|
344
|
+
return details;
|
|
345
|
+
};
|
|
346
|
+
exports.createPageRedirectedActivityDetails = createPageRedirectedActivityDetails;
|
|
328
347
|
var toHeaderEntryArray = function (headers) {
|
|
329
348
|
return Object.entries(headers).flatMap(function (_a) {
|
|
330
349
|
var key = _a[0], values = _a[1];
|
|
@@ -228,6 +228,13 @@ var ConfigurationBase = /** @class */ (function () {
|
|
|
228
228
|
enumerable: false,
|
|
229
229
|
configurable: true
|
|
230
230
|
});
|
|
231
|
+
Object.defineProperty(ConfigurationBase.prototype, "matrixParamsEnabled", {
|
|
232
|
+
get: function () {
|
|
233
|
+
return this.configParams.px_matrix_params_enabled;
|
|
234
|
+
},
|
|
235
|
+
enumerable: false,
|
|
236
|
+
configurable: true
|
|
237
|
+
});
|
|
231
238
|
Object.defineProperty(ConfigurationBase.prototype, "filteredHttpMethods", {
|
|
232
239
|
get: function () {
|
|
233
240
|
return this.configParams.px_filter_by_http_method;
|
|
@@ -27,6 +27,7 @@ var EnforceFlow = /** @class */ (function (_super) {
|
|
|
27
27
|
new phase_1.EnrichContextFromRequestPhase(config, products, dataEnrichment, graphQLParser),
|
|
28
28
|
new phase_1.RiskApiPhase(products, riskApiClient),
|
|
29
29
|
new phase_1.AdditionalActivityHandlerPhase(config),
|
|
30
|
+
new phase_1.CreateRedirectResponsePhase(config, cors),
|
|
30
31
|
new phase_1.CreateBlockResponsePhase(config, phase_1.CreateBlockResponsePhase.getBlockers(products), cors),
|
|
31
32
|
new phase_1.ModifyIncomingRequestPhase(Object.values(products)),
|
|
32
33
|
]) || this;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.CreateRedirectResponsePhase = void 0;
|
|
40
|
+
var http_1 = require("../../http/index.js");
|
|
41
|
+
var action_1 = require("../../action/index.js");
|
|
42
|
+
var pxhd_1 = require("../../pxhd/index.js");
|
|
43
|
+
/**
|
|
44
|
+
* `CreateRedirectResponsePhase` is a phase that creates a 302 redirect response when the enforcer
|
|
45
|
+
* action is REDIRECT. It mirrors the structure of `CreateBlockResponsePhase`.
|
|
46
|
+
*/
|
|
47
|
+
var CreateRedirectResponsePhase = /** @class */ (function () {
|
|
48
|
+
function CreateRedirectResponsePhase(config, cors) {
|
|
49
|
+
this.config = config;
|
|
50
|
+
if (cors) {
|
|
51
|
+
this.cors = cors;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
CreateRedirectResponsePhase.prototype.execute = function (context) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var response;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
if (context.action !== action_1.Action.REDIRECT) {
|
|
61
|
+
return [2 /*return*/, { done: false }];
|
|
62
|
+
}
|
|
63
|
+
context.logger.debug('create redirect response phase');
|
|
64
|
+
response = new http_1.MinimalResponseImpl({
|
|
65
|
+
status: 302,
|
|
66
|
+
headers: { location: [context.redirectUrl] },
|
|
67
|
+
body: '',
|
|
68
|
+
});
|
|
69
|
+
return [4 /*yield*/, this.addHeadersToResponse(response, context)];
|
|
70
|
+
case 1:
|
|
71
|
+
response = _a.sent();
|
|
72
|
+
return [2 /*return*/, { done: true, response: response }];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
CreateRedirectResponsePhase.prototype.addHeadersToResponse = function (response, context) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var corsHeaders;
|
|
80
|
+
var _a;
|
|
81
|
+
return __generator(this, function (_b) {
|
|
82
|
+
switch (_b.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
if (!context.isMobile && ((_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.source) === pxhd_1.PXHDSource.RISK) {
|
|
85
|
+
response = pxhd_1.PXHDUtils.addPxhdToMinimalResponse(this.config, context, response);
|
|
86
|
+
}
|
|
87
|
+
if (!(this.config.corsSupportEnabled && this.cors && this.cors.isCorsRequest(context))) return [3 /*break*/, 2];
|
|
88
|
+
return [4 /*yield*/, this.cors.getCorsBlockHeaders(context)];
|
|
89
|
+
case 1:
|
|
90
|
+
corsHeaders = _b.sent();
|
|
91
|
+
response = http_1.MinimalResponseUtils.appendHeaders(response, corsHeaders);
|
|
92
|
+
_b.label = 2;
|
|
93
|
+
case 2: return [2 /*return*/, response];
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
return CreateRedirectResponsePhase;
|
|
99
|
+
}());
|
|
100
|
+
exports.CreateRedirectResponsePhase = CreateRedirectResponsePhase;
|
|
@@ -55,6 +55,7 @@ exports.RiskApiPhase = void 0;
|
|
|
55
55
|
var action_1 = require("../../action/index.js");
|
|
56
56
|
var utils_1 = require("../../utils/index.js");
|
|
57
57
|
var pxhd_1 = require("../../pxhd/index.js");
|
|
58
|
+
var blocker_1 = require("../../blocker/index.js");
|
|
58
59
|
var DecideActionPhase_1 = require("./DecideActionPhase.js");
|
|
59
60
|
/**
|
|
60
61
|
* The `RiskApiPhase` class is responsible for making the synchronous Risk API request when necessary. If a Risk API call
|
|
@@ -152,6 +153,9 @@ var RiskApiPhase = /** @class */ (function (_super) {
|
|
|
152
153
|
source: pxhd_1.PXHDSource.RISK,
|
|
153
154
|
};
|
|
154
155
|
}
|
|
156
|
+
if (riskResponse.action === blocker_1.BlockAction.REDIRECT && riskResponse.redirectUrl) {
|
|
157
|
+
context.redirectUrl = riskResponse.redirectUrl;
|
|
158
|
+
}
|
|
155
159
|
};
|
|
156
160
|
RiskApiPhase.prototype.enrichContextWithProductDataFromRiskApi = function (context) {
|
|
157
161
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -52,7 +52,13 @@ var SendAsyncActivitiesPhase = /** @class */ (function () {
|
|
|
52
52
|
return __generator(this, function (_a) {
|
|
53
53
|
switch (_a.label) {
|
|
54
54
|
case 0:
|
|
55
|
-
if (![
|
|
55
|
+
if (![
|
|
56
|
+
action_1.Action.PASS_REQUEST,
|
|
57
|
+
action_1.Action.BLOCK,
|
|
58
|
+
action_1.Action.SIMULATED_BLOCK,
|
|
59
|
+
action_1.Action.REDIRECT,
|
|
60
|
+
action_1.Action.SIMULATED_REDIRECT,
|
|
61
|
+
].includes(context.action)) return [3 /*break*/, 2];
|
|
56
62
|
promise = this.activityClient.sendActivities(context);
|
|
57
63
|
if (!this.config.awaitAsyncHttpRequests) return [3 /*break*/, 2];
|
|
58
64
|
return [4 /*yield*/, promise];
|
|
@@ -22,6 +22,7 @@ __exportStar(require("./ParseTokenPhase.js"), exports);
|
|
|
22
22
|
__exportStar(require("./DecideActionPhase.js"), exports);
|
|
23
23
|
__exportStar(require("./RiskApiPhase.js"), exports);
|
|
24
24
|
__exportStar(require("./CreateBlockResponsePhase.js"), exports);
|
|
25
|
+
__exportStar(require("./CreateRedirectResponsePhase.js"), exports);
|
|
25
26
|
__exportStar(require("./ModifyIncomingRequestPhase.js"), exports);
|
|
26
27
|
__exportStar(require("./EnrichContextFromResponsePhase.js"), exports);
|
|
27
28
|
__exportStar(require("./ModifyOutgoingResponsePhase.js"), exports);
|
|
@@ -58,6 +58,7 @@ var block_1 = require("./block/index.js");
|
|
|
58
58
|
var filter_1 = require("./filter/index.js");
|
|
59
59
|
var first_party_1 = require("./first_party/index.js");
|
|
60
60
|
var reasons_1 = require("./reasons/index.js");
|
|
61
|
+
var blocker_1 = require("../../blocker/index.js");
|
|
61
62
|
var BotDefenderActionData_1 = require("./BotDefenderActionData.js");
|
|
62
63
|
var BotDefenderUtils_1 = require("./BotDefenderUtils.js");
|
|
63
64
|
var BotDefender = /** @class */ (function () {
|
|
@@ -161,7 +162,8 @@ var BotDefender = /** @class */ (function () {
|
|
|
161
162
|
};
|
|
162
163
|
BotDefender.prototype.getRiskApiActionData = function (_a) {
|
|
163
164
|
return __awaiter(this, arguments, void 0, function (_b) {
|
|
164
|
-
var
|
|
165
|
+
var riskResponse, isMonitored, actionData;
|
|
166
|
+
var riskApiData = _b.riskApiData, bd = _b.productData.bd, logger = _b.logger;
|
|
165
167
|
return __generator(this, function (_c) {
|
|
166
168
|
switch (riskApiData.riskApiCallResult) {
|
|
167
169
|
case risk_api_1.RiskApiCallResult.NONE:
|
|
@@ -170,14 +172,25 @@ var BotDefender = /** @class */ (function () {
|
|
|
170
172
|
return [2 /*return*/, new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S_ERROR)];
|
|
171
173
|
case risk_api_1.RiskApiCallResult.TIMEOUT:
|
|
172
174
|
return [2 /*return*/, new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S_TIMEOUT)];
|
|
173
|
-
case risk_api_1.RiskApiCallResult.SUCCESSFUL:
|
|
174
|
-
|
|
175
|
+
case risk_api_1.RiskApiCallResult.SUCCESSFUL: {
|
|
176
|
+
riskResponse = riskApiData.riskResponse;
|
|
177
|
+
isMonitored = !!(bd === null || bd === void 0 ? void 0 : bd.isMonitoredRequest);
|
|
178
|
+
actionData = this.getSuccessfulRiskApiAction(riskResponse, isMonitored);
|
|
179
|
+
logger.debug("bot defender action: ".concat(actionData.action, ", risk action: ").concat(riskResponse.action, ", redirect url: ").concat(riskResponse.redirectUrl, ", score: ").concat(riskResponse.score, ", monitored: ").concat(isMonitored));
|
|
180
|
+
return [2 /*return*/, actionData];
|
|
181
|
+
}
|
|
175
182
|
}
|
|
176
183
|
return [2 /*return*/];
|
|
177
184
|
});
|
|
178
185
|
});
|
|
179
186
|
};
|
|
180
187
|
BotDefender.prototype.getSuccessfulRiskApiAction = function (riskResponse, isMonitored) {
|
|
188
|
+
if (riskResponse.action === blocker_1.BlockAction.REDIRECT) {
|
|
189
|
+
if (!riskResponse.redirectUrl) {
|
|
190
|
+
return new BotDefenderActionData_1.BotDefenderActionData(action_1.Action.PASS_REQUEST, reasons_1.BotDefenderPassReason.S2S_ERROR);
|
|
191
|
+
}
|
|
192
|
+
return new BotDefenderActionData_1.BotDefenderActionData(isMonitored ? action_1.Action.SIMULATED_REDIRECT : action_1.Action.REDIRECT, reasons_1.BotDefenderRedirectReason.S2S);
|
|
193
|
+
}
|
|
181
194
|
if (riskResponse.score >= this.config.blockingScore) {
|
|
182
195
|
return new BotDefenderActionData_1.BotDefenderActionData(isMonitored ? action_1.Action.SIMULATED_BLOCK : action_1.Action.BLOCK, reasons_1.BotDefenderBlockReason.S2S_HIGH_SCORE);
|
|
183
196
|
}
|
|
@@ -98,9 +98,16 @@ var DefaultBotDefenderFilter = /** @class */ (function () {
|
|
|
98
98
|
if (requestData.method !== http_1.HttpMethod.GET && requestData.method !== http_1.HttpMethod.HEAD) {
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
|
-
var ext = (0, utils_1.getExtension)(requestData.url.href);
|
|
101
|
+
var ext = (0, utils_1.getExtension)(this.getExtensionFilterPath(requestData.url.href));
|
|
102
102
|
return !!ext && this.config.filteredExtensions.includes(ext);
|
|
103
103
|
};
|
|
104
|
+
DefaultBotDefenderFilter.prototype.getExtensionFilterPath = function (url) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
if (!this.config.matrixParamsEnabled) {
|
|
107
|
+
return url;
|
|
108
|
+
}
|
|
109
|
+
return (0, utils_1.stripMatrixParams)((_b = (_a = url.split('?', 1)[0]) === null || _a === void 0 ? void 0 : _a.split('#', 1)[0]) !== null && _b !== void 0 ? _b : url);
|
|
110
|
+
};
|
|
104
111
|
DefaultBotDefenderFilter.prototype.shouldFilterByHttpMethod = function (method) {
|
|
105
112
|
return this.config.filteredHttpMethods.some(function (filteredMethod) { return filteredMethod.toUpperCase() === method; });
|
|
106
113
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotDefenderRedirectReason = void 0;
|
|
4
|
+
var BotDefenderRedirectReason;
|
|
5
|
+
(function (BotDefenderRedirectReason) {
|
|
6
|
+
BotDefenderRedirectReason["S2S"] = "s2s";
|
|
7
|
+
})(BotDefenderRedirectReason || (exports.BotDefenderRedirectReason = BotDefenderRedirectReason = {}));
|
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./BotDefenderBlockReason.js"), exports);
|
|
18
18
|
__exportStar(require("./BotDefenderPassReason.js"), exports);
|
|
19
|
+
__exportStar(require("./BotDefenderRedirectReason.js"), exports);
|
|
19
20
|
__exportStar(require("./BotDefenderS2SCallReason.js"), exports);
|
|
20
21
|
__exportStar(require("./BotDefenderReasonType.js"), exports);
|
|
@@ -13,4 +13,7 @@ exports.GetRiskResponseHeaders = {
|
|
|
13
13
|
Status: 'x-px-status',
|
|
14
14
|
TelemetryRequested: 'x-px-telemetry-requested',
|
|
15
15
|
Uuid: 'x-px-uuid',
|
|
16
|
+
RedirectUrl: 'x-px-redirect-url',
|
|
17
|
+
RedirectRuleId: 'x-px-redirect-rule-id',
|
|
18
|
+
RedirectRuleName: 'x-px-redirect-rule-name',
|
|
16
19
|
};
|
|
@@ -145,6 +145,30 @@ var RiskResponseBase = /** @class */ (function () {
|
|
|
145
145
|
enumerable: false,
|
|
146
146
|
configurable: true
|
|
147
147
|
});
|
|
148
|
+
Object.defineProperty(RiskResponseBase.prototype, "redirectUrl", {
|
|
149
|
+
get: function () {
|
|
150
|
+
var _a;
|
|
151
|
+
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.redirect_url;
|
|
152
|
+
},
|
|
153
|
+
enumerable: false,
|
|
154
|
+
configurable: true
|
|
155
|
+
});
|
|
156
|
+
Object.defineProperty(RiskResponseBase.prototype, "redirectRuleId", {
|
|
157
|
+
get: function () {
|
|
158
|
+
var _a;
|
|
159
|
+
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.redirect_rule_id;
|
|
160
|
+
},
|
|
161
|
+
enumerable: false,
|
|
162
|
+
configurable: true
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(RiskResponseBase.prototype, "redirectRuleName", {
|
|
165
|
+
get: function () {
|
|
166
|
+
var _a;
|
|
167
|
+
return (_a = this.riskResponse) === null || _a === void 0 ? void 0 : _a.redirect_rule_name;
|
|
168
|
+
},
|
|
169
|
+
enumerable: false,
|
|
170
|
+
configurable: true
|
|
171
|
+
});
|
|
148
172
|
RiskResponseBase.prototype.toJSON = function () {
|
|
149
173
|
return {
|
|
150
174
|
status: this.status,
|
|
@@ -158,6 +182,9 @@ var RiskResponseBase = /** @class */ (function () {
|
|
|
158
182
|
additionalRiskInfo: this.additionalRiskInfo,
|
|
159
183
|
telemetryRequested: this.telemetryRequested,
|
|
160
184
|
uuid: this.uuid,
|
|
185
|
+
redirectUrl: this.redirectUrl,
|
|
186
|
+
redirectRuleId: this.redirectRuleId,
|
|
187
|
+
redirectRuleName: this.redirectRuleName,
|
|
161
188
|
};
|
|
162
189
|
};
|
|
163
190
|
return RiskResponseBase;
|
|
@@ -15,6 +15,9 @@ var SerializedRiskResponse = /** @class */ (function () {
|
|
|
15
15
|
this.score = riskResponseJson.score;
|
|
16
16
|
this.status = riskResponseJson.status;
|
|
17
17
|
this.uuid = riskResponseJson.uuid;
|
|
18
|
+
this.redirectUrl = riskResponseJson.redirectUrl;
|
|
19
|
+
this.redirectRuleId = riskResponseJson.redirectRuleId;
|
|
20
|
+
this.redirectRuleName = riskResponseJson.redirectRuleName;
|
|
18
21
|
}
|
|
19
22
|
SerializedRiskResponse.prototype.validate = function () {
|
|
20
23
|
throw new utils_1.EnforcerError('SerializedRiskResponse.validate() should not be invoked');
|
|
@@ -39,6 +39,9 @@ var GetRiskResponseV2 = /** @class */ (function (_super) {
|
|
|
39
39
|
var telemetryRequested = this.getHeader(response, model_1.GetRiskResponseHeaders.TelemetryRequested);
|
|
40
40
|
var uuid = this.getHeader(response, model_1.GetRiskResponseHeaders.Uuid);
|
|
41
41
|
var action = this.getHeader(response, model_1.GetRiskResponseHeaders.Action);
|
|
42
|
+
var redirectUrl = this.getHeader(response, model_1.GetRiskResponseHeaders.RedirectUrl);
|
|
43
|
+
var redirectRuleId = this.getHeader(response, model_1.GetRiskResponseHeaders.RedirectRuleId);
|
|
44
|
+
var redirectRuleName = this.getHeader(response, model_1.GetRiskResponseHeaders.RedirectRuleName);
|
|
42
45
|
return {
|
|
43
46
|
status: status,
|
|
44
47
|
action: action,
|
|
@@ -51,6 +54,9 @@ var GetRiskResponseV2 = /** @class */ (function (_super) {
|
|
|
51
54
|
telemetry_requested: telemetryRequested === 'true',
|
|
52
55
|
drc: drc ? parseInt(drc) : undefined,
|
|
53
56
|
cookie_cfg_block_result: blockResult,
|
|
57
|
+
redirect_url: redirectUrl,
|
|
58
|
+
redirect_rule_id: redirectRuleId,
|
|
59
|
+
redirect_rule_name: redirectRuleName,
|
|
54
60
|
};
|
|
55
61
|
};
|
|
56
62
|
GetRiskResponseV2.prototype.getHeader = function (response, header) {
|
|
@@ -15,4 +15,4 @@ exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
15
15
|
exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
16
16
|
exports.URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
17
17
|
exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
18
|
-
exports.CORE_MODULE_VERSION = 'JS Core 1.0
|
|
18
|
+
exports.CORE_MODULE_VERSION = 'JS Core 1.2.0';
|
package/lib/cjs/utils/utils.js
CHANGED
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.isAscii = exports.isNullOrUndefined = exports.isValidTokenVersion = exports.telemetryConfigReplacer = exports.convertRegexStringToRegex = exports.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.isStringMatch = exports.isStringInPatterns = exports.removeSensitiveHeaders = exports.redactSensitiveFields = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
|
|
39
|
+
exports.isAscii = exports.isNullOrUndefined = exports.isValidTokenVersion = exports.telemetryConfigReplacer = exports.convertRegexStringToRegex = exports.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.isStringMatch = exports.isStringInPatterns = exports.removeSensitiveHeaders = exports.redactSensitiveFields = exports.stripMatrixParams = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
|
|
40
40
|
var http_1 = require("../http/index.js");
|
|
41
41
|
var error_1 = require("./error/index.js");
|
|
42
42
|
var constants_1 = require("./constants.js");
|
|
@@ -79,6 +79,24 @@ var getExtension = function (route) {
|
|
|
79
79
|
return endOfPath.substring(extensionIndex);
|
|
80
80
|
};
|
|
81
81
|
exports.getExtension = getExtension;
|
|
82
|
+
var stripMatrixParams = function (path) {
|
|
83
|
+
if (path.indexOf(';') === -1) {
|
|
84
|
+
return path;
|
|
85
|
+
}
|
|
86
|
+
var segments = path.split('/');
|
|
87
|
+
var stripped = [];
|
|
88
|
+
segments.forEach(function (segment, i) {
|
|
89
|
+
var semicolonIndex = segment.indexOf(';');
|
|
90
|
+
if (semicolonIndex === -1) {
|
|
91
|
+
stripped.push(segment);
|
|
92
|
+
}
|
|
93
|
+
else if (semicolonIndex !== 0 || i === segments.length - 1) {
|
|
94
|
+
stripped.push(segment.substring(0, semicolonIndex));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return stripped.join('/');
|
|
98
|
+
};
|
|
99
|
+
exports.stripMatrixParams = stripMatrixParams;
|
|
82
100
|
var redactSensitiveFields = function (object, sensitiveFields) {
|
|
83
101
|
var newObj = Object.assign({}, object);
|
|
84
102
|
sensitiveFields.forEach(function (fieldName) {
|
package/lib/esm/action/Action.js
CHANGED
|
@@ -19,4 +19,12 @@ export var Action;
|
|
|
19
19
|
* Indicates that the request should be blocked and a block response should be returned.
|
|
20
20
|
*/
|
|
21
21
|
Action["BLOCK"] = "block";
|
|
22
|
+
/**
|
|
23
|
+
* Indicates that the client should be redirected to a specified URL with a 302 response.
|
|
24
|
+
*/
|
|
25
|
+
Action["REDIRECT"] = "redirect";
|
|
26
|
+
/**
|
|
27
|
+
* Indicates that the client would be redirected, but no redirect response will be returned (monitor mode).
|
|
28
|
+
*/
|
|
29
|
+
Action["SIMULATED_REDIRECT"] = "simulated_redirect";
|
|
22
30
|
})(Action || (Action = {}));
|
|
@@ -4,6 +4,8 @@ import { Action } from './Action.js';
|
|
|
4
4
|
* and the first action that matches a product recommendation will be taken.
|
|
5
5
|
*/
|
|
6
6
|
export const ACTION_PRIORITY_ORDER = [
|
|
7
|
+
Action.REDIRECT,
|
|
8
|
+
Action.SIMULATED_REDIRECT,
|
|
7
9
|
Action.BLOCK,
|
|
8
10
|
Action.SIMULATED_BLOCK,
|
|
9
11
|
Action.TRIGGER_RISK_API,
|
|
@@ -46,17 +46,30 @@ export class HttpActivityClient {
|
|
|
46
46
|
*/
|
|
47
47
|
createActivities(context) {
|
|
48
48
|
const activities = [];
|
|
49
|
-
if (this.
|
|
50
|
-
activities.push(this.
|
|
49
|
+
if (this.shouldCreatePageRedirectedActivity(context)) {
|
|
50
|
+
activities.push(this.createPageRedirectedActivity(context));
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
else {
|
|
53
|
+
if (this.shouldCreateBlockActivity(context)) {
|
|
54
|
+
activities.push(this.createBlockActivity(context));
|
|
55
|
+
}
|
|
56
|
+
if (this.shouldCreatePageRequestedActivity(context)) {
|
|
57
|
+
activities.push(this.createPageRequestedActivity(context));
|
|
58
|
+
}
|
|
59
|
+
if (this.shouldCreateAdditionalS2SActivity(context)) {
|
|
60
|
+
activities.push(this.createAdditionalS2SActivity(context));
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
63
|
return activities.map(this.finalizeActivity);
|
|
59
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Whether to create a page_redirected activity based on the context.
|
|
67
|
+
* @param context
|
|
68
|
+
* @protected
|
|
69
|
+
*/
|
|
70
|
+
shouldCreatePageRedirectedActivity(context) {
|
|
71
|
+
return context.action === Action.REDIRECT || context.action === Action.SIMULATED_REDIRECT;
|
|
72
|
+
}
|
|
60
73
|
/**
|
|
61
74
|
* Whether to create a block activity based on the context.
|
|
62
75
|
* @param context
|
|
@@ -83,6 +96,14 @@ export class HttpActivityClient {
|
|
|
83
96
|
!!context.productData.ci &&
|
|
84
97
|
this.config.ciAutomaticAdditionalS2SEnabled);
|
|
85
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Creates a page_redirected activity based on the context.
|
|
101
|
+
* @param context
|
|
102
|
+
* @protected
|
|
103
|
+
*/
|
|
104
|
+
createPageRedirectedActivity(context) {
|
|
105
|
+
return createAsyncActivity(ActivityType.PAGE_REDIRECTED, this.config, context);
|
|
106
|
+
}
|
|
86
107
|
/**
|
|
87
108
|
* Creates a block activity based on the context.
|
|
88
109
|
* @param context
|
|
@@ -46,6 +46,9 @@ export const createActivityDetails = (activityType, config, context) => {
|
|
|
46
46
|
case ActivityType.ADDITIONAL_S2S:
|
|
47
47
|
specificActivityDetails = createAdditionalS2SActivityDetails(config, context);
|
|
48
48
|
break;
|
|
49
|
+
case ActivityType.PAGE_REDIRECTED:
|
|
50
|
+
specificActivityDetails = createPageRedirectedActivityDetails(context);
|
|
51
|
+
break;
|
|
49
52
|
}
|
|
50
53
|
return Object.assign(commonActivityDetails, commonAsyncActivityDetails, specificActivityDetails);
|
|
51
54
|
};
|
|
@@ -297,6 +300,21 @@ export const createAdditionalS2SActivityDetails = ({ ciSendRawUsernameOnAddition
|
|
|
297
300
|
}
|
|
298
301
|
return details;
|
|
299
302
|
};
|
|
303
|
+
export const createPageRedirectedActivityDetails = (context) => {
|
|
304
|
+
const details = {
|
|
305
|
+
redirect_url: context.redirectUrl,
|
|
306
|
+
redirect_reason: 's2s',
|
|
307
|
+
simulated_redirect: context.action === Action.SIMULATED_REDIRECT,
|
|
308
|
+
};
|
|
309
|
+
const { riskResponse } = context.riskApiData;
|
|
310
|
+
if (riskResponse?.redirectRuleId) {
|
|
311
|
+
details.redirect_rule_id = riskResponse.redirectRuleId;
|
|
312
|
+
}
|
|
313
|
+
if (riskResponse?.redirectRuleName) {
|
|
314
|
+
details.redirect_rule_name = riskResponse.redirectRuleName;
|
|
315
|
+
}
|
|
316
|
+
return details;
|
|
317
|
+
};
|
|
300
318
|
export const toHeaderEntryArray = (headers) => {
|
|
301
319
|
return Object.entries(headers).flatMap(([key, values]) => values.map((value) => ({
|
|
302
320
|
name: key,
|