perimeterx-js-core 0.4.4 → 0.5.1
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 +2 -0
- package/lib/activities/utils.js +2 -1
- package/lib/block_handler/DefaultBlockResponseGenerator.d.ts +1 -1
- package/lib/block_handler/DefaultBlockResponseGenerator.js +9 -3
- package/lib/config/ConfigurationParams.d.ts +5 -0
- package/lib/config/DefaultConfigurations.js +4 -0
- package/lib/config/IConfiguration.d.ts +17 -0
- package/lib/config/StaticConfigurationBase.d.ts +5 -0
- package/lib/config/StaticConfigurationBase.js +28 -0
- package/lib/context/ContextBase.d.ts +5 -4
- package/lib/context/ContextBase.js +9 -1
- package/lib/context/IContext.d.ts +3 -2
- package/lib/cors/CustomBlockResponseHeadersHandler.d.ts +2 -0
- package/lib/cors/CustomBlockResponseHeadersHandler.js +2 -0
- package/lib/cors/CustomPreflightHandler.d.ts +2 -0
- package/lib/cors/CustomPreflightHandler.js +2 -0
- package/lib/cors/DefaultCors.d.ts +15 -0
- package/lib/cors/DefaultCors.js +107 -0
- package/lib/cors/ICors.d.ts +26 -0
- package/lib/cors/ICors.js +2 -0
- package/lib/cors/constants.d.ts +2 -0
- package/lib/cors/constants.js +5 -0
- package/lib/cors/index.d.ts +5 -0
- package/lib/cors/index.js +20 -0
- package/lib/enforcer/EnforcerBase.d.ts +4 -1
- package/lib/enforcer/EnforcerBase.js +65 -31
- package/lib/graphql/DefaultGraphQLParser.d.ts +2 -2
- package/lib/graphql/DefaultGraphQLParser.js +14 -11
- package/lib/http/interfaces/IHeaders.d.ts +8 -0
- package/lib/http/interfaces/IHeaders.js +2 -0
- package/lib/http/interfaces/IIncomingRequest.d.ts +2 -1
- package/lib/http/interfaces/IOutgoingResponse.d.ts +2 -1
- package/lib/http/interfaces/ReadOnlyHeaders.d.ts +2 -2
- package/lib/http/interfaces/ReadOnlyHeaders.js +1 -14
- package/lib/http/interfaces/index.d.ts +1 -0
- package/lib/http/interfaces/index.js +1 -0
- package/lib/http/utils/MinimalResponseUtils.d.ts +2 -0
- package/lib/http/utils/MinimalResponseUtils.js +15 -5
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/pxhd/PXHDUtils.d.ts +2 -1
- package/lib/pxhd/PXHDUtils.js +6 -2
- package/lib/pxhd/index.d.ts +1 -0
- package/lib/pxhd/index.js +15 -0
- package/lib/pxhd/model/PXHD.d.ts +6 -0
- package/lib/pxhd/model/PXHD.js +2 -0
- package/lib/pxhd/model/PXHDSource.d.ts +4 -0
- package/lib/pxhd/model/PXHDSource.js +8 -0
- package/lib/pxhd/model/index.d.ts +2 -0
- package/lib/pxhd/model/index.js +18 -0
- package/lib/risk_api/PostRiskApiClient.js +9 -5
- package/lib/risk_api/model/RiskResponseV2.d.ts +1 -0
- package/lib/risk_api/model/RiskResponseV3.d.ts +1 -0
- package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.js +15 -7
- package/lib/risk_api/risk_response_handler/RiskResponseV3Handler.js +18 -8
- package/lib/utils/constants.d.ts +1 -1
- package/lib/utils/constants.js +1 -1
- package/lib/utils/utils.d.ts +3 -0
- package/lib/utils/utils.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,6 +79,8 @@ While you will need to create a custom implementation for the request context, y
|
|
|
79
79
|
Every framework has a different API for creating and sending HTTP requests and responses. This library reduces this functionality
|
|
80
80
|
into several interfaces:
|
|
81
81
|
|
|
82
|
+
`IHeaders` - Represents the HTTP request/response headers.
|
|
83
|
+
|
|
82
84
|
`IIncomingRequest` - Represents an HTTP request from the user.
|
|
83
85
|
|
|
84
86
|
`IOutgoingResponse` - Represents an HTTP response which is returned to the user.
|
package/lib/activities/utils.js
CHANGED
|
@@ -5,12 +5,13 @@ var utils_1 = require("../utils");
|
|
|
5
5
|
var ActivityType_1 = require("./ActivityType");
|
|
6
6
|
var http_1 = require("../http");
|
|
7
7
|
var createActivity = function (activityType, config, context) {
|
|
8
|
+
var _a;
|
|
8
9
|
return {
|
|
9
10
|
type: activityType,
|
|
10
11
|
px_app_id: config.appId,
|
|
11
12
|
url: context.requestData.url.href,
|
|
12
13
|
headers: (0, http_1.joinHeaderValues)((0, utils_1.removeSensitiveHeaders)(context.requestData.headers, config.sensitiveHeaders)),
|
|
13
|
-
pxhd: context.pxhd,
|
|
14
|
+
pxhd: (_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.value,
|
|
14
15
|
socket_ip: context.requestData.ip,
|
|
15
16
|
timestamp: Date.now(),
|
|
16
17
|
vid: context.vid,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IContext } from '../context';
|
|
2
2
|
import { IConfiguration } from '../config';
|
|
3
|
+
import { IMinimalResponse } from '../http';
|
|
3
4
|
import { IBase64Utils } from '../utils';
|
|
4
5
|
import { IBlockResponseGenerator } from './IBlockResponseGenerator';
|
|
5
|
-
import { IMinimalResponse } from '../http';
|
|
6
6
|
export declare class DefaultBlockResponseGenerator implements IBlockResponseGenerator {
|
|
7
7
|
private readonly config;
|
|
8
8
|
private readonly captchaResponseGenerator;
|
|
@@ -6,7 +6,7 @@ var http_1 = require("../http");
|
|
|
6
6
|
var BlockAction_1 = require("./BlockAction");
|
|
7
7
|
var CaptchaBlockResponseGenerator_1 = require("./captcha/CaptchaBlockResponseGenerator");
|
|
8
8
|
var rate_limit_template_1 = require("./templates/rate_limit_template");
|
|
9
|
-
var
|
|
9
|
+
var PXHDSource_1 = require("../pxhd/model/PXHDSource");
|
|
10
10
|
var DefaultBlockResponseGenerator = /** @class */ (function () {
|
|
11
11
|
function DefaultBlockResponseGenerator(config, base64Utils) {
|
|
12
12
|
this.config = config;
|
|
@@ -16,6 +16,7 @@ var DefaultBlockResponseGenerator = /** @class */ (function () {
|
|
|
16
16
|
return !context.isMonitoredRequest && !!context.blockReason;
|
|
17
17
|
};
|
|
18
18
|
DefaultBlockResponseGenerator.prototype.generateBlockResponse = function (context) {
|
|
19
|
+
var _a;
|
|
19
20
|
var res;
|
|
20
21
|
switch (context.blockAction) {
|
|
21
22
|
case BlockAction_1.BlockAction.RATE_LIMIT:
|
|
@@ -27,7 +28,12 @@ var DefaultBlockResponseGenerator = /** @class */ (function () {
|
|
|
27
28
|
res = this.generateCaptchaResponse(context);
|
|
28
29
|
break;
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
if (((_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.source) == PXHDSource_1.PXHDSource.RISK) {
|
|
32
|
+
return pxhd_1.PXHDUtils.addPxhdToMinimalResponse(context, res);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return res;
|
|
36
|
+
}
|
|
31
37
|
};
|
|
32
38
|
DefaultBlockResponseGenerator.prototype.generateRateLimitResponse = function () {
|
|
33
39
|
var _a;
|
|
@@ -35,7 +41,7 @@ var DefaultBlockResponseGenerator = /** @class */ (function () {
|
|
|
35
41
|
var headers = (_a = {},
|
|
36
42
|
_a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.TEXT_HTML],
|
|
37
43
|
_a);
|
|
38
|
-
return new
|
|
44
|
+
return new http_1.MinimalResponseImpl({
|
|
39
45
|
body: rate_limit_template_1.RATE_LIMIT_TEMPLATE,
|
|
40
46
|
status: status,
|
|
41
47
|
headers: headers,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CustomParametersFunction } from '../custom_parameters';
|
|
2
2
|
import { AdditionalActivityHandler } from '../additional_activity_handler';
|
|
3
|
+
import { CustomPreflightHandler, CustomBlockResponseHeadersHandler } from '../cors';
|
|
3
4
|
export declare type ConfigurationParams = {
|
|
4
5
|
px_app_id: string;
|
|
5
6
|
px_auth_token: string;
|
|
@@ -62,8 +63,12 @@ export declare type ConfigurationParams = {
|
|
|
62
63
|
px_graphql_routes?: string[];
|
|
63
64
|
px_sensitive_graphql_operation_names?: string[];
|
|
64
65
|
px_sensitive_graphql_operation_types?: Array<'query' | 'mutation' | 'subscription'>;
|
|
66
|
+
px_cors_support_enabled?: boolean;
|
|
67
|
+
px_cors_preflight_request_filter_enabled?: boolean;
|
|
65
68
|
px_extract_ip?: () => {};
|
|
66
69
|
px_additional_activity_handler?: AdditionalActivityHandler;
|
|
67
70
|
px_enrich_custom_parameters?: CustomParametersFunction;
|
|
68
71
|
px_login_successful_custom_callback?: () => {};
|
|
72
|
+
px_cors_custom_preflight_handler?: CustomPreflightHandler;
|
|
73
|
+
px_cors_create_custom_block_response_headers?: CustomBlockResponseHeadersHandler;
|
|
69
74
|
};
|
|
@@ -108,4 +108,8 @@ exports.DEFAULT_CONFIGURATIONS = {
|
|
|
108
108
|
px_jwt_header_name: '',
|
|
109
109
|
px_jwt_header_user_id_field_name: '',
|
|
110
110
|
px_jwt_header_additional_field_names: [],
|
|
111
|
+
px_cors_support_enabled: false,
|
|
112
|
+
px_cors_custom_preflight_handler: null,
|
|
113
|
+
px_cors_preflight_request_filter_enabled: false,
|
|
114
|
+
px_cors_create_custom_block_response_headers: null,
|
|
111
115
|
};
|
|
@@ -3,6 +3,7 @@ import { ILogger, LoggerSeverity } from '../logger';
|
|
|
3
3
|
import { CustomParametersFunction } from '../custom_parameters';
|
|
4
4
|
import { AdditionalActivityHandler } from '../additional_activity_handler';
|
|
5
5
|
import { ConfigurationParams } from './ConfigurationParams';
|
|
6
|
+
import { CustomPreflightHandler, CustomBlockResponseHeadersHandler } from '../cors';
|
|
6
7
|
export interface IConfiguration<ParamsType extends ConfigurationParams = ConfigurationParams> {
|
|
7
8
|
/**
|
|
8
9
|
* The application ID.
|
|
@@ -195,4 +196,20 @@ export interface IConfiguration<ParamsType extends ConfigurationParams = Configu
|
|
|
195
196
|
* Returns an object representation of the current configuration.
|
|
196
197
|
*/
|
|
197
198
|
toParams(): ParamsType;
|
|
199
|
+
/**
|
|
200
|
+
* Whether cors support feature should be enabled.
|
|
201
|
+
*/
|
|
202
|
+
readonly corsSupportEnabled: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Function that will be called for preflight requests and returns response that will be returned to the client.
|
|
205
|
+
*/
|
|
206
|
+
readonly corsCustomPreflightHandler: CustomPreflightHandler;
|
|
207
|
+
/**
|
|
208
|
+
* Function that returns an object with custom headers to be added to the block response.
|
|
209
|
+
*/
|
|
210
|
+
readonly corsCreateCustomBlockResponseHeaders: CustomBlockResponseHeadersHandler;
|
|
211
|
+
/**
|
|
212
|
+
* Whether preflight requests will be filtered out from the enforcer.
|
|
213
|
+
*/
|
|
214
|
+
readonly corsPreflightRequestFilterEnabled: boolean;
|
|
198
215
|
}
|
|
@@ -4,6 +4,7 @@ import { CustomParametersFunction } from '../custom_parameters';
|
|
|
4
4
|
import { AdditionalActivityHandler } from '../additional_activity_handler';
|
|
5
5
|
import { ILogger, LoggerSeverity } from '../logger';
|
|
6
6
|
import { ModuleMode } from '../utils';
|
|
7
|
+
import { CustomBlockResponseHeadersHandler, CustomPreflightHandler } from '../cors';
|
|
7
8
|
export declare abstract class StaticConfigurationBase<ParamsType extends ConfigurationParams = ConfigurationParams> implements IConfiguration<ParamsType> {
|
|
8
9
|
protected readonly configParams: ParamsType;
|
|
9
10
|
protected internalLogger: ILogger;
|
|
@@ -60,4 +61,8 @@ export declare abstract class StaticConfigurationBase<ParamsType extends Configu
|
|
|
60
61
|
get enrichCustomParameters(): CustomParametersFunction;
|
|
61
62
|
get additionalActivityHandler(): AdditionalActivityHandler;
|
|
62
63
|
get altBackendCaptchaUrl(): string;
|
|
64
|
+
get corsSupportEnabled(): boolean;
|
|
65
|
+
get corsCustomPreflightHandler(): CustomPreflightHandler;
|
|
66
|
+
get corsPreflightRequestFilterEnabled(): boolean;
|
|
67
|
+
get corsCreateCustomBlockResponseHeaders(): CustomBlockResponseHeadersHandler;
|
|
63
68
|
}
|
|
@@ -392,6 +392,34 @@ var StaticConfigurationBase = /** @class */ (function () {
|
|
|
392
392
|
enumerable: false,
|
|
393
393
|
configurable: true
|
|
394
394
|
});
|
|
395
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "corsSupportEnabled", {
|
|
396
|
+
get: function () {
|
|
397
|
+
return this.configParams.px_cors_support_enabled;
|
|
398
|
+
},
|
|
399
|
+
enumerable: false,
|
|
400
|
+
configurable: true
|
|
401
|
+
});
|
|
402
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "corsCustomPreflightHandler", {
|
|
403
|
+
get: function () {
|
|
404
|
+
return this.configParams.px_cors_custom_preflight_handler || null;
|
|
405
|
+
},
|
|
406
|
+
enumerable: false,
|
|
407
|
+
configurable: true
|
|
408
|
+
});
|
|
409
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "corsPreflightRequestFilterEnabled", {
|
|
410
|
+
get: function () {
|
|
411
|
+
return this.configParams.px_cors_preflight_request_filter_enabled;
|
|
412
|
+
},
|
|
413
|
+
enumerable: false,
|
|
414
|
+
configurable: true
|
|
415
|
+
});
|
|
416
|
+
Object.defineProperty(StaticConfigurationBase.prototype, "corsCreateCustomBlockResponseHeaders", {
|
|
417
|
+
get: function () {
|
|
418
|
+
return this.configParams.px_cors_create_custom_block_response_headers || null;
|
|
419
|
+
},
|
|
420
|
+
enumerable: false,
|
|
421
|
+
configurable: true
|
|
422
|
+
});
|
|
395
423
|
return StaticConfigurationBase;
|
|
396
424
|
}());
|
|
397
425
|
exports.StaticConfigurationBase = StaticConfigurationBase;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { IConfiguration } from '../config';
|
|
2
|
-
import {
|
|
2
|
+
import { BlockAction, BlockReason } from '../block_handler';
|
|
3
3
|
import { CustomParameters } from '../custom_parameters';
|
|
4
4
|
import { FilterReason } from '../filter';
|
|
5
5
|
import { PXDE } from '../pxde';
|
|
6
6
|
import { GraphQLData } from '../graphql';
|
|
7
7
|
import { IBotDefenderToken, TokenOrigin } from '../risk_token';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { IIncomingRequest, ReadOnlyHeaders } from '../http';
|
|
9
|
+
import { ICookieParser, IUuidGenerator, PassReason, VidSource } from '../utils';
|
|
10
10
|
import { IContext, MobileData, RequestData, ResponseData, RiskApiData, ServerData, TlsData } from './IContext';
|
|
11
|
+
import { PXHD } from '../pxhd/model/PXHD';
|
|
11
12
|
export declare type ContextBaseOptions = {
|
|
12
13
|
cookieParser?: ICookieParser;
|
|
13
14
|
uuidGenerator?: IUuidGenerator;
|
|
@@ -32,7 +33,7 @@ export declare abstract class ContextBase<OptionsType extends ContextBaseOptions
|
|
|
32
33
|
filterReason?: FilterReason;
|
|
33
34
|
tokenOrigin?: TokenOrigin;
|
|
34
35
|
riskToken?: IBotDefenderToken;
|
|
35
|
-
pxhd?:
|
|
36
|
+
pxhd?: PXHD;
|
|
36
37
|
pxde?: PXDE;
|
|
37
38
|
pxdeVerified?: boolean;
|
|
38
39
|
customParameters?: CustomParameters;
|
|
@@ -5,6 +5,7 @@ var block_handler_1 = require("../block_handler");
|
|
|
5
5
|
var risk_token_1 = require("../risk_token");
|
|
6
6
|
var http_1 = require("../http");
|
|
7
7
|
var utils_1 = require("../utils");
|
|
8
|
+
var PXHDSource_1 = require("../pxhd/model/PXHDSource");
|
|
8
9
|
var ContextBase = /** @class */ (function () {
|
|
9
10
|
function ContextBase(config, request, options) {
|
|
10
11
|
this.config = config;
|
|
@@ -107,7 +108,14 @@ var ContextBase = /** @class */ (function () {
|
|
|
107
108
|
};
|
|
108
109
|
ContextBase.prototype.setCookiesOnContext = function () {
|
|
109
110
|
this.vid = this.requestData.cookies[utils_1.PXVID_COOKIE_NAME] || '';
|
|
110
|
-
|
|
111
|
+
var cookiePxhd = this.requestData.cookies[utils_1.PXHD_COOKIE_NAME];
|
|
112
|
+
if (cookiePxhd) {
|
|
113
|
+
this.pxhd = {
|
|
114
|
+
value: cookiePxhd,
|
|
115
|
+
domain: null,
|
|
116
|
+
source: PXHDSource_1.PXHDSource.COOKIE,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
111
119
|
};
|
|
112
120
|
ContextBase.prototype.getMobileToken = function (config, mobileToken, options) {
|
|
113
121
|
var _a;
|
|
@@ -8,7 +8,8 @@ import { PXDE } from '../pxde';
|
|
|
8
8
|
import { GraphQLData } from '../graphql';
|
|
9
9
|
import { HttpMethod } from '../http';
|
|
10
10
|
import { ReadOnlyHeaders } from '../http';
|
|
11
|
-
import { IIncomingRequest } from '../http
|
|
11
|
+
import { IIncomingRequest } from '../http';
|
|
12
|
+
import { PXHD } from '../pxhd/model/PXHD';
|
|
12
13
|
export declare type RequestData = {
|
|
13
14
|
/**
|
|
14
15
|
* The request URL.
|
|
@@ -239,7 +240,7 @@ export interface IContext {
|
|
|
239
240
|
/**
|
|
240
241
|
* The PXHD (PerimeterX Hashed Data) cookie value, if it exists on the request.
|
|
241
242
|
*/
|
|
242
|
-
pxhd?:
|
|
243
|
+
pxhd?: PXHD;
|
|
243
244
|
/**
|
|
244
245
|
* The PXDE (PerimeterX Data Enrichment) object, if it was parsed from
|
|
245
246
|
* the PXDE cookie or received on the risk response.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ICors } from './ICors';
|
|
2
|
+
import { IConfiguration } from '../config';
|
|
3
|
+
import { IContext } from '../context';
|
|
4
|
+
import { ReadOnlyHeaders, IMinimalResponse } from '../http';
|
|
5
|
+
export declare class DefaultCors implements ICors {
|
|
6
|
+
private readonly customBlockResponseHeaders;
|
|
7
|
+
private readonly customPreflightHandler;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(config: IConfiguration);
|
|
10
|
+
isPreflightRequest(context: IContext): boolean;
|
|
11
|
+
runPreflightCustomHandler(context: IContext): Promise<IMinimalResponse>;
|
|
12
|
+
isCorsRequest(context: IContext): boolean;
|
|
13
|
+
getCorsBlockHeaders(context: IContext): Promise<ReadOnlyHeaders>;
|
|
14
|
+
getDefaultCorsHeaders(context: IContext): ReadOnlyHeaders;
|
|
15
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.DefaultCors = void 0;
|
|
40
|
+
var constants_1 = require("./constants");
|
|
41
|
+
var http_1 = require("../http");
|
|
42
|
+
var DefaultCors = /** @class */ (function () {
|
|
43
|
+
function DefaultCors(config) {
|
|
44
|
+
this.customBlockResponseHeaders = config.corsCreateCustomBlockResponseHeaders;
|
|
45
|
+
this.customPreflightHandler = config.corsCustomPreflightHandler;
|
|
46
|
+
this.logger = config.logger;
|
|
47
|
+
}
|
|
48
|
+
DefaultCors.prototype.isPreflightRequest = function (context) {
|
|
49
|
+
var requestData = context.requestData;
|
|
50
|
+
return !!(requestData.method.toUpperCase() === http_1.HttpMethod.OPTIONS &&
|
|
51
|
+
requestData.headers[constants_1.ORIGIN_HEADER] &&
|
|
52
|
+
requestData.headers[constants_1.ACCESS_CONTROL_REQUEST_METHOD_HEADER]);
|
|
53
|
+
};
|
|
54
|
+
DefaultCors.prototype.runPreflightCustomHandler = function (context) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
+
var e_1;
|
|
57
|
+
return __generator(this, function (_a) {
|
|
58
|
+
switch (_a.label) {
|
|
59
|
+
case 0:
|
|
60
|
+
if (!(this.customPreflightHandler && typeof this.customPreflightHandler === 'function')) return [3 /*break*/, 4];
|
|
61
|
+
_a.label = 1;
|
|
62
|
+
case 1:
|
|
63
|
+
_a.trys.push([1, 3, , 4]);
|
|
64
|
+
return [4 /*yield*/, this.customPreflightHandler(context.requestData.request)];
|
|
65
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
66
|
+
case 3:
|
|
67
|
+
e_1 = _a.sent();
|
|
68
|
+
this.logger.debug("Exception occurred while executing custom preflight handler: ".concat(e_1));
|
|
69
|
+
return [3 /*break*/, 4];
|
|
70
|
+
case 4: return [2 /*return*/, null];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
DefaultCors.prototype.isCorsRequest = function (context) {
|
|
76
|
+
return !!context.requestData.headers[constants_1.ORIGIN_HEADER];
|
|
77
|
+
};
|
|
78
|
+
DefaultCors.prototype.getCorsBlockHeaders = function (context) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
var e_2;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
if (!(this.customBlockResponseHeaders && typeof this.customBlockResponseHeaders === 'function')) return [3 /*break*/, 4];
|
|
85
|
+
_a.label = 1;
|
|
86
|
+
case 1:
|
|
87
|
+
_a.trys.push([1, 3, , 4]);
|
|
88
|
+
return [4 /*yield*/, this.customBlockResponseHeaders(context.requestData.request)];
|
|
89
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
90
|
+
case 3:
|
|
91
|
+
e_2 = _a.sent();
|
|
92
|
+
this.logger.debug("Exception occurred in px_cors_create_custom_block_response_headers custom function: ".concat(e_2));
|
|
93
|
+
return [3 /*break*/, 4];
|
|
94
|
+
case 4: return [2 /*return*/, this.getDefaultCorsHeaders(context)];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
DefaultCors.prototype.getDefaultCorsHeaders = function (context) {
|
|
100
|
+
return {
|
|
101
|
+
'Access-Control-Allow-Origin': context.requestData.headers[constants_1.ORIGIN_HEADER],
|
|
102
|
+
'Access-Control-Allow-Credentials': ['true'],
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
return DefaultCors;
|
|
106
|
+
}());
|
|
107
|
+
exports.DefaultCors = DefaultCors;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IContext } from '../context';
|
|
2
|
+
import { IMinimalResponse } from '../http';
|
|
3
|
+
import { ReadOnlyHeaders } from '../http';
|
|
4
|
+
export interface ICors {
|
|
5
|
+
/**
|
|
6
|
+
* @param context
|
|
7
|
+
* @returns boolean - Whether the request is preflight.
|
|
8
|
+
*/
|
|
9
|
+
isPreflightRequest(context: IContext): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* @param context- The request context.
|
|
12
|
+
* @returns IMinimalResponse- The response that return to client for preflight request.
|
|
13
|
+
*/
|
|
14
|
+
runPreflightCustomHandler(context: IContext): Promise<IMinimalResponse> | null;
|
|
15
|
+
/**
|
|
16
|
+
* @param context- The request context.
|
|
17
|
+
* @returns boolean - Whether the request is CORS.
|
|
18
|
+
*/
|
|
19
|
+
isCorsRequest(context: IContext): boolean;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param context - The request context.
|
|
23
|
+
* @returns ReadOnlyHeaders - headers to be added to the block response.
|
|
24
|
+
*/
|
|
25
|
+
getCorsBlockHeaders(context: IContext): Promise<ReadOnlyHeaders>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACCESS_CONTROL_REQUEST_METHOD_HEADER = exports.ORIGIN_HEADER = void 0;
|
|
4
|
+
exports.ORIGIN_HEADER = 'origin';
|
|
5
|
+
exports.ACCESS_CONTROL_REQUEST_METHOD_HEADER = 'access-control-request-method';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DefaultCors = void 0;
|
|
18
|
+
var DefaultCors_1 = require("./DefaultCors");
|
|
19
|
+
Object.defineProperty(exports, "DefaultCors", { enumerable: true, get: function () { return DefaultCors_1.DefaultCors; } });
|
|
20
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -10,7 +10,8 @@ import { IBlockResponseGenerator } from '../block_handler';
|
|
|
10
10
|
import { TokenVersion } from '../risk_token';
|
|
11
11
|
import { IActivityClient } from '../activities';
|
|
12
12
|
import { IGraphQLParser } from '../graphql';
|
|
13
|
-
import {
|
|
13
|
+
import { ICors } from '../cors';
|
|
14
|
+
import { IHttpClient, IMinimalResponse, IOutgoingResponse } from '../http';
|
|
14
15
|
export declare type EnforcerBaseOptions = {
|
|
15
16
|
tokenVersion?: TokenVersion;
|
|
16
17
|
dataEnrichment?: IDataEnrichment;
|
|
@@ -22,6 +23,7 @@ export declare type EnforcerBaseOptions = {
|
|
|
22
23
|
cipherUtils?: ICipherUtils;
|
|
23
24
|
blockGenerator?: IBlockResponseGenerator;
|
|
24
25
|
graphqlParser?: IGraphQLParser;
|
|
26
|
+
cors?: ICors;
|
|
25
27
|
} & ({
|
|
26
28
|
httpClient: IHttpClient;
|
|
27
29
|
firstParty?: IFirstParty;
|
|
@@ -46,6 +48,7 @@ export declare abstract class EnforcerBase<EnforceArgs extends any[], Req, Res>
|
|
|
46
48
|
protected blockGenerator: IBlockResponseGenerator;
|
|
47
49
|
protected activityClient: IActivityClient;
|
|
48
50
|
protected graphQLParser?: IGraphQLParser;
|
|
51
|
+
protected cors?: ICors;
|
|
49
52
|
/**
|
|
50
53
|
* Returns the original Req object in case the module is disabled or an error is thrown.
|
|
51
54
|
* @param args - The EnforceArgs required to enforce the incoming request.
|
|
@@ -59,6 +59,9 @@ var risk_api_1 = require("../risk_api");
|
|
|
59
59
|
var activities_1 = require("../activities");
|
|
60
60
|
var graphql_1 = require("../graphql");
|
|
61
61
|
var custom_parameters_1 = require("../custom_parameters");
|
|
62
|
+
var cors_1 = require("../cors");
|
|
63
|
+
var MinimalResponseUtils_1 = require("../http/utils/MinimalResponseUtils");
|
|
64
|
+
var PXHDSource_1 = require("../pxhd/model/PXHDSource");
|
|
62
65
|
var EnforcerBase = /** @class */ (function () {
|
|
63
66
|
/**
|
|
64
67
|
* The EnforcerBase constructor.
|
|
@@ -90,6 +93,7 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
90
93
|
: new risk_api_1.RiskResponseV3Handler(this.config);
|
|
91
94
|
this.riskApiScoreRetriever =
|
|
92
95
|
options.riskApiScoreRetriever || new risk_api_1.PostRiskApiClient(this.config, httpClient, riskResponseHandler);
|
|
96
|
+
this.cors = this.config.corsSupportEnabled ? options.cors || new cors_1.DefaultCors(this.config) : null;
|
|
93
97
|
}
|
|
94
98
|
/**
|
|
95
99
|
* The central function that triggers enforcement on the incoming request.
|
|
@@ -130,20 +134,21 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
130
134
|
* @protected
|
|
131
135
|
*/
|
|
132
136
|
EnforcerBase.prototype.doEnforce = function () {
|
|
137
|
+
var _a;
|
|
133
138
|
var args = [];
|
|
134
139
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
135
140
|
args[_i] = arguments[_i];
|
|
136
141
|
}
|
|
137
142
|
return __awaiter(this, void 0, void 0, function () {
|
|
138
|
-
var context, httpResponse;
|
|
139
|
-
return __generator(this, function (
|
|
140
|
-
switch (
|
|
143
|
+
var context, httpResponse, response;
|
|
144
|
+
return __generator(this, function (_b) {
|
|
145
|
+
switch (_b.label) {
|
|
141
146
|
case 0: return [4 /*yield*/, this.createContext.apply(this, args)];
|
|
142
147
|
case 1:
|
|
143
|
-
context =
|
|
148
|
+
context = _b.sent();
|
|
144
149
|
return [4 /*yield*/, this.handleFirstParty(context)];
|
|
145
150
|
case 2:
|
|
146
|
-
httpResponse =
|
|
151
|
+
httpResponse = _b.sent();
|
|
147
152
|
if (httpResponse) {
|
|
148
153
|
this.config.logger.debug('returning first party response');
|
|
149
154
|
return [2 /*return*/, this.convertToRes(httpResponse)];
|
|
@@ -152,34 +157,47 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
152
157
|
this.config.logger.debug("filtering due to ".concat(context.filterReason));
|
|
153
158
|
return [2 /*return*/, null];
|
|
154
159
|
}
|
|
155
|
-
|
|
160
|
+
if (!((_a = this.cors) === null || _a === void 0 ? void 0 : _a.isPreflightRequest(context))) return [3 /*break*/, 4];
|
|
161
|
+
this.config.logger.debug("Preflight request");
|
|
162
|
+
return [4 /*yield*/, this.cors.runPreflightCustomHandler(context)];
|
|
156
163
|
case 3:
|
|
157
|
-
|
|
164
|
+
response = _b.sent();
|
|
165
|
+
if (response) {
|
|
166
|
+
return [2 /*return*/, this.convertToRes(response)];
|
|
167
|
+
}
|
|
168
|
+
if (this.config.corsPreflightRequestFilterEnabled) {
|
|
169
|
+
this.config.logger.debug("Skipping verification due to preflight request");
|
|
170
|
+
return [2 /*return*/, null];
|
|
171
|
+
}
|
|
172
|
+
_b.label = 4;
|
|
173
|
+
case 4: return [4 /*yield*/, this.handleCompleteContextInitialization(context)];
|
|
174
|
+
case 5:
|
|
175
|
+
_b.sent();
|
|
158
176
|
this.config.logger.debug('context initialization complete');
|
|
159
177
|
return [4 /*yield*/, this.handleGraphQL(context)];
|
|
160
|
-
case
|
|
161
|
-
|
|
178
|
+
case 6:
|
|
179
|
+
_b.sent();
|
|
162
180
|
return [4 /*yield*/, this.handleEnrichCustomParameters(context)];
|
|
163
|
-
case
|
|
164
|
-
|
|
181
|
+
case 7:
|
|
182
|
+
_b.sent();
|
|
165
183
|
return [4 /*yield*/, this.handleTelemetryIfNeeded(context)];
|
|
166
|
-
case
|
|
167
|
-
|
|
184
|
+
case 8:
|
|
185
|
+
_b.sent();
|
|
168
186
|
return [4 /*yield*/, this.handlePxde(context)];
|
|
169
|
-
case
|
|
170
|
-
|
|
187
|
+
case 9:
|
|
188
|
+
_b.sent();
|
|
171
189
|
return [4 /*yield*/, this.handleCookieRetrieverIfNeeded(context)];
|
|
172
|
-
case
|
|
173
|
-
|
|
190
|
+
case 10:
|
|
191
|
+
_b.sent();
|
|
174
192
|
return [4 /*yield*/, this.handleRiskApiIfNeeded(context)];
|
|
175
|
-
case
|
|
176
|
-
|
|
193
|
+
case 11:
|
|
194
|
+
_b.sent();
|
|
177
195
|
return [4 /*yield*/, this.handleAdditionalActivityHandler(context)];
|
|
178
|
-
case
|
|
179
|
-
|
|
196
|
+
case 12:
|
|
197
|
+
_b.sent();
|
|
180
198
|
return [4 /*yield*/, this.handleBlockResponse(context)];
|
|
181
|
-
case
|
|
182
|
-
httpResponse =
|
|
199
|
+
case 13:
|
|
200
|
+
httpResponse = _b.sent();
|
|
183
201
|
if (httpResponse) {
|
|
184
202
|
this.config.logger.debug("blocking request due to ".concat(context.blockReason));
|
|
185
203
|
return [2 /*return*/, this.convertToRes(httpResponse)];
|
|
@@ -322,16 +340,28 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
322
340
|
});
|
|
323
341
|
};
|
|
324
342
|
EnforcerBase.prototype.handleBlockResponse = function (context) {
|
|
343
|
+
var _a;
|
|
325
344
|
return __awaiter(this, void 0, void 0, function () {
|
|
326
|
-
|
|
327
|
-
|
|
345
|
+
var res, corsBlockResponseHeaders;
|
|
346
|
+
return __generator(this, function (_b) {
|
|
347
|
+
switch (_b.label) {
|
|
328
348
|
case 0:
|
|
329
|
-
if (!this.blockGenerator.shouldGenerate(context)) return [3 /*break*/,
|
|
349
|
+
if (!this.blockGenerator.shouldGenerate(context)) return [3 /*break*/, 4];
|
|
330
350
|
return [4 /*yield*/, this.handleSendActivities(context)];
|
|
331
351
|
case 1:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
352
|
+
_b.sent();
|
|
353
|
+
res = this.blockGenerator.generateBlockResponse(context);
|
|
354
|
+
if (!((_a = this.cors) === null || _a === void 0 ? void 0 : _a.isCorsRequest(context))) return [3 /*break*/, 3];
|
|
355
|
+
this.config.logger.debug("Adding CORS headers to block response");
|
|
356
|
+
return [4 /*yield*/, this.cors.getCorsBlockHeaders(context)];
|
|
357
|
+
case 2:
|
|
358
|
+
corsBlockResponseHeaders = _b.sent();
|
|
359
|
+
if (corsBlockResponseHeaders) {
|
|
360
|
+
res = (0, MinimalResponseUtils_1.appendHeaders)(res, corsBlockResponseHeaders);
|
|
361
|
+
}
|
|
362
|
+
_b.label = 3;
|
|
363
|
+
case 3: return [2 /*return*/, res];
|
|
364
|
+
case 4: return [2 /*return*/, null];
|
|
335
365
|
}
|
|
336
366
|
});
|
|
337
367
|
});
|
|
@@ -404,9 +434,13 @@ var EnforcerBase = /** @class */ (function () {
|
|
|
404
434
|
});
|
|
405
435
|
};
|
|
406
436
|
EnforcerBase.prototype.handlePxhd = function (context, response) {
|
|
437
|
+
var _a;
|
|
407
438
|
return __awaiter(this, void 0, void 0, function () {
|
|
408
|
-
return __generator(this, function (
|
|
409
|
-
|
|
439
|
+
return __generator(this, function (_b) {
|
|
440
|
+
if (((_a = context.pxhd) === null || _a === void 0 ? void 0 : _a.source) === PXHDSource_1.PXHDSource.RISK) {
|
|
441
|
+
pxhd_1.PXHDUtils.addPxhdToOutgoingResponse(context, response);
|
|
442
|
+
}
|
|
443
|
+
return [2 /*return*/];
|
|
410
444
|
});
|
|
411
445
|
});
|
|
412
446
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { IContext } from '../context
|
|
1
|
+
import { IContext } from '../context';
|
|
2
2
|
import { IConfiguration } from '../config';
|
|
3
3
|
import { IGraphQLParser } from './IGraphQLParser';
|
|
4
4
|
export declare class DefaultGraphQLParser implements IGraphQLParser {
|
|
5
|
-
private readonly
|
|
5
|
+
private readonly config;
|
|
6
6
|
private readonly graphqlRoutes;
|
|
7
7
|
private readonly sensitiveOperationTypes;
|
|
8
8
|
private readonly sensitiveOperationNames;
|
|
@@ -42,7 +42,7 @@ var utils_1 = require("../utils");
|
|
|
42
42
|
var http_1 = require("../http");
|
|
43
43
|
var DefaultGraphQLParser = /** @class */ (function () {
|
|
44
44
|
function DefaultGraphQLParser(config) {
|
|
45
|
-
this.
|
|
45
|
+
this.config = config;
|
|
46
46
|
this.graphqlRoutes = config.graphqlRoutes;
|
|
47
47
|
this.sensitiveOperationNames = config.sensitiveGraphqlOperationNames;
|
|
48
48
|
this.sensitiveOperationTypes = config.sensitiveGraphqlOperationTypes;
|
|
@@ -62,21 +62,21 @@ var DefaultGraphQLParser = /** @class */ (function () {
|
|
|
62
62
|
case 1:
|
|
63
63
|
graphQLOperations = _a.sent();
|
|
64
64
|
if (!graphQLOperations) {
|
|
65
|
-
this.logger.debug('unable to get graphql operations from request body');
|
|
65
|
+
this.config.logger.debug('unable to get graphql operations from request body');
|
|
66
66
|
return [2 /*return*/, false];
|
|
67
67
|
}
|
|
68
68
|
data = this.parseGraphQLOperations(graphQLOperations);
|
|
69
69
|
if (!data || data.length === 0) {
|
|
70
|
-
this.logger.debug('unable to parse graphql operations');
|
|
70
|
+
this.config.logger.debug('unable to parse graphql operations');
|
|
71
71
|
return [2 /*return*/, false];
|
|
72
72
|
}
|
|
73
|
-
this.logger.debug("".concat(data.length, " graphql operation").concat(data.length === 1 ? '' : 's', " parsed successfully"));
|
|
73
|
+
this.config.logger.debug("".concat(data.length, " graphql operation").concat(data.length === 1 ? '' : 's', " parsed successfully"));
|
|
74
74
|
context.graphqlData = data;
|
|
75
75
|
context.isSensitiveRequest = context.isSensitiveRequest || data.some(function (operation) { return operation.sensitive; });
|
|
76
76
|
return [2 /*return*/, true];
|
|
77
77
|
case 2:
|
|
78
78
|
e_1 = _a.sent();
|
|
79
|
-
this.logger.debug("
|
|
79
|
+
this.config.logger.debug("unable to parse graphql request: ".concat(e_1));
|
|
80
80
|
return [2 /*return*/, false];
|
|
81
81
|
case 3: return [2 /*return*/];
|
|
82
82
|
}
|
|
@@ -86,20 +86,23 @@ var DefaultGraphQLParser = /** @class */ (function () {
|
|
|
86
86
|
DefaultGraphQLParser.prototype.getGraphQLOperationsFromBody = function (_a) {
|
|
87
87
|
var request = _a.request;
|
|
88
88
|
return __awaiter(this, void 0, void 0, function () {
|
|
89
|
-
var body;
|
|
90
|
-
var _this = this;
|
|
89
|
+
var body, e_2;
|
|
91
90
|
return __generator(this, function (_b) {
|
|
92
91
|
switch (_b.label) {
|
|
93
|
-
case 0:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})];
|
|
92
|
+
case 0:
|
|
93
|
+
_b.trys.push([0, 2, , 3]);
|
|
94
|
+
return [4 /*yield*/, request.json()];
|
|
97
95
|
case 1:
|
|
98
96
|
body = _b.sent();
|
|
99
97
|
if (!body) {
|
|
100
98
|
return [2 /*return*/, null];
|
|
101
99
|
}
|
|
102
100
|
return [2 /*return*/, Array.isArray(body) ? body : [body]];
|
|
101
|
+
case 2:
|
|
102
|
+
e_2 = _b.sent();
|
|
103
|
+
this.config.logger.debug("unable to parse body to json: ".concat(e_2));
|
|
104
|
+
return [2 /*return*/, null];
|
|
105
|
+
case 3: return [2 /*return*/];
|
|
103
106
|
}
|
|
104
107
|
});
|
|
105
108
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface IHeaders {
|
|
2
|
+
append(name: string, value: string): void;
|
|
3
|
+
delete(name: string): void;
|
|
4
|
+
get(name: string): string | null;
|
|
5
|
+
has(name: string): boolean;
|
|
6
|
+
set(name: string, value: string): void;
|
|
7
|
+
forEach(callbackfn: (value: string, key: string, parent: IHeaders) => void, thisArg?: any): void;
|
|
8
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HttpMethod } from '../utils';
|
|
2
2
|
import { IBody } from './IBody';
|
|
3
|
+
import { IHeaders } from './IHeaders';
|
|
3
4
|
/**
|
|
4
5
|
* describes a request that comes from the end user.
|
|
5
6
|
*/
|
|
@@ -15,7 +16,7 @@ export interface IIncomingRequest extends IBody {
|
|
|
15
16
|
/**
|
|
16
17
|
* returns the request headers (for read usage).
|
|
17
18
|
*/
|
|
18
|
-
readonly headers:
|
|
19
|
+
readonly headers: IHeaders;
|
|
19
20
|
/**
|
|
20
21
|
* return the client ip or null.
|
|
21
22
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IHeaders } from './IHeaders';
|
|
1
2
|
/**
|
|
2
3
|
* Describes a response that is going to be returned to the end user.
|
|
3
4
|
*/
|
|
@@ -9,7 +10,7 @@ export interface IOutgoingResponse {
|
|
|
9
10
|
/**
|
|
10
11
|
* the response headers (for read usage)
|
|
11
12
|
*/
|
|
12
|
-
readonly headers:
|
|
13
|
+
readonly headers: IHeaders | null;
|
|
13
14
|
/**
|
|
14
15
|
* the response body.
|
|
15
16
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import { IHeaders } from './IHeaders';
|
|
1
2
|
export declare type ReadOnlyHeaders = Readonly<Record<string, string[]>>;
|
|
2
|
-
export declare const toReadOnlyHeaders: (headers:
|
|
3
|
-
export declare const fromReadOnlyHeaders: (headers?: ReadOnlyHeaders) => Headers;
|
|
3
|
+
export declare const toReadOnlyHeaders: (headers: IHeaders) => ReadOnlyHeaders;
|
|
4
4
|
export declare const joinHeaderValues: (headers: ReadOnlyHeaders) => Record<string, string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.joinHeaderValues = exports.
|
|
3
|
+
exports.joinHeaderValues = exports.toReadOnlyHeaders = void 0;
|
|
4
4
|
var toReadOnlyHeaders = function (headers) {
|
|
5
5
|
var readonlyHeaders = {};
|
|
6
6
|
headers.forEach(function (headerValue, headerName) {
|
|
@@ -10,19 +10,6 @@ var toReadOnlyHeaders = function (headers) {
|
|
|
10
10
|
return readonlyHeaders;
|
|
11
11
|
};
|
|
12
12
|
exports.toReadOnlyHeaders = toReadOnlyHeaders;
|
|
13
|
-
var fromReadOnlyHeaders = function (headers) {
|
|
14
|
-
if (!headers) {
|
|
15
|
-
return new Headers();
|
|
16
|
-
}
|
|
17
|
-
var init = Object.entries(headers)
|
|
18
|
-
.filter(function (e) { return (e === null || e === void 0 ? void 0 : e[0]) && (e === null || e === void 0 ? void 0 : e[1]); })
|
|
19
|
-
.flatMap(function (_a) {
|
|
20
|
-
var key = _a[0], values = _a[1];
|
|
21
|
-
return values.map(function (value) { return [key, value]; });
|
|
22
|
-
});
|
|
23
|
-
return new Headers(init);
|
|
24
|
-
};
|
|
25
|
-
exports.fromReadOnlyHeaders = fromReadOnlyHeaders;
|
|
26
13
|
var joinHeaderValues = function (headers) {
|
|
27
14
|
return Object.fromEntries(Object.entries(headers).map(function (_a) {
|
|
28
15
|
var name = _a[0], values = _a[1];
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { IMinimalResponse } from '..';
|
|
2
2
|
import { IIncomingResponse } from '..';
|
|
3
|
+
import { ReadOnlyHeaders } from '..';
|
|
3
4
|
export declare const appendHeader: (response: IMinimalResponse, name: string, value: string) => IMinimalResponse;
|
|
5
|
+
export declare const appendHeaders: (response: IMinimalResponse, headers: ReadOnlyHeaders) => IMinimalResponse;
|
|
4
6
|
export declare const from: (response: IIncomingResponse) => IMinimalResponse;
|
|
@@ -11,21 +11,31 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.from = exports.appendHeader = void 0;
|
|
14
|
+
exports.from = exports.appendHeaders = exports.appendHeader = void 0;
|
|
15
15
|
var __1 = require("..");
|
|
16
16
|
var appendHeader = function (response, name, value) {
|
|
17
|
+
var _a;
|
|
18
|
+
return (0, exports.appendHeaders)(response, (_a = {},
|
|
19
|
+
_a[name] = [value],
|
|
20
|
+
_a));
|
|
21
|
+
};
|
|
22
|
+
exports.appendHeader = appendHeader;
|
|
23
|
+
var appendHeaders = function (response, headers) {
|
|
17
24
|
var body = response.body;
|
|
18
25
|
var statusCode = response.status;
|
|
19
|
-
var
|
|
20
|
-
var newHeaders = __assign({},
|
|
21
|
-
|
|
26
|
+
var responseHeaders = response.headers;
|
|
27
|
+
var newHeaders = __assign({}, responseHeaders);
|
|
28
|
+
Object.entries(headers).forEach(function (_a) {
|
|
29
|
+
var name = _a[0], values = _a[1];
|
|
30
|
+
newHeaders[name] = (newHeaders[name] || []).concat(values);
|
|
31
|
+
});
|
|
22
32
|
return new __1.MinimalResponseImpl({
|
|
23
33
|
body: body,
|
|
24
34
|
headers: newHeaders,
|
|
25
35
|
status: statusCode,
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
|
-
exports.
|
|
38
|
+
exports.appendHeaders = appendHeaders;
|
|
29
39
|
var from = function (response) {
|
|
30
40
|
return new (/** @class */ (function () {
|
|
31
41
|
function class_1() {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./block_handler"), exports);
|
|
|
20
20
|
__exportStar(require("./config"), exports);
|
|
21
21
|
__exportStar(require("./context"), exports);
|
|
22
22
|
__exportStar(require("./custom_parameters"), exports);
|
|
23
|
+
__exportStar(require("./cors"), exports);
|
|
23
24
|
__exportStar(require("./enforcer"), exports);
|
|
24
25
|
__exportStar(require("./filter"), exports);
|
|
25
26
|
__exportStar(require("./first_party"), exports);
|
package/lib/pxhd/PXHDUtils.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { IContext } from '../context';
|
|
2
2
|
import { IOutgoingResponse, IMinimalResponse } from '../http';
|
|
3
|
+
import { PXHD } from './model';
|
|
3
4
|
export declare namespace PXHDUtils {
|
|
4
5
|
const PXHD_SAMESITE_VALUE = "Lax";
|
|
5
6
|
const PXHD_PATH_VALUE = "/";
|
|
6
7
|
const addPxhdToResponse: (context: IContext, httpResponse: IMinimalResponse) => IMinimalResponse;
|
|
7
8
|
const addPxhdToOutgoingResponse: (context: IContext, response: IOutgoingResponse) => void;
|
|
8
9
|
const addPxhdToMinimalResponse: (context: IContext, response: IMinimalResponse) => IMinimalResponse;
|
|
9
|
-
const getPxhdCookieValue: (
|
|
10
|
+
const getPxhdCookieValue: (pxhd: PXHD) => string;
|
|
10
11
|
}
|
package/lib/pxhd/PXHDUtils.js
CHANGED
|
@@ -29,7 +29,11 @@ var PXHDUtils;
|
|
|
29
29
|
}
|
|
30
30
|
return response;
|
|
31
31
|
};
|
|
32
|
-
PXHDUtils.getPxhdCookieValue = function (
|
|
33
|
-
|
|
32
|
+
PXHDUtils.getPxhdCookieValue = function (pxhd) {
|
|
33
|
+
var value = "".concat(utils_1.PXHD_COOKIE_NAME, "=").concat(pxhd.value);
|
|
34
|
+
var domain = pxhd.domain && "domain=".concat(pxhd.domain);
|
|
35
|
+
var path = "path=".concat(PXHDUtils.PXHD_PATH_VALUE);
|
|
36
|
+
var sameSite = "SameSite=".concat(PXHDUtils.PXHD_SAMESITE_VALUE);
|
|
37
|
+
return [value, domain, path, sameSite].filter(Boolean).join('; ');
|
|
34
38
|
};
|
|
35
39
|
})(PXHDUtils = exports.PXHDUtils || (exports.PXHDUtils = {}));
|
package/lib/pxhd/index.d.ts
CHANGED
package/lib/pxhd/index.js
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.PXHDUtils = void 0;
|
|
4
18
|
var PXHDUtils_1 = require("./PXHDUtils");
|
|
5
19
|
Object.defineProperty(exports, "PXHDUtils", { enumerable: true, get: function () { return PXHDUtils_1.PXHDUtils; } });
|
|
20
|
+
__exportStar(require("./model"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PXHDSource = void 0;
|
|
4
|
+
var PXHDSource;
|
|
5
|
+
(function (PXHDSource) {
|
|
6
|
+
PXHDSource["COOKIE"] = "cookie";
|
|
7
|
+
PXHDSource["RISK"] = "risk";
|
|
8
|
+
})(PXHDSource = exports.PXHDSource || (exports.PXHDSource = {}));
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./PXHD"), exports);
|
|
18
|
+
__exportStar(require("./PXHDSource"), exports);
|
|
@@ -162,11 +162,15 @@ var PostRiskApiClient = /** @class */ (function () {
|
|
|
162
162
|
this.addCustomParamsToAdditional(riskActivity, context);
|
|
163
163
|
};
|
|
164
164
|
PostRiskApiClient.prototype.addOptionalRiskFieldsToRoot = function (riskActivity, context) {
|
|
165
|
-
(
|
|
166
|
-
vid
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
165
|
+
if (context.vid) {
|
|
166
|
+
riskActivity.vid = context.vid;
|
|
167
|
+
}
|
|
168
|
+
if (context.uuid) {
|
|
169
|
+
riskActivity.uuid = context.uuid;
|
|
170
|
+
}
|
|
171
|
+
if (context.pxhd) {
|
|
172
|
+
riskActivity.pxhd = context.pxhd.value;
|
|
173
|
+
}
|
|
170
174
|
};
|
|
171
175
|
PostRiskApiClient.prototype.addOptionalRiskFieldsToAdditional = function (riskActivity, context) {
|
|
172
176
|
(0, utils_1.transferExistingProperties)(context, riskActivity.additional, {
|
|
@@ -16,9 +16,9 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.RiskResponseV2Handler = void 0;
|
|
19
|
-
var utils_1 = require("../../utils");
|
|
20
19
|
var RiskStatus_1 = require("../model/RiskStatus");
|
|
21
20
|
var RiskResponseHandlerBase_1 = require("./RiskResponseHandlerBase");
|
|
21
|
+
var PXHDSource_1 = require("../../pxhd/model/PXHDSource");
|
|
22
22
|
var RiskResponseV2Handler = /** @class */ (function (_super) {
|
|
23
23
|
__extends(RiskResponseV2Handler, _super);
|
|
24
24
|
function RiskResponseV2Handler(config) {
|
|
@@ -32,14 +32,22 @@ var RiskResponseV2Handler = /** @class */ (function (_super) {
|
|
|
32
32
|
};
|
|
33
33
|
RiskResponseV2Handler.prototype.setRiskResponseContextFields = function (context, riskResponse) {
|
|
34
34
|
context.score = this.extractScoreFromRiskResponse(riskResponse);
|
|
35
|
-
(
|
|
36
|
-
uuid
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
if (riskResponse.uuid) {
|
|
36
|
+
context.uuid = riskResponse.uuid;
|
|
37
|
+
}
|
|
38
|
+
if (riskResponse.pxhd) {
|
|
39
|
+
context.pxhd = {
|
|
40
|
+
value: riskResponse.pxhd,
|
|
41
|
+
domain: riskResponse.pxhdDomain,
|
|
42
|
+
source: PXHDSource_1.PXHDSource.RISK,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (riskResponse.action) {
|
|
46
|
+
context.blockAction = riskResponse.action;
|
|
47
|
+
}
|
|
41
48
|
if (riskResponse.data_enrichment) {
|
|
42
49
|
context.pxdeVerified = true;
|
|
50
|
+
context.pxde = riskResponse.data_enrichment;
|
|
43
51
|
}
|
|
44
52
|
};
|
|
45
53
|
return RiskResponseV2Handler;
|
|
@@ -16,9 +16,9 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.RiskResponseV3Handler = void 0;
|
|
19
|
-
var utils_1 = require("../../utils");
|
|
20
19
|
var RiskStatus_1 = require("../model/RiskStatus");
|
|
21
20
|
var RiskResponseHandlerBase_1 = require("./RiskResponseHandlerBase");
|
|
21
|
+
var PXHDSource_1 = require("../../pxhd/model/PXHDSource");
|
|
22
22
|
var RiskResponseV3Handler = /** @class */ (function (_super) {
|
|
23
23
|
__extends(RiskResponseV3Handler, _super);
|
|
24
24
|
function RiskResponseV3Handler(config) {
|
|
@@ -31,15 +31,25 @@ var RiskResponseV3Handler = /** @class */ (function (_super) {
|
|
|
31
31
|
return riskResponse.score;
|
|
32
32
|
};
|
|
33
33
|
RiskResponseV3Handler.prototype.setRiskResponseContextFields = function (context, riskResponse) {
|
|
34
|
-
(
|
|
35
|
-
score
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
if (typeof riskResponse.score === 'number') {
|
|
35
|
+
context.score = riskResponse.score;
|
|
36
|
+
}
|
|
37
|
+
if (riskResponse.uuid) {
|
|
38
|
+
context.uuid = riskResponse.uuid;
|
|
39
|
+
}
|
|
40
|
+
if (riskResponse.action) {
|
|
41
|
+
context.blockAction = riskResponse.action;
|
|
42
|
+
}
|
|
43
|
+
if (riskResponse.pxhd) {
|
|
44
|
+
context.pxhd = {
|
|
45
|
+
value: riskResponse.pxhd,
|
|
46
|
+
domain: riskResponse.pxhdDomain,
|
|
47
|
+
source: PXHDSource_1.PXHDSource.RISK,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
41
50
|
if (riskResponse.data_enrichment) {
|
|
42
51
|
context.pxdeVerified = true;
|
|
52
|
+
context.pxde = riskResponse.data_enrichment;
|
|
43
53
|
}
|
|
44
54
|
};
|
|
45
55
|
return RiskResponseV3Handler;
|
package/lib/utils/constants.d.ts
CHANGED
|
@@ -7,4 +7,4 @@ export declare const BYPASS_MONITOR_HEADER_VALUE = "1";
|
|
|
7
7
|
export declare const X_PX_AUTHORIZATION_HEADER_NAME = "x-px-authorization";
|
|
8
8
|
export declare const X_PX_ORIGINAL_TOKEN_HEADER_NAME = "x-px-original-token";
|
|
9
9
|
export declare const X_PX_BYPASS_REASON_HEADER_NAME = "x-px-bypass-reason";
|
|
10
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.
|
|
10
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.5.1";
|
package/lib/utils/constants.js
CHANGED
|
@@ -10,4 +10,4 @@ exports.BYPASS_MONITOR_HEADER_VALUE = '1';
|
|
|
10
10
|
exports.X_PX_AUTHORIZATION_HEADER_NAME = 'x-px-authorization';
|
|
11
11
|
exports.X_PX_ORIGINAL_TOKEN_HEADER_NAME = 'x-px-original-token';
|
|
12
12
|
exports.X_PX_BYPASS_REASON_HEADER_NAME = 'x-px-bypass-reason';
|
|
13
|
-
exports.CORE_MODULE_VERSION = 'JS Core 0.
|
|
13
|
+
exports.CORE_MODULE_VERSION = 'JS Core 0.5.1';
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -9,5 +9,8 @@ export declare const removeSensitiveFields: <T extends Record<string, any>>(obje
|
|
|
9
9
|
export declare const removeSensitiveHeaders: (headers: Record<string, string[]>, sensitiveHeaderNames: string[]) => Record<string, string[]>;
|
|
10
10
|
export declare const isRouteInPatterns: (route: string, patterns: Array<string | RegExp>) => boolean;
|
|
11
11
|
export declare const isRouteMatch: (route: string, pattern: string | RegExp) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated this method is not typesafe. Copy the fields manually instead.
|
|
14
|
+
*/
|
|
12
15
|
export declare const transferExistingProperties: <FromObj extends Record<string, any>, ToObj extends Record<string, any>>(fromObj: FromObj, toObj: ToObj, propertyMappings: Partial<Record<keyof FromObj, keyof ToObj>>) => void;
|
|
13
16
|
export declare const rejectOnTimeout: <T>(promise: Promise<T>, ms: number) => Promise<T>;
|
package/lib/utils/utils.js
CHANGED
|
@@ -124,6 +124,9 @@ var isRouteMatch = function (route, pattern) {
|
|
|
124
124
|
return false;
|
|
125
125
|
};
|
|
126
126
|
exports.isRouteMatch = isRouteMatch;
|
|
127
|
+
/**
|
|
128
|
+
* @deprecated this method is not typesafe. Copy the fields manually instead.
|
|
129
|
+
*/
|
|
127
130
|
var transferExistingProperties = function (fromObj, toObj, propertyMappings) {
|
|
128
131
|
if (!toObj || !fromObj) {
|
|
129
132
|
return;
|