perimeterx-js-core 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/config/ConfigurationBase.js +7 -0
- package/lib/cjs/config/defaults/DefaultConfigurationParams.js +1 -0
- package/lib/cjs/products/bot_defender/filter/DefaultBotDefenderFilter.js +8 -1
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/utils.js +19 -1
- package/lib/esm/config/ConfigurationBase.js +3 -0
- package/lib/esm/config/defaults/DefaultConfigurationParams.js +1 -0
- package/lib/esm/products/bot_defender/filter/DefaultBotDefenderFilter.js +8 -2
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/utils.js +17 -0
- package/lib/types/config/ConfigurationBase.d.ts +1 -0
- package/lib/types/config/IConfiguration.d.ts +4 -0
- package/lib/types/config/params/CoreConfigurationParams.d.ts +1 -0
- package/lib/types/products/bot_defender/filter/DefaultBotDefenderFilter.d.ts +1 -0
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/utils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -228,6 +228,13 @@ var ConfigurationBase = /** @class */ (function () {
|
|
|
228
228
|
enumerable: false,
|
|
229
229
|
configurable: true
|
|
230
230
|
});
|
|
231
|
+
Object.defineProperty(ConfigurationBase.prototype, "matrixParamsEnabled", {
|
|
232
|
+
get: function () {
|
|
233
|
+
return this.configParams.px_matrix_params_enabled;
|
|
234
|
+
},
|
|
235
|
+
enumerable: false,
|
|
236
|
+
configurable: true
|
|
237
|
+
});
|
|
231
238
|
Object.defineProperty(ConfigurationBase.prototype, "filteredHttpMethods", {
|
|
232
239
|
get: function () {
|
|
233
240
|
return this.configParams.px_filter_by_http_method;
|
|
@@ -98,9 +98,16 @@ var DefaultBotDefenderFilter = /** @class */ (function () {
|
|
|
98
98
|
if (requestData.method !== http_1.HttpMethod.GET && requestData.method !== http_1.HttpMethod.HEAD) {
|
|
99
99
|
return false;
|
|
100
100
|
}
|
|
101
|
-
var ext = (0, utils_1.getExtension)(requestData.url.href);
|
|
101
|
+
var ext = (0, utils_1.getExtension)(this.getExtensionFilterPath(requestData.url.href));
|
|
102
102
|
return !!ext && this.config.filteredExtensions.includes(ext);
|
|
103
103
|
};
|
|
104
|
+
DefaultBotDefenderFilter.prototype.getExtensionFilterPath = function (url) {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
if (!this.config.matrixParamsEnabled) {
|
|
107
|
+
return url;
|
|
108
|
+
}
|
|
109
|
+
return (0, utils_1.stripMatrixParams)((_b = (_a = url.split('?', 1)[0]) === null || _a === void 0 ? void 0 : _a.split('#', 1)[0]) !== null && _b !== void 0 ? _b : url);
|
|
110
|
+
};
|
|
104
111
|
DefaultBotDefenderFilter.prototype.shouldFilterByHttpMethod = function (method) {
|
|
105
112
|
return this.config.filteredHttpMethods.some(function (filteredMethod) { return filteredMethod.toUpperCase() === method; });
|
|
106
113
|
};
|
|
@@ -15,4 +15,4 @@ exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
15
15
|
exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
16
16
|
exports.URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
17
17
|
exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
18
|
-
exports.CORE_MODULE_VERSION = 'JS Core 1.
|
|
18
|
+
exports.CORE_MODULE_VERSION = 'JS Core 1.2.0';
|
package/lib/cjs/utils/utils.js
CHANGED
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.isAscii = exports.isNullOrUndefined = exports.isValidTokenVersion = exports.telemetryConfigReplacer = exports.convertRegexStringToRegex = exports.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.isStringMatch = exports.isStringInPatterns = exports.removeSensitiveHeaders = exports.redactSensitiveFields = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
|
|
39
|
+
exports.isAscii = exports.isNullOrUndefined = exports.isValidTokenVersion = exports.telemetryConfigReplacer = exports.convertRegexStringToRegex = exports.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.isStringMatch = exports.isStringInPatterns = exports.removeSensitiveHeaders = exports.redactSensitiveFields = exports.stripMatrixParams = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
|
|
40
40
|
var http_1 = require("../http/index.js");
|
|
41
41
|
var error_1 = require("./error/index.js");
|
|
42
42
|
var constants_1 = require("./constants.js");
|
|
@@ -79,6 +79,24 @@ var getExtension = function (route) {
|
|
|
79
79
|
return endOfPath.substring(extensionIndex);
|
|
80
80
|
};
|
|
81
81
|
exports.getExtension = getExtension;
|
|
82
|
+
var stripMatrixParams = function (path) {
|
|
83
|
+
if (path.indexOf(';') === -1) {
|
|
84
|
+
return path;
|
|
85
|
+
}
|
|
86
|
+
var segments = path.split('/');
|
|
87
|
+
var stripped = [];
|
|
88
|
+
segments.forEach(function (segment, i) {
|
|
89
|
+
var semicolonIndex = segment.indexOf(';');
|
|
90
|
+
if (semicolonIndex === -1) {
|
|
91
|
+
stripped.push(segment);
|
|
92
|
+
}
|
|
93
|
+
else if (semicolonIndex !== 0 || i === segments.length - 1) {
|
|
94
|
+
stripped.push(segment.substring(0, semicolonIndex));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return stripped.join('/');
|
|
98
|
+
};
|
|
99
|
+
exports.stripMatrixParams = stripMatrixParams;
|
|
82
100
|
var redactSensitiveFields = function (object, sensitiveFields) {
|
|
83
101
|
var newObj = Object.assign({}, object);
|
|
84
102
|
sensitiveFields.forEach(function (fieldName) {
|
|
@@ -170,6 +170,9 @@ export class ConfigurationBase {
|
|
|
170
170
|
get filteredExtensions() {
|
|
171
171
|
return this.configParams.px_filter_by_extension;
|
|
172
172
|
}
|
|
173
|
+
get matrixParamsEnabled() {
|
|
174
|
+
return this.configParams.px_matrix_params_enabled;
|
|
175
|
+
}
|
|
173
176
|
get filteredHttpMethods() {
|
|
174
177
|
return this.configParams.px_filter_by_http_method;
|
|
175
178
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HttpMethod } from '../../../http/index.js';
|
|
2
2
|
import { FilterReason } from '../../../filter/index.js';
|
|
3
|
-
import { getExtension, isStringInPatterns } from '../../../utils/index.js';
|
|
3
|
+
import { getExtension, isStringInPatterns, stripMatrixParams } from '../../../utils/index.js';
|
|
4
4
|
export class DefaultBotDefenderFilter {
|
|
5
5
|
config;
|
|
6
6
|
ipRangeChecker;
|
|
@@ -42,9 +42,15 @@ export class DefaultBotDefenderFilter {
|
|
|
42
42
|
if (requestData.method !== HttpMethod.GET && requestData.method !== HttpMethod.HEAD) {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
45
|
-
const ext = getExtension(requestData.url.href);
|
|
45
|
+
const ext = getExtension(this.getExtensionFilterPath(requestData.url.href));
|
|
46
46
|
return !!ext && this.config.filteredExtensions.includes(ext);
|
|
47
47
|
}
|
|
48
|
+
getExtensionFilterPath(url) {
|
|
49
|
+
if (!this.config.matrixParamsEnabled) {
|
|
50
|
+
return url;
|
|
51
|
+
}
|
|
52
|
+
return stripMatrixParams(url.split('?', 1)[0]?.split('#', 1)[0] ?? url);
|
|
53
|
+
}
|
|
48
54
|
shouldFilterByHttpMethod(method) {
|
|
49
55
|
return this.config.filteredHttpMethods.some((filteredMethod) => filteredMethod.toUpperCase() === method);
|
|
50
56
|
}
|
|
@@ -12,4 +12,4 @@ export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
12
12
|
export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
13
13
|
export const URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
14
14
|
export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
15
|
-
export const CORE_MODULE_VERSION = 'JS Core 1.
|
|
15
|
+
export const CORE_MODULE_VERSION = 'JS Core 1.2.0';
|
package/lib/esm/utils/utils.js
CHANGED
|
@@ -32,6 +32,23 @@ export const getExtension = (route) => {
|
|
|
32
32
|
}
|
|
33
33
|
return endOfPath.substring(extensionIndex);
|
|
34
34
|
};
|
|
35
|
+
export const stripMatrixParams = (path) => {
|
|
36
|
+
if (path.indexOf(';') === -1) {
|
|
37
|
+
return path;
|
|
38
|
+
}
|
|
39
|
+
const segments = path.split('/');
|
|
40
|
+
const stripped = [];
|
|
41
|
+
segments.forEach((segment, i) => {
|
|
42
|
+
const semicolonIndex = segment.indexOf(';');
|
|
43
|
+
if (semicolonIndex === -1) {
|
|
44
|
+
stripped.push(segment);
|
|
45
|
+
}
|
|
46
|
+
else if (semicolonIndex !== 0 || i === segments.length - 1) {
|
|
47
|
+
stripped.push(segment.substring(0, semicolonIndex));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return stripped.join('/');
|
|
51
|
+
};
|
|
35
52
|
export const redactSensitiveFields = (object, sensitiveFields) => {
|
|
36
53
|
const newObj = Object.assign({}, object);
|
|
37
54
|
sensitiveFields.forEach((fieldName) => {
|
|
@@ -70,6 +70,7 @@ export declare abstract class ConfigurationBase<Req, Res, Supported extends stri
|
|
|
70
70
|
get enforcedRoutes(): Array<string | RegExp>;
|
|
71
71
|
get customIsEnforcedRequest(): CustomRequestFunction<Req> | null;
|
|
72
72
|
get filteredExtensions(): string[];
|
|
73
|
+
get matrixParamsEnabled(): boolean;
|
|
73
74
|
get filteredHttpMethods(): string[];
|
|
74
75
|
get filteredIps(): string[];
|
|
75
76
|
get filteredRoutes(): Array<string | RegExp>;
|
|
@@ -63,6 +63,10 @@ export interface IConfiguration<Req, Res, Supported extends string, Added> {
|
|
|
63
63
|
* An array of extensions that should not go through the enforcer flow.
|
|
64
64
|
*/
|
|
65
65
|
readonly filteredExtensions: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Whether matrix parameters (;...) should be stripped from all path segments before filtering by extension.
|
|
68
|
+
*/
|
|
69
|
+
readonly matrixParamsEnabled: boolean;
|
|
66
70
|
/**
|
|
67
71
|
* An array of IP addresses that should not go through the enforcer flow.
|
|
68
72
|
*/
|
|
@@ -95,6 +95,7 @@ export type CommonConfigurationParams<Req, Res, Supported extends string, Added>
|
|
|
95
95
|
px_sensitive_headers?: string[];
|
|
96
96
|
px_sensitive_routes?: Array<string | RegExp>;
|
|
97
97
|
px_filter_by_extension?: string[];
|
|
98
|
+
px_matrix_params_enabled?: boolean;
|
|
98
99
|
px_filter_by_http_method?: string[];
|
|
99
100
|
px_filter_by_ip?: string[];
|
|
100
101
|
px_filter_by_route?: Array<string | RegExp>;
|
|
@@ -10,6 +10,7 @@ export declare class DefaultBotDefenderFilter<Req, Res, Supported extends string
|
|
|
10
10
|
shouldFilter(context: ReadonlyContext<Req, Res>): Promise<boolean>;
|
|
11
11
|
protected getFilterReason(context: ReadonlyContext<Req, Res>): Promise<FilterReason>;
|
|
12
12
|
protected shouldFilterByExtension(requestData: DeepReadonly<RequestData<Req>>): boolean;
|
|
13
|
+
private getExtensionFilterPath;
|
|
13
14
|
protected shouldFilterByHttpMethod(method: string): boolean;
|
|
14
15
|
protected shouldFilterByIp(ip: string): boolean;
|
|
15
16
|
protected shouldFilterByRoute(route: string): boolean;
|
|
@@ -12,4 +12,4 @@ export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
|
|
|
12
12
|
export declare const EMAIL_ADDRESS_REGEX: RegExp;
|
|
13
13
|
export declare const URL_REGEX: RegExp;
|
|
14
14
|
export declare const REGEX_STRUCTURE: RegExp;
|
|
15
|
-
export declare const CORE_MODULE_VERSION = "JS Core 1.
|
|
15
|
+
export declare const CORE_MODULE_VERSION = "JS Core 1.2.0";
|
|
@@ -9,6 +9,7 @@ export declare const getScoreApiDomain: (appId: string) => string;
|
|
|
9
9
|
export declare const getCollectorDomain: (appId: string) => string;
|
|
10
10
|
export declare const getAuthorizationHeader: (authToken: string) => string;
|
|
11
11
|
export declare const getExtension: (route: string) => string;
|
|
12
|
+
export declare const stripMatrixParams: (path: string) => string;
|
|
12
13
|
export declare const redactSensitiveFields: <T extends Record<string, any>>(object: T, sensitiveFields: Array<keyof T | string>) => T;
|
|
13
14
|
export declare const removeSensitiveHeaders: (headers: ReadonlyHeaders, sensitiveHeaderNames: string[]) => Record<string, string[]>;
|
|
14
15
|
export declare const isStringInPatterns: (str: string, patterns: Array<string | RegExp>) => boolean;
|