perimeterx-js-core 0.2.0 → 0.4.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/README.md +16 -9
- package/lib/activities/HttpActivityClient.d.ts +1 -1
- package/lib/activities/HttpActivityClient.js +7 -4
- package/lib/activities/HttpBatchedActivityClient.d.ts +1 -1
- package/lib/activities/model/ActivityDetails.d.ts +4 -2
- package/lib/activities/utils.js +2 -1
- package/lib/block_handler/DefaultBlockResponseGenerator.d.ts +2 -2
- package/lib/block_handler/DefaultBlockResponseGenerator.js +7 -2
- package/lib/block_handler/IBlockResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.js +6 -1
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.js +8 -4
- package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.d.ts +2 -2
- package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.js +6 -1
- package/lib/config/ConfigurationParams.d.ts +4 -0
- package/lib/config/DefaultConfigurations.js +9 -5
- package/lib/config/IConfiguration.d.ts +18 -0
- package/lib/config/StaticConfigurationBase.d.ts +4 -0
- package/lib/config/StaticConfigurationBase.js +28 -0
- package/lib/context/ContextBase.d.ts +9 -7
- package/lib/context/ContextBase.js +22 -89
- package/lib/context/DefaultTokenV2Context.d.ts +2 -2
- package/lib/context/DefaultTokenV2Context.js +1 -1
- package/lib/context/DefaultTokenV3Context.d.ts +2 -2
- package/lib/context/DefaultTokenV3Context.js +1 -1
- package/lib/context/IContext.d.ts +9 -6
- package/lib/custom_parameters/CustomParametersFunction.d.ts +2 -2
- package/lib/custom_parameters/CustomParametersUtils.d.ts +3 -0
- package/lib/custom_parameters/CustomParametersUtils.js +59 -0
- package/lib/enforcer/EnforcerBase.d.ts +20 -27
- package/lib/enforcer/EnforcerBase.js +54 -19
- package/lib/filter/DefaultFilter.js +1 -1
- package/lib/first_party/DefaultFirstParty.d.ts +3 -2
- package/lib/first_party/DefaultFirstParty.js +45 -35
- package/lib/first_party/IFirstParty.d.ts +2 -2
- package/lib/first_party/constants.d.ts +2 -9
- package/lib/first_party/constants.js +7 -9
- package/lib/graphql/DefaultGraphQLParser.d.ts +19 -0
- package/lib/graphql/DefaultGraphQLParser.js +179 -0
- package/lib/graphql/IGraphQLParser.d.ts +5 -0
- package/lib/graphql/index.d.ts +5 -0
- package/lib/graphql/index.js +7 -0
- package/lib/graphql/model/GraphQLData.d.ts +7 -0
- package/lib/graphql/model/GraphQLOperation.d.ts +5 -0
- package/lib/graphql/model/GraphQLOperationType.d.ts +5 -0
- package/lib/graphql/model/GraphQLOperationType.js +9 -0
- package/lib/http/impl/MinimalResponseImpl.d.ts +13 -0
- package/lib/http/impl/MinimalResponseImpl.js +12 -0
- package/lib/http/impl/OutgoingRequestImpl.d.ts +14 -0
- package/lib/http/impl/OutgoingRequestImpl.js +14 -0
- package/lib/http/impl/index.d.ts +2 -0
- package/lib/http/impl/index.js +18 -0
- package/lib/http/index.d.ts +2 -9
- package/lib/http/index.js +2 -11
- package/lib/http/interfaces/IBody.d.ts +26 -0
- package/lib/http/interfaces/IHttpClient.d.ts +8 -0
- package/lib/http/interfaces/IIncomingRequest.d.ts +23 -0
- package/lib/http/interfaces/IIncomingRequest.js +2 -0
- package/lib/http/interfaces/IIncomingResponse.d.ts +9 -0
- package/lib/http/interfaces/IIncomingResponse.js +2 -0
- package/lib/http/interfaces/IMinimalResponse.d.ts +6 -0
- package/lib/http/interfaces/IMinimalResponse.js +2 -0
- package/lib/http/interfaces/IOutgoingRequest.d.ts +11 -0
- package/lib/http/interfaces/IOutgoingRequest.js +2 -0
- package/lib/http/interfaces/IOutgoingResponse.d.ts +17 -0
- package/lib/http/interfaces/IOutgoingResponse.js +2 -0
- package/lib/http/interfaces/ReadOnlyHeaders.d.ts +3 -0
- package/lib/http/interfaces/ReadOnlyHeaders.js +25 -0
- package/lib/http/interfaces/index.d.ts +7 -0
- package/lib/http/interfaces/index.js +23 -0
- package/lib/http/utils/MinimalResponseUtils.d.ts +4 -0
- package/lib/http/utils/MinimalResponseUtils.js +39 -0
- package/lib/http/utils/index.d.ts +1 -3
- package/lib/http/utils/index.js +2 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/pxde/IDataEnrichment.d.ts +1 -1
- package/lib/pxhd/PXHDUtils.d.ts +5 -2
- package/lib/pxhd/PXHDUtils.js +17 -2
- package/lib/risk_api/PostRiskApiClient.d.ts +3 -2
- package/lib/risk_api/PostRiskApiClient.js +20 -14
- package/lib/risk_api/S2SErrorHandler.d.ts +2 -2
- package/lib/risk_api/S2SErrorHandler.js +1 -1
- package/lib/risk_api/model/RiskActivity.d.ts +2 -0
- package/lib/risk_api/model/RiskResponseV2.d.ts +2 -0
- package/lib/risk_api/risk_response_handler/IRiskResponseHandler.d.ts +2 -2
- package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.d.ts +2 -2
- package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.js +1 -0
- package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.js +12 -4
- package/lib/telemetry/DefaultTelemetry.d.ts +2 -1
- package/lib/telemetry/DefaultTelemetry.js +16 -7
- package/lib/utils/IScoreRetriever.d.ts +1 -1
- package/lib/utils/base64/{DefaultBase64Utils.d.ts → AtobBase64Utils.d.ts} +2 -2
- package/lib/utils/base64/AtobBase64Utils.js +15 -0
- package/lib/utils/base64/BufferBase64Utils.d.ts +6 -0
- package/lib/utils/base64/BufferBase64Utils.js +18 -0
- package/lib/utils/base64/JSBase64Base64Utils.d.ts +5 -0
- package/lib/utils/base64/JSBase64Base64Utils.js +16 -0
- package/lib/utils/base64/index.d.ts +4 -2
- package/lib/utils/base64/index.js +18 -3
- package/lib/utils/cipher/CryptoCipherUtils.d.ts +12 -0
- package/lib/{http/body_reader/StringBodyReader.js → utils/cipher/CryptoCipherUtils.js} +20 -25
- package/lib/utils/cipher/SubtleCryptoCipherUtils.d.ts +9 -0
- package/lib/utils/cipher/SubtleCryptoCipherUtils.js +94 -0
- package/lib/utils/cipher/index.d.ts +2 -0
- package/lib/utils/cipher/index.js +16 -0
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/lib/utils/hash/CryptoHmacUtils.d.ts +11 -0
- package/lib/utils/hash/CryptoHmacUtils.js +25 -0
- package/lib/utils/hash/{DefaultHashUtils.d.ts → CryptoJSHmacUtils.d.ts} +1 -1
- package/lib/utils/hash/CryptoJSHmacUtils.js +19 -0
- package/lib/utils/hash/index.d.ts +3 -2
- package/lib/utils/hash/index.js +17 -3
- package/lib/utils/utils.d.ts +1 -2
- package/lib/utils/utils.js +15 -4
- package/package.json +1 -2
- package/lib/http/IHttpClient.d.ts +0 -14
- package/lib/http/body_reader/IBodyReader.d.ts +0 -5
- package/lib/http/body_reader/StringBodyReader.d.ts +0 -8
- package/lib/http/request/DefaultHttpRequest.d.ts +0 -5
- package/lib/http/request/DefaultHttpRequest.js +0 -42
- package/lib/http/request/HttpRequestBase.d.ts +0 -24
- package/lib/http/request/HttpRequestBase.js +0 -77
- package/lib/http/request/IHttpRequest.d.ts +0 -31
- package/lib/http/response/DefaultHttpResponse.d.ts +0 -5
- package/lib/http/response/DefaultHttpResponse.js +0 -32
- package/lib/http/response/HttpResponseBase.d.ts +0 -17
- package/lib/http/response/HttpResponseBase.js +0 -75
- package/lib/http/response/IHttpResponse.d.ts +0 -26
- package/lib/http/utils/HttpBody.d.ts +0 -4
- package/lib/http/utils/HttpHeaders.d.ts +0 -51
- package/lib/http/utils/HttpHeaders.js +0 -106
- package/lib/utils/base64/DefaultBase64Utils.js +0 -16
- package/lib/utils/hash/DefaultHashUtils.js +0 -19
- /package/lib/{http/IHttpClient.js → graphql/IGraphQLParser.js} +0 -0
- /package/lib/{http/body_reader/IBodyReader.js → graphql/model/GraphQLData.js} +0 -0
- /package/lib/{http/request/IHttpRequest.js → graphql/model/GraphQLOperation.js} +0 -0
- /package/lib/http/{response/IHttpResponse.js → interfaces/IBody.js} +0 -0
- /package/lib/http/{utils/HttpBody.js → interfaces/IHttpClient.js} +0 -0
|
@@ -1,44 +1,7 @@
|
|
|
1
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;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "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 (_) 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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.ContextBase = void 0;
|
|
40
4
|
var block_handler_1 = require("../block_handler");
|
|
41
|
-
var custom_parameters_1 = require("../custom_parameters");
|
|
42
5
|
var http_1 = require("../http");
|
|
43
6
|
var risk_token_1 = require("../risk_token");
|
|
44
7
|
var utils_1 = require("../utils");
|
|
@@ -63,21 +26,31 @@ var ContextBase = /** @class */ (function () {
|
|
|
63
26
|
}
|
|
64
27
|
}
|
|
65
28
|
ContextBase.prototype.createRequestData = function (config, request, cookieParser) {
|
|
66
|
-
var _a;
|
|
67
29
|
if (cookieParser === void 0) { cookieParser = new utils_1.DefaultCookieParser(); }
|
|
68
30
|
var url = (0, utils_1.getDecodedUrl)(request.url);
|
|
69
31
|
var method = request.method;
|
|
70
32
|
var headers = request.headers;
|
|
71
|
-
var
|
|
72
|
-
var cookies = cookieHeaderValue ? cookieParser.parseCookies(cookieHeaderValue) : {};
|
|
33
|
+
var cookies = this.getCookies(cookieParser, request.headers.get(http_1.COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
|
|
73
34
|
var requestCookieNames = Object.keys(cookies);
|
|
74
|
-
var
|
|
75
|
-
var
|
|
76
|
-
|
|
35
|
+
var readOnlyHeaders = (0, http_1.toReadOnlyHeaders)(headers);
|
|
36
|
+
var userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
|
|
37
|
+
var ip = this.extractIpFromHeader(config, readOnlyHeaders);
|
|
38
|
+
return { url: url, method: method, headers: readOnlyHeaders, cookies: cookies, ip: ip, userAgent: userAgent, requestCookieNames: requestCookieNames, request: request };
|
|
39
|
+
};
|
|
40
|
+
ContextBase.prototype.getCookies = function (cookieParser) {
|
|
41
|
+
var cookieHeaderValues = [];
|
|
42
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
43
|
+
cookieHeaderValues[_i - 1] = arguments[_i];
|
|
44
|
+
}
|
|
45
|
+
var cookies = {};
|
|
46
|
+
cookieHeaderValues.forEach(function (value) {
|
|
47
|
+
Object.assign(cookies, value ? cookieParser.parseCookies(value) : null);
|
|
48
|
+
});
|
|
49
|
+
return cookies;
|
|
77
50
|
};
|
|
78
51
|
ContextBase.prototype.extractUserAgentFromHeader = function (config, headers) {
|
|
79
52
|
var _a;
|
|
80
|
-
var userAgent = ((_a = headers
|
|
53
|
+
var userAgent = ((_a = headers[http_1.USER_AGENT_HEADER_NAME]) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
81
54
|
if (userAgent.length > config.userAgentMaxLength) {
|
|
82
55
|
userAgent = userAgent.substring(0, config.userAgentMaxLength);
|
|
83
56
|
}
|
|
@@ -87,7 +60,7 @@ var ContextBase = /** @class */ (function () {
|
|
|
87
60
|
var ip;
|
|
88
61
|
config.ipHeaders.some(function (ipHeader) {
|
|
89
62
|
var _a;
|
|
90
|
-
var headerValue = (_a = headers
|
|
63
|
+
var headerValue = (_a = headers[ipHeader]) === null || _a === void 0 ? void 0 : _a[0];
|
|
91
64
|
if (headerValue) {
|
|
92
65
|
ip = headerValue;
|
|
93
66
|
return true;
|
|
@@ -107,25 +80,11 @@ var ContextBase = /** @class */ (function () {
|
|
|
107
80
|
return (0, utils_1.isRouteInPatterns)(url.pathname, config.sensitiveRoutes);
|
|
108
81
|
};
|
|
109
82
|
ContextBase.prototype.isAllowedToBypassMonitor = function (config, requestData) {
|
|
110
|
-
var _a;
|
|
111
83
|
return (config.bypassMonitorHeader &&
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
ContextBase.prototype.completeInitialization = function () {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
-
return __generator(this, function (_a) {
|
|
117
|
-
switch (_a.label) {
|
|
118
|
-
case 0: return [4 /*yield*/, this.handleCustomParameters(this.config, this.requestData.request)];
|
|
119
|
-
case 1:
|
|
120
|
-
_a.sent();
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
84
|
+
requestData.request.headers.get(config.bypassMonitorHeader) === utils_1.BYPASS_MONITOR_HEADER_VALUE);
|
|
125
85
|
};
|
|
126
86
|
ContextBase.prototype.setRiskTokenOnContext = function (config, options) {
|
|
127
|
-
var
|
|
128
|
-
var mobileToken = (_a = this.requestData.headers.get(utils_1.X_PX_AUTHORIZATION_HEADER_NAME)) === null || _a === void 0 ? void 0 : _a[0];
|
|
87
|
+
var mobileToken = this.requestData.request.headers.get(utils_1.X_PX_AUTHORIZATION_HEADER_NAME);
|
|
129
88
|
if (mobileToken) {
|
|
130
89
|
this.setMobileTokenOnContext(config, mobileToken, options);
|
|
131
90
|
}
|
|
@@ -134,11 +93,10 @@ var ContextBase = /** @class */ (function () {
|
|
|
134
93
|
}
|
|
135
94
|
};
|
|
136
95
|
ContextBase.prototype.setMobileTokenOnContext = function (config, mobileToken, options) {
|
|
137
|
-
var _a, _b;
|
|
138
96
|
this.tokenOrigin = risk_token_1.TokenOrigin.HEADER;
|
|
139
97
|
this.riskToken = this.getMobileToken(config, mobileToken, options);
|
|
140
|
-
this.mobileData.originalToken = this.getMobileToken(config,
|
|
141
|
-
this.mobileData.bypassReason =
|
|
98
|
+
this.mobileData.originalToken = this.getMobileToken(config, this.requestData.request.headers.get(utils_1.X_PX_ORIGINAL_TOKEN_HEADER_NAME), options);
|
|
99
|
+
this.mobileData.bypassReason = this.requestData.request.headers.get(utils_1.X_PX_BYPASS_REASON_HEADER_NAME) || '';
|
|
142
100
|
if (!this.riskToken && /^\d+$/.test(mobileToken)) {
|
|
143
101
|
this.mobileData.mobileError = mobileToken;
|
|
144
102
|
}
|
|
@@ -169,31 +127,6 @@ var ContextBase = /** @class */ (function () {
|
|
|
169
127
|
return null;
|
|
170
128
|
}
|
|
171
129
|
};
|
|
172
|
-
ContextBase.prototype.handleCustomParameters = function (config, request) {
|
|
173
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
-
var _a, _b, _c, e_1;
|
|
175
|
-
return __generator(this, function (_d) {
|
|
176
|
-
switch (_d.label) {
|
|
177
|
-
case 0:
|
|
178
|
-
if (!(config.enrichCustomParameters && typeof config.enrichCustomParameters === 'function')) return [3 /*break*/, 4];
|
|
179
|
-
_d.label = 1;
|
|
180
|
-
case 1:
|
|
181
|
-
_d.trys.push([1, 3, , 4]);
|
|
182
|
-
_a = this;
|
|
183
|
-
_c = (_b = custom_parameters_1.CustomParametersUtils).normalizeCustomParams;
|
|
184
|
-
return [4 /*yield*/, config.enrichCustomParameters(config.toParams(), request)];
|
|
185
|
-
case 2:
|
|
186
|
-
_a.customParameters = _c.apply(_b, [_d.sent()]);
|
|
187
|
-
return [3 /*break*/, 4];
|
|
188
|
-
case 3:
|
|
189
|
-
e_1 = _d.sent();
|
|
190
|
-
config.logger.error("unable to enrich custom params: ".concat(e_1));
|
|
191
|
-
return [3 /*break*/, 4];
|
|
192
|
-
case 4: return [2 /*return*/];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
};
|
|
197
130
|
Object.defineProperty(ContextBase.prototype, "isMobile", {
|
|
198
131
|
get: function () {
|
|
199
132
|
return this.tokenOrigin === risk_token_1.TokenOrigin.HEADER;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
|
-
import { IHttpRequest } from '../http';
|
|
3
2
|
import { IBotDefenderToken } from '../risk_token';
|
|
4
3
|
import { IBase64Utils, IHashUtils } from '../utils';
|
|
5
4
|
import { ContextBase, ContextBaseOptions } from './ContextBase';
|
|
5
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
6
6
|
export declare type DefaultTokenV2ContextOptions = {
|
|
7
7
|
base64Utils?: IBase64Utils;
|
|
8
8
|
hashUtils?: IHashUtils;
|
|
9
9
|
} & ContextBaseOptions;
|
|
10
10
|
export declare class DefaultTokenV2Context extends ContextBase<DefaultTokenV2ContextOptions> {
|
|
11
|
-
constructor(config: IConfiguration, httpRequest:
|
|
11
|
+
constructor(config: IConfiguration, httpRequest: IIncomingRequest, options?: DefaultTokenV2ContextOptions);
|
|
12
12
|
protected createRiskToken(config: IConfiguration, cookies: Record<string, string>, options: DefaultTokenV2ContextOptions): IBotDefenderToken;
|
|
13
13
|
}
|
|
@@ -26,7 +26,7 @@ var DefaultTokenV2Context = /** @class */ (function (_super) {
|
|
|
26
26
|
}
|
|
27
27
|
DefaultTokenV2Context.prototype.createRiskToken = function (config, cookies, options) {
|
|
28
28
|
if (cookies[risk_token_1.COOKIE_V2_NAME]) {
|
|
29
|
-
return new risk_token_1.DefaultBotDefenderTokenV2(config, cookies[risk_token_1.COOKIE_V2_NAME], (options === null || options === void 0 ? void 0 : options.base64Utils) || new utils_1.
|
|
29
|
+
return new risk_token_1.DefaultBotDefenderTokenV2(config, cookies[risk_token_1.COOKIE_V2_NAME], (options === null || options === void 0 ? void 0 : options.base64Utils) || new utils_1.JSBase64Base64Utils(), (options === null || options === void 0 ? void 0 : options.hashUtils) || new utils_1.CryptoJSHmacUtils());
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
32
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
|
-
import { IHttpRequest } from '../http';
|
|
3
2
|
import { IBotDefenderToken } from '../risk_token';
|
|
4
3
|
import { IHashUtils, ICipherUtils } from '../utils';
|
|
5
4
|
import { ContextBase, ContextBaseOptions } from './ContextBase';
|
|
5
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
6
6
|
export declare type DefaultTokenV3ContextOptions = {
|
|
7
7
|
cipherUtils: ICipherUtils;
|
|
8
8
|
hashUtils?: IHashUtils;
|
|
9
9
|
} & ContextBaseOptions;
|
|
10
10
|
export declare class DefaultTokenV3Context extends ContextBase<DefaultTokenV3ContextOptions> {
|
|
11
|
-
constructor(config: IConfiguration, httpRequest:
|
|
11
|
+
constructor(config: IConfiguration, httpRequest: IIncomingRequest, options: DefaultTokenV3ContextOptions);
|
|
12
12
|
protected createRiskToken(config: IConfiguration, cookies: Record<string, string>, options: DefaultTokenV3ContextOptions): IBotDefenderToken;
|
|
13
13
|
}
|
|
@@ -26,7 +26,7 @@ var DefaultTokenV3Context = /** @class */ (function (_super) {
|
|
|
26
26
|
}
|
|
27
27
|
DefaultTokenV3Context.prototype.createRiskToken = function (config, cookies, options) {
|
|
28
28
|
if (cookies[risk_token_1.COOKIE_V3_NAME]) {
|
|
29
|
-
return new risk_token_1.DefaultBotDefenderTokenV3(config, cookies[risk_token_1.COOKIE_V3_NAME], options.cipherUtils, options.hashUtils || new utils_1.
|
|
29
|
+
return new risk_token_1.DefaultBotDefenderTokenV3(config, cookies[risk_token_1.COOKIE_V3_NAME], options.cipherUtils, options.hashUtils || new utils_1.CryptoJSHmacUtils());
|
|
30
30
|
}
|
|
31
31
|
return null;
|
|
32
32
|
};
|
|
@@ -3,9 +3,12 @@ import { FilterReason } from '../filter';
|
|
|
3
3
|
import { S2SCallReason, S2SErrorReason } from '../risk_api';
|
|
4
4
|
import { PassReason, VidSource } from '../utils';
|
|
5
5
|
import { BlockAction, BlockReason } from '../block_handler';
|
|
6
|
-
import { HttpHeaders, HttpMethod, IHttpRequest } from '../http';
|
|
7
6
|
import { CustomParameters } from '../custom_parameters';
|
|
8
7
|
import { PXDE } from '../pxde';
|
|
8
|
+
import { GraphQLData } from '../graphql';
|
|
9
|
+
import { HttpMethod } from '../http';
|
|
10
|
+
import { ReadOnlyHeaders } from '../http';
|
|
11
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
9
12
|
export declare type RequestData = {
|
|
10
13
|
/**
|
|
11
14
|
* The request URL.
|
|
@@ -19,7 +22,7 @@ export declare type RequestData = {
|
|
|
19
22
|
* An object representing the request headers. The keys are the header names (all lowercase) and the values
|
|
20
23
|
* are arrays of strings, with each string representing one value associated with the header name.
|
|
21
24
|
*/
|
|
22
|
-
headers:
|
|
25
|
+
headers: ReadOnlyHeaders;
|
|
23
26
|
/**
|
|
24
27
|
* An object representing the request cookies. The keys are the cookie
|
|
25
28
|
* names and the values are the cookie values.
|
|
@@ -40,7 +43,7 @@ export declare type RequestData = {
|
|
|
40
43
|
/**
|
|
41
44
|
* An interface representing the original HTTP request.
|
|
42
45
|
*/
|
|
43
|
-
request:
|
|
46
|
+
request: IIncomingRequest;
|
|
44
47
|
/**
|
|
45
48
|
* The HTTP version used for the request (e.g., 0.9, 1.0, 1.1, 2.0).
|
|
46
49
|
*/
|
|
@@ -253,8 +256,8 @@ export interface IContext {
|
|
|
253
256
|
*/
|
|
254
257
|
customParameters?: CustomParameters;
|
|
255
258
|
/**
|
|
256
|
-
*
|
|
257
|
-
* the request
|
|
259
|
+
* An array of objects with information about the different GraphQL operations
|
|
260
|
+
* parsed from the request.
|
|
258
261
|
*/
|
|
259
|
-
|
|
262
|
+
graphqlData?: GraphQLData[];
|
|
260
263
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IHttpRequest } from '../http';
|
|
2
1
|
import { ConfigurationParams } from '../config';
|
|
3
2
|
import { CustomParameters } from './CustomParameters';
|
|
4
|
-
|
|
3
|
+
import { IIncomingRequest } from '../http/interfaces/IIncomingRequest';
|
|
4
|
+
export declare type CustomParametersFunction = (config: ConfigurationParams, httpRequest: IIncomingRequest) => CustomParameters | Promise<CustomParameters>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { IConfiguration } from '../config';
|
|
2
|
+
import { IContext } from '../context';
|
|
1
3
|
import { CustomParameters } from './CustomParameters';
|
|
2
4
|
export declare namespace CustomParametersUtils {
|
|
5
|
+
const handleCustomParameters: (config: IConfiguration, context: IContext) => Promise<void>;
|
|
3
6
|
const normalizeCustomParams: (customParameters: Record<string, any>) => CustomParameters;
|
|
4
7
|
}
|
|
@@ -1,8 +1,67 @@
|
|
|
1
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;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "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 (_) 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
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.CustomParametersUtils = void 0;
|
|
4
40
|
var CustomParametersUtils;
|
|
5
41
|
(function (CustomParametersUtils) {
|
|
42
|
+
var _this = this;
|
|
43
|
+
CustomParametersUtils.handleCustomParameters = function (config, context) { return __awaiter(_this, void 0, void 0, function () {
|
|
44
|
+
var parameters, e_1;
|
|
45
|
+
return __generator(this, function (_a) {
|
|
46
|
+
switch (_a.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
if (!(config.enrichCustomParameters && typeof config.enrichCustomParameters === 'function')) return [3 /*break*/, 4];
|
|
49
|
+
_a.label = 1;
|
|
50
|
+
case 1:
|
|
51
|
+
_a.trys.push([1, 3, , 4]);
|
|
52
|
+
return [4 /*yield*/, config.enrichCustomParameters(config.toParams(), context.requestData.request)];
|
|
53
|
+
case 2:
|
|
54
|
+
parameters = _a.sent();
|
|
55
|
+
context.customParameters = CustomParametersUtils.normalizeCustomParams(parameters);
|
|
56
|
+
return [3 /*break*/, 4];
|
|
57
|
+
case 3:
|
|
58
|
+
e_1 = _a.sent();
|
|
59
|
+
config.logger.error("unable to enrich custom params: ".concat(e_1));
|
|
60
|
+
return [3 /*break*/, 4];
|
|
61
|
+
case 4: return [2 /*return*/];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}); };
|
|
6
65
|
CustomParametersUtils.normalizeCustomParams = function (customParameters) {
|
|
7
66
|
var normalizedParams = {};
|
|
8
67
|
if (customParameters && typeof customParameters === 'object') {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IEnforcer } from './IEnforcer';
|
|
2
2
|
import { IConfiguration } from '../config';
|
|
3
|
-
import { IHttpClient, IHttpRequest, IHttpResponse } from '../http';
|
|
4
3
|
import { IBase64Utils, ICipherUtils, IHashUtils, IIpRangeChecker, IScoreRetriever } from '../utils';
|
|
5
4
|
import { IContext } from '../context';
|
|
6
5
|
import { IFilter } from '../filter';
|
|
@@ -10,6 +9,10 @@ import { ITelemetry } from '../telemetry';
|
|
|
10
9
|
import { IBlockResponseGenerator } from '../block_handler';
|
|
11
10
|
import { TokenVersion } from '../risk_token';
|
|
12
11
|
import { IActivityClient } from '../activities';
|
|
12
|
+
import { IGraphQLParser } from '../graphql';
|
|
13
|
+
import { IHttpClient } from '../http';
|
|
14
|
+
import { IOutgoingResponse } from '../http';
|
|
15
|
+
import { IMinimalResponse } from '../http';
|
|
13
16
|
export declare type EnforcerBaseOptions = {
|
|
14
17
|
tokenVersion?: TokenVersion;
|
|
15
18
|
dataEnrichment?: IDataEnrichment;
|
|
@@ -20,6 +23,7 @@ export declare type EnforcerBaseOptions = {
|
|
|
20
23
|
hashUtils?: IHashUtils;
|
|
21
24
|
cipherUtils?: ICipherUtils;
|
|
22
25
|
blockGenerator?: IBlockResponseGenerator;
|
|
26
|
+
graphqlParser?: IGraphQLParser;
|
|
23
27
|
} & ({
|
|
24
28
|
httpClient: IHttpClient;
|
|
25
29
|
firstParty?: IFirstParty;
|
|
@@ -33,7 +37,7 @@ export declare type EnforcerBaseOptions = {
|
|
|
33
37
|
riskApiScoreRetriever: IScoreRetriever;
|
|
34
38
|
activityClient: IActivityClient;
|
|
35
39
|
});
|
|
36
|
-
export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res> implements IEnforcer<EnforceArgs, [Req, Res, ...EnforceArgs], Promise<
|
|
40
|
+
export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res> implements IEnforcer<EnforceArgs, [Req, Res, ...EnforceArgs], Promise<null | Res>, Promise<void>> {
|
|
37
41
|
protected config: IConfiguration;
|
|
38
42
|
protected filter: IFilter;
|
|
39
43
|
protected dataEnrichment: IDataEnrichment;
|
|
@@ -43,6 +47,7 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
43
47
|
protected riskApiScoreRetriever: IScoreRetriever;
|
|
44
48
|
protected blockGenerator: IBlockResponseGenerator;
|
|
45
49
|
protected activityClient: IActivityClient;
|
|
50
|
+
protected graphQLParser?: IGraphQLParser;
|
|
46
51
|
/**
|
|
47
52
|
* Returns the original Req object in case the module is disabled or an error is thrown.
|
|
48
53
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
@@ -65,39 +70,25 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
65
70
|
* @returns IContext - The context for the request.
|
|
66
71
|
* @protected
|
|
67
72
|
*/
|
|
68
|
-
protected abstract retrieveContext(req: Req, res: Res, ...args: EnforceArgs): IContext;
|
|
69
|
-
/**
|
|
70
|
-
* Converts the IHttpRequest object into the Req object.
|
|
71
|
-
* @param httpRequest - The IHttpRequest object.
|
|
72
|
-
* @returns Promise<Req> - A Promise resolving to Req.
|
|
73
|
-
* @protected
|
|
74
|
-
*/
|
|
75
|
-
protected abstract convertToReq(httpRequest: IHttpRequest): Promise<Req>;
|
|
73
|
+
protected abstract retrieveContext(req: Req, res: Res, ...args: EnforceArgs): IContext | null;
|
|
76
74
|
/**
|
|
77
75
|
* Converts the IHttpResponse object into the Res object.
|
|
78
76
|
* @param httpResponse - The IHttpResponse object.
|
|
79
77
|
* @returns Promise<Res> - A Promise resolving to Res.
|
|
80
78
|
* @protected
|
|
81
79
|
*/
|
|
82
|
-
protected abstract convertToRes(httpResponse:
|
|
83
|
-
/**
|
|
84
|
-
* Converts the Req object into the IHttpRequest interface.
|
|
85
|
-
* @param req - The Req object.
|
|
86
|
-
* @returns Promise<IHttpRequest> - A Promise resolving to IHttpRequest.
|
|
87
|
-
* @protected
|
|
88
|
-
*/
|
|
89
|
-
protected abstract convertToHttpRequest(req: Req): Promise<IHttpRequest>;
|
|
80
|
+
protected abstract convertToRes(httpResponse: IMinimalResponse): Promise<Res>;
|
|
90
81
|
/**
|
|
91
82
|
* Converts the Res object into the IHttpResponse interface.
|
|
92
83
|
* @param res - The Res object.
|
|
93
84
|
* @returns Promise<IHttpResponse> - A Promise resolving to IHttpResponse.
|
|
94
85
|
* @protected
|
|
95
86
|
*/
|
|
96
|
-
protected abstract convertToHttpResponse(res: Res): Promise<
|
|
87
|
+
protected abstract convertToHttpResponse(res: Res): Promise<IOutgoingResponse>;
|
|
97
88
|
/**
|
|
98
89
|
* The EnforcerBase constructor.
|
|
99
90
|
* @param config - The enforcer configuration.
|
|
100
|
-
* @param options - An
|
|
91
|
+
* @param options - An MinimalResponseOptions object that allows for overriding any functional building blocks in the enforcer.
|
|
101
92
|
* @protected
|
|
102
93
|
*/
|
|
103
94
|
protected constructor(config: IConfiguration, options: EnforcerBaseOptions);
|
|
@@ -106,24 +97,26 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
106
97
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
107
98
|
* @returns Promise<Req|Res> - A Promise resolving to a either Req or Res depending on the action that should be taken.
|
|
108
99
|
*/
|
|
109
|
-
enforce(...args: EnforceArgs): Promise<
|
|
100
|
+
enforce(...args: EnforceArgs): Promise<Res | null>;
|
|
110
101
|
/**
|
|
111
102
|
* Performs all enforcer functionality on the incoming request context.
|
|
112
103
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
113
104
|
* @returns Promise<Req|Res> - A Promise resolving to a either Req or Res depending on the action that should be taken.
|
|
114
105
|
* @protected
|
|
115
106
|
*/
|
|
116
|
-
protected doEnforce(...args: EnforceArgs): Promise<
|
|
107
|
+
protected doEnforce(...args: EnforceArgs): Promise<Res | null>;
|
|
117
108
|
protected createContext(...args: EnforceArgs): Promise<IContext>;
|
|
118
|
-
protected handleFirstParty(context: IContext): Promise<
|
|
109
|
+
protected handleFirstParty(context: IContext): Promise<IMinimalResponse>;
|
|
119
110
|
protected handleFilter(context: IContext): boolean;
|
|
120
111
|
protected handleCompleteContextInitialization(context: IContext): Promise<void>;
|
|
112
|
+
protected handleGraphQL(context: IContext): Promise<void>;
|
|
113
|
+
protected handleEnrichCustomParameters(context: IContext): Promise<void>;
|
|
121
114
|
protected handleTelemetryIfNeeded(context: IContext): Promise<void>;
|
|
122
115
|
protected handlePxde(context: IContext): Promise<void>;
|
|
123
116
|
protected handleCookieRetrieverIfNeeded(context: IContext): Promise<void>;
|
|
124
117
|
protected handleRiskApiIfNeeded(context: IContext): Promise<void>;
|
|
125
118
|
protected handleAdditionalActivityHandler(context: IContext): Promise<void>;
|
|
126
|
-
protected handleBlockResponse(context: IContext): Promise<null |
|
|
119
|
+
protected handleBlockResponse(context: IContext): Promise<null | IMinimalResponse>;
|
|
127
120
|
protected handleSendActivities(context: IContext): Promise<void>;
|
|
128
121
|
/**
|
|
129
122
|
* Performs all required functionality after an origin response has been received.
|
|
@@ -133,7 +126,7 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
133
126
|
* @returns Promise<Res> - A modified response
|
|
134
127
|
* @protected
|
|
135
128
|
*/
|
|
136
|
-
postEnforce(req: Req, res: Res, ...args: EnforceArgs): Promise<
|
|
137
|
-
protected setResponseData(context: IContext, response:
|
|
138
|
-
protected handlePxhd(context: IContext, response:
|
|
129
|
+
postEnforce(req: Req, res: Res, ...args: EnforceArgs): Promise<void>;
|
|
130
|
+
protected setResponseData(context: IContext, response: IOutgoingResponse): Promise<void>;
|
|
131
|
+
protected handlePxhd(context: IContext, response: IOutgoingResponse): Promise<void>;
|
|
139
132
|
}
|
|
@@ -57,21 +57,26 @@ var block_handler_1 = require("../block_handler");
|
|
|
57
57
|
var risk_token_1 = require("../risk_token");
|
|
58
58
|
var risk_api_1 = require("../risk_api");
|
|
59
59
|
var activities_1 = require("../activities");
|
|
60
|
+
var graphql_1 = require("../graphql");
|
|
61
|
+
var custom_parameters_1 = require("../custom_parameters");
|
|
60
62
|
var EnforcerBase = /** @class */ (function () {
|
|
61
63
|
/**
|
|
62
64
|
* The EnforcerBase constructor.
|
|
63
65
|
* @param config - The enforcer configuration.
|
|
64
|
-
* @param options - An
|
|
66
|
+
* @param options - An MinimalResponseOptions object that allows for overriding any functional building blocks in the enforcer.
|
|
65
67
|
* @protected
|
|
66
68
|
*/
|
|
67
69
|
function EnforcerBase(config, options) {
|
|
68
70
|
this.config = config;
|
|
69
|
-
var base64Utils = options.base64Utils || new utils_1.
|
|
70
|
-
var hashUtils = options.hashUtils || new utils_1.
|
|
71
|
+
var base64Utils = options.base64Utils || new utils_1.JSBase64Base64Utils();
|
|
72
|
+
var hashUtils = options.hashUtils || new utils_1.CryptoJSHmacUtils();
|
|
71
73
|
this.filter = options.filter || new filter_1.DefaultFilter(this.config, options === null || options === void 0 ? void 0 : options.ipRangeChecker);
|
|
72
74
|
this.cookieScoreRetriever = options.cookieScoreRetriever || new risk_token_1.RiskTokenScoreRetriever(this.config);
|
|
73
75
|
this.blockGenerator = options.blockGenerator || new block_handler_1.DefaultBlockResponseGenerator(this.config, base64Utils);
|
|
74
76
|
this.dataEnrichment = options.dataEnrichment || new pxde_1.DefaultDataEnrichment(this.config, base64Utils, hashUtils);
|
|
77
|
+
this.graphQLParser = this.config.graphqlEnabled
|
|
78
|
+
? options.graphqlParser || new graphql_1.DefaultGraphQLParser(this.config)
|
|
79
|
+
: null;
|
|
75
80
|
var httpClient = options.httpClient;
|
|
76
81
|
this.firstParty = options.firstParty || new first_party_1.DefaultFirstParty(this.config, httpClient);
|
|
77
82
|
this.telemetry = options.telemetry || new telemetry_1.DefaultTelemetry(this.config, httpClient, base64Utils, hashUtils);
|
|
@@ -104,7 +109,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
104
109
|
_a.trys.push([0, 2, , 3]);
|
|
105
110
|
if (!this.config.moduleEnabled) {
|
|
106
111
|
this.config.logger.debug('module is disabled, will not enforce');
|
|
107
|
-
return [2 /*return*/,
|
|
112
|
+
return [2 /*return*/, null];
|
|
108
113
|
}
|
|
109
114
|
this.config.logger.debug('module is enabled, continuing with enforcement');
|
|
110
115
|
return [4 /*yield*/, this.doEnforce.apply(this, args)];
|
|
@@ -112,7 +117,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
112
117
|
case 2:
|
|
113
118
|
e_1 = _a.sent();
|
|
114
119
|
this.config.logger.error("caught error in enforce - ".concat(e_1));
|
|
115
|
-
return [2 /*return*/,
|
|
120
|
+
return [2 /*return*/, null];
|
|
116
121
|
case 3: return [2 /*return*/];
|
|
117
122
|
}
|
|
118
123
|
});
|
|
@@ -145,36 +150,42 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
145
150
|
}
|
|
146
151
|
if (this.handleFilter(context)) {
|
|
147
152
|
this.config.logger.debug("filtering due to ".concat(context.filterReason));
|
|
148
|
-
return [2 /*return*/,
|
|
153
|
+
return [2 /*return*/, null];
|
|
149
154
|
}
|
|
150
155
|
return [4 /*yield*/, this.handleCompleteContextInitialization(context)];
|
|
151
156
|
case 3:
|
|
152
157
|
_a.sent();
|
|
153
158
|
this.config.logger.debug('context initialization complete');
|
|
154
|
-
return [4 /*yield*/, this.
|
|
159
|
+
return [4 /*yield*/, this.handleGraphQL(context)];
|
|
155
160
|
case 4:
|
|
156
161
|
_a.sent();
|
|
157
|
-
return [4 /*yield*/, this.
|
|
162
|
+
return [4 /*yield*/, this.handleEnrichCustomParameters(context)];
|
|
158
163
|
case 5:
|
|
159
164
|
_a.sent();
|
|
160
|
-
return [4 /*yield*/, this.
|
|
165
|
+
return [4 /*yield*/, this.handleTelemetryIfNeeded(context)];
|
|
161
166
|
case 6:
|
|
162
167
|
_a.sent();
|
|
163
|
-
return [4 /*yield*/, this.
|
|
168
|
+
return [4 /*yield*/, this.handlePxde(context)];
|
|
164
169
|
case 7:
|
|
165
170
|
_a.sent();
|
|
166
|
-
return [4 /*yield*/, this.
|
|
171
|
+
return [4 /*yield*/, this.handleCookieRetrieverIfNeeded(context)];
|
|
167
172
|
case 8:
|
|
168
173
|
_a.sent();
|
|
169
|
-
return [4 /*yield*/, this.
|
|
174
|
+
return [4 /*yield*/, this.handleRiskApiIfNeeded(context)];
|
|
170
175
|
case 9:
|
|
176
|
+
_a.sent();
|
|
177
|
+
return [4 /*yield*/, this.handleAdditionalActivityHandler(context)];
|
|
178
|
+
case 10:
|
|
179
|
+
_a.sent();
|
|
180
|
+
return [4 /*yield*/, this.handleBlockResponse(context)];
|
|
181
|
+
case 11:
|
|
171
182
|
httpResponse = _a.sent();
|
|
172
183
|
if (httpResponse) {
|
|
173
184
|
this.config.logger.debug("blocking request due to ".concat(context.blockReason));
|
|
174
185
|
return [2 /*return*/, this.convertToRes(httpResponse)];
|
|
175
186
|
}
|
|
176
187
|
this.config.logger.debug("passing request due to ".concat(context.passReason || 'monitor mode'));
|
|
177
|
-
return [2 /*return*/,
|
|
188
|
+
return [2 /*return*/, null];
|
|
178
189
|
}
|
|
179
190
|
});
|
|
180
191
|
});
|
|
@@ -204,10 +215,33 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
204
215
|
return this.filter.shouldFilter(context);
|
|
205
216
|
};
|
|
206
217
|
EnforcerBase.prototype.handleCompleteContextInitialization = function (context) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
219
|
+
return __generator(this, function (_a) {
|
|
220
|
+
return [2 /*return*/];
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
EnforcerBase.prototype.handleGraphQL = function (context) {
|
|
225
|
+
var _a;
|
|
226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
return __generator(this, function (_b) {
|
|
228
|
+
switch (_b.label) {
|
|
229
|
+
case 0:
|
|
230
|
+
if (!((_a = this.graphQLParser) === null || _a === void 0 ? void 0 : _a.isGraphQLRequest(context))) return [3 /*break*/, 2];
|
|
231
|
+
return [4 /*yield*/, this.graphQLParser.parseGraphQLRequest(context)];
|
|
232
|
+
case 1:
|
|
233
|
+
_b.sent();
|
|
234
|
+
_b.label = 2;
|
|
235
|
+
case 2: return [2 /*return*/];
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
};
|
|
240
|
+
EnforcerBase.prototype.handleEnrichCustomParameters = function (context) {
|
|
207
241
|
return __awaiter(this, void 0, void 0, function () {
|
|
208
242
|
return __generator(this, function (_a) {
|
|
209
243
|
switch (_a.label) {
|
|
210
|
-
case 0: return [4 /*yield*/,
|
|
244
|
+
case 0: return [4 /*yield*/, custom_parameters_1.CustomParametersUtils.handleCustomParameters(this.config, context)];
|
|
211
245
|
case 1:
|
|
212
246
|
_a.sent();
|
|
213
247
|
return [2 /*return*/];
|
|
@@ -347,15 +381,14 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
347
381
|
_a.sent();
|
|
348
382
|
return [4 /*yield*/, this.handlePxhd(context_1, response)];
|
|
349
383
|
case 5:
|
|
350
|
-
|
|
384
|
+
_a.sent();
|
|
351
385
|
_a.label = 6;
|
|
352
386
|
case 6: return [3 /*break*/, 8];
|
|
353
387
|
case 7:
|
|
354
388
|
e_2 = _a.sent();
|
|
355
389
|
this.config.logger.error("error in post enforce - ".concat(e_2));
|
|
356
390
|
return [3 /*break*/, 8];
|
|
357
|
-
case 8: return [
|
|
358
|
-
case 9: return [2 /*return*/, _a.sent()];
|
|
391
|
+
case 8: return [2 /*return*/];
|
|
359
392
|
}
|
|
360
393
|
});
|
|
361
394
|
});
|
|
@@ -363,7 +396,9 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
363
396
|
EnforcerBase.prototype.setResponseData = function (context, response) {
|
|
364
397
|
return __awaiter(this, void 0, void 0, function () {
|
|
365
398
|
return __generator(this, function (_a) {
|
|
366
|
-
|
|
399
|
+
if (response.status) {
|
|
400
|
+
context.responseData.status = response.status;
|
|
401
|
+
}
|
|
367
402
|
return [2 /*return*/];
|
|
368
403
|
});
|
|
369
404
|
});
|
|
@@ -371,7 +406,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
371
406
|
EnforcerBase.prototype.handlePxhd = function (context, response) {
|
|
372
407
|
return __awaiter(this, void 0, void 0, function () {
|
|
373
408
|
return __generator(this, function (_a) {
|
|
374
|
-
return [2 /*return*/, pxhd_1.PXHDUtils.
|
|
409
|
+
return [2 /*return*/, pxhd_1.PXHDUtils.addPxhdToOutgoingResponse(context, response)];
|
|
375
410
|
});
|
|
376
411
|
});
|
|
377
412
|
};
|