perimeterx-js-core 0.30.1 → 0.31.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/BotDefender.js +9 -1
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/esm/config/ConfigurationBase.js +3 -0
- package/lib/esm/config/defaults/DefaultConfigurationParams.js +1 -0
- package/lib/esm/products/bot_defender/BotDefender.js +9 -2
- package/lib/esm/utils/constants.js +1 -1
- package/lib/types/config/ConfigurationBase.d.ts +1 -0
- package/lib/types/config/IConfiguration.d.ts +4 -0
- package/lib/types/config/params/CoreConfigurationParams.d.ts +1 -0
- package/lib/types/products/bot_defender/BotDefender.d.ts +1 -1
- package/lib/types/utils/constants.d.ts +1 -1
- package/package.json +5 -5
|
@@ -775,6 +775,13 @@ var ConfigurationBase = /** @class */ (function () {
|
|
|
775
775
|
enumerable: false,
|
|
776
776
|
configurable: true
|
|
777
777
|
});
|
|
778
|
+
Object.defineProperty(ConfigurationBase.prototype, "dataEnrichmentHeaderName", {
|
|
779
|
+
get: function () {
|
|
780
|
+
return this.configParams.px_data_enrichment_header_name;
|
|
781
|
+
},
|
|
782
|
+
enumerable: false,
|
|
783
|
+
configurable: true
|
|
784
|
+
});
|
|
778
785
|
Object.defineProperty(ConfigurationBase.prototype, "enableBlockedUrlOnCaptchaBlockPage", {
|
|
779
786
|
get: function () {
|
|
780
787
|
return true;
|
|
@@ -132,6 +132,7 @@ var defaultConfigurationParams = function () { return ({
|
|
|
132
132
|
px_remote_config_retry_interval_ms: 1000,
|
|
133
133
|
px_url_decode_reserved_characters: false,
|
|
134
134
|
px_secured_pxhd_enabled: false,
|
|
135
|
+
px_data_enrichment_header_name: '',
|
|
135
136
|
px_snippet_injection_enabled: false,
|
|
136
137
|
px_create_custom_snippet: null,
|
|
137
138
|
px_custom_is_sensitive_request: null,
|
|
@@ -189,9 +189,17 @@ var BotDefender = /** @class */ (function () {
|
|
|
189
189
|
BotDefender.prototype.createBlockResponse = function (context) {
|
|
190
190
|
return this.blocker.createBlockResponse(context);
|
|
191
191
|
};
|
|
192
|
-
BotDefender.prototype.modifyIncomingRequest = function (
|
|
192
|
+
BotDefender.prototype.modifyIncomingRequest = function (context) {
|
|
193
193
|
return __awaiter(this, void 0, void 0, function () {
|
|
194
194
|
return __generator(this, function (_a) {
|
|
195
|
+
if (this.config.dataEnrichmentHeaderName && context.pxde && context.pxdeVerified) {
|
|
196
|
+
try {
|
|
197
|
+
context.requestData.request.headers.set(this.config.dataEnrichmentHeaderName, JSON.stringify(context.pxde));
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
context.logger.debug("unable to set data enrichment header: ".concat(err));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
195
203
|
return [2 /*return*/];
|
|
196
204
|
});
|
|
197
205
|
});
|
|
@@ -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 0.
|
|
18
|
+
exports.CORE_MODULE_VERSION = 'JS Core 0.31.0';
|
|
@@ -405,6 +405,9 @@ export class ConfigurationBase {
|
|
|
405
405
|
get createCustomSnippet() {
|
|
406
406
|
return this.configParams.px_create_custom_snippet;
|
|
407
407
|
}
|
|
408
|
+
get dataEnrichmentHeaderName() {
|
|
409
|
+
return this.configParams.px_data_enrichment_header_name;
|
|
410
|
+
}
|
|
408
411
|
get enableBlockedUrlOnCaptchaBlockPage() {
|
|
409
412
|
return true;
|
|
410
413
|
}
|
|
@@ -129,6 +129,7 @@ export const defaultConfigurationParams = () => ({
|
|
|
129
129
|
px_remote_config_retry_interval_ms: 1000,
|
|
130
130
|
px_url_decode_reserved_characters: false,
|
|
131
131
|
px_secured_pxhd_enabled: false,
|
|
132
|
+
px_data_enrichment_header_name: '',
|
|
132
133
|
px_snippet_injection_enabled: false,
|
|
133
134
|
px_create_custom_snippet: null,
|
|
134
135
|
px_custom_is_sensitive_request: null,
|
|
@@ -101,8 +101,15 @@ export class BotDefender {
|
|
|
101
101
|
createBlockResponse(context) {
|
|
102
102
|
return this.blocker.createBlockResponse(context);
|
|
103
103
|
}
|
|
104
|
-
async modifyIncomingRequest(
|
|
105
|
-
|
|
104
|
+
async modifyIncomingRequest(context) {
|
|
105
|
+
if (this.config.dataEnrichmentHeaderName && context.pxde && context.pxdeVerified) {
|
|
106
|
+
try {
|
|
107
|
+
context.requestData.request.headers.set(this.config.dataEnrichmentHeaderName, JSON.stringify(context.pxde));
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
context.logger.debug(`unable to set data enrichment header: ${err}`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
106
113
|
}
|
|
107
114
|
async modifyOutgoingResponse(_context) {
|
|
108
115
|
// intentionally left blank
|
|
@@ -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 0.
|
|
15
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.31.0';
|
|
@@ -143,6 +143,7 @@ export declare abstract class ConfigurationBase<Req, Res, Added, Removed extends
|
|
|
143
143
|
get tokenVersion(): `${TokenVersion}`;
|
|
144
144
|
get snippetInjectionEnabled(): boolean;
|
|
145
145
|
get createCustomSnippet(): CustomSnippetFunction<Req, Res, Added, Removed> | null;
|
|
146
|
+
get dataEnrichmentHeaderName(): string;
|
|
146
147
|
get enableBlockedUrlOnCaptchaBlockPage(): boolean;
|
|
147
148
|
get awaitAsyncHttpRequests(): boolean;
|
|
148
149
|
get isPostEnforceEnabled(): boolean;
|
|
@@ -404,6 +404,10 @@ export interface IConfiguration<Req, Res, Added, Removed> {
|
|
|
404
404
|
* The version of the token the enforcer is able to parse.
|
|
405
405
|
*/
|
|
406
406
|
readonly tokenVersion: `${TokenVersion}`;
|
|
407
|
+
/**
|
|
408
|
+
* The header name to use when adding the data enrichment value as an incoming request header.
|
|
409
|
+
*/
|
|
410
|
+
readonly dataEnrichmentHeaderName: string;
|
|
407
411
|
/**
|
|
408
412
|
* Returns an object representation of the current configuration.
|
|
409
413
|
*/
|
|
@@ -120,6 +120,7 @@ export type CommonConfigurationParams<Req, Res, Added, Removed> = TokenV3Configu
|
|
|
120
120
|
px_remote_config_retry_interval_ms?: number;
|
|
121
121
|
px_url_decode_reserved_characters?: boolean;
|
|
122
122
|
px_secured_pxhd_enabled?: boolean;
|
|
123
|
+
px_data_enrichment_header_name?: string;
|
|
123
124
|
px_additional_activity_handler?: AdditionalActivityHandler<Req, Res, Added, Removed> | null;
|
|
124
125
|
px_enrich_custom_parameters?: CustomParametersFunction<Req, Res, Added, Removed> | null;
|
|
125
126
|
px_enrich_response_custom_parameters?: ResponseCustomParametersFunction<Req, Res, Added, Removed> | null;
|
|
@@ -46,6 +46,6 @@ export declare class BotDefender<Req, Res, Added, Removed> implements IBotDefend
|
|
|
46
46
|
protected getSuccessfulRiskApiAction(riskResponse: DeepReadonly<IRiskResponse>, isMonitored: boolean): ActionData;
|
|
47
47
|
shouldBlock(context: ReadonlyContext<Req, Res>): boolean;
|
|
48
48
|
createBlockResponse(context: ReadonlyContext<Req, Res>): IMinimalResponse;
|
|
49
|
-
modifyIncomingRequest(
|
|
49
|
+
modifyIncomingRequest(context: ReadonlyContext<Req, Res>): Promise<void>;
|
|
50
50
|
modifyOutgoingResponse(_context: ReadonlyContext<Req, Res>): Promise<void>;
|
|
51
51
|
}
|
|
@@ -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 0.
|
|
15
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.31.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perimeterx-js-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"typesVersions": {
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"lint": "eslint . --ext .ts",
|
|
39
39
|
"lint:fix": "eslint . --ext .ts --fix",
|
|
40
40
|
"test": "mocha",
|
|
41
|
-
"coverage": "
|
|
41
|
+
"coverage": "c8 npm run test",
|
|
42
42
|
"pre-commit": "./node_modules/.bin/lint-staged",
|
|
43
43
|
"prepare": "husky"
|
|
44
44
|
},
|
|
@@ -58,8 +58,9 @@
|
|
|
58
58
|
"@types/node": "^18.19.50 || ^20.6.0 || ^22.0.0",
|
|
59
59
|
"@types/sinon": "^17.0.1",
|
|
60
60
|
"@types/uuid": "^10.0.0",
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^8.38.0",
|
|
62
62
|
"@typescript-eslint/parser": "^8.26.0",
|
|
63
|
+
"c8": "^10.1.3",
|
|
63
64
|
"chai": "^5.2.0",
|
|
64
65
|
"chai-as-promised": "^8.0.0",
|
|
65
66
|
"core-js": "^3.19.1",
|
|
@@ -69,9 +70,8 @@
|
|
|
69
70
|
"husky": "^9.1.7",
|
|
70
71
|
"lint-staged": "^16.0.0",
|
|
71
72
|
"mocha": "^11.4.0",
|
|
72
|
-
"nyc": "^17.0.0",
|
|
73
73
|
"prettier": "^3.5.3",
|
|
74
|
-
"sinon": "^
|
|
74
|
+
"sinon": "^21.0.0",
|
|
75
75
|
"ts-loader": "^9.4.1",
|
|
76
76
|
"ts-node": "^10.9.1",
|
|
77
77
|
"tsc-alias": "^1.8.11",
|