perimeterx-js-core 0.26.0 → 0.26.2
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/risk_api/client/GetRiskApiClientV2.js +31 -13
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/utils.js +3 -1
- package/lib/esm/risk_api/client/GetRiskApiClientV2.js +25 -11
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/utils.js +1 -0
- package/lib/types/risk_api/client/GetRiskApiClientV2.d.ts +4 -1
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/utils.d.ts +1 -0
- package/package.json +7 -7
|
@@ -21,6 +21,7 @@ var http_1 = require("../../http/index.js");
|
|
|
21
21
|
var risk_response_1 = require("../risk_response/index.js");
|
|
22
22
|
var model_1 = require("../model/index.js");
|
|
23
23
|
var utils_1 = require("../utils.js");
|
|
24
|
+
var utils_2 = require("../../utils/index.js");
|
|
24
25
|
var GetRiskApiClientV2 = /** @class */ (function (_super) {
|
|
25
26
|
__extends(GetRiskApiClientV2, _super);
|
|
26
27
|
function GetRiskApiClientV2(config, httpClient) {
|
|
@@ -35,34 +36,47 @@ var GetRiskApiClientV2 = /** @class */ (function (_super) {
|
|
|
35
36
|
};
|
|
36
37
|
GetRiskApiClientV2.prototype.getRiskActivityHeaders = function (context) {
|
|
37
38
|
var riskHeaders = this.getRiskHeaders();
|
|
38
|
-
var requestHeaders = this.getRequestHeadersForRisk(context);
|
|
39
39
|
var riskActivityHeaders = this.riskActivityToHeaders((0, utils_1.createRiskApiActivity)(this.config, context));
|
|
40
|
-
return Object.assign(
|
|
40
|
+
return Object.assign(this.finalizeHeaders(riskActivityHeaders), riskHeaders);
|
|
41
41
|
};
|
|
42
|
-
GetRiskApiClientV2.prototype.
|
|
42
|
+
GetRiskApiClientV2.prototype.addHeadersFromRiskActivityHeaderEntries = function (headers, headerEntries) {
|
|
43
43
|
var HEADERS_TO_DELETE = [http_1.CONTENT_LENGTH_HEADER_NAME, http_1.CONTENT_TYPE_HEADER_NAME, http_1.AUTHORIZATION_HEADER_NAME];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
headers[key] = value.concat();
|
|
44
|
+
headerEntries.forEach(function (_a) {
|
|
45
|
+
var name = _a.name, value = _a.value;
|
|
46
|
+
if (!HEADERS_TO_DELETE.includes(name.toLowerCase())) {
|
|
47
|
+
headers[name] = [value];
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
return headers;
|
|
52
51
|
};
|
|
53
52
|
GetRiskApiClientV2.prototype.riskActivityToHeaders = function (riskActivity) {
|
|
54
53
|
var headers = {};
|
|
54
|
+
// order matters, risk activity field headers should override any request headers with the same name
|
|
55
|
+
this.addHeadersFromRiskActivityHeaderEntries(headers, riskActivity.request.headers);
|
|
55
56
|
this.addHeadersFromObject(headers, riskActivity, model_1.RISK_ACTIVITY_FIELDS_TO_HEADER_NAMES);
|
|
56
57
|
this.addHeadersFromObject(headers, riskActivity.request, model_1.RISK_ACTIVITY_REQUEST_FIELDS_TO_HEADER_NAMES);
|
|
57
58
|
this.addHeadersFromObject(headers, riskActivity.additional, model_1.RISK_ACTIVITY_ADDITIONAL_FIELDS_TO_HEADER_NAMES);
|
|
58
59
|
return headers;
|
|
59
60
|
};
|
|
61
|
+
GetRiskApiClientV2.prototype.finalizeHeaders = function (headers) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
return Object.fromEntries(Object.entries(headers).filter(function (_a) {
|
|
64
|
+
var name = _a[0], value = _a[1];
|
|
65
|
+
return _this.shouldFilterHeader(name, value);
|
|
66
|
+
}));
|
|
67
|
+
};
|
|
68
|
+
GetRiskApiClientV2.prototype.shouldFilterHeader = function (headerName, headerValue) {
|
|
69
|
+
return (0, utils_2.isAscii)(headerName) && headerValue.every(function (value) { return (0, utils_2.isAscii)(value); });
|
|
70
|
+
};
|
|
60
71
|
GetRiskApiClientV2.prototype.addHeadersFromObject = function (headers, object, headerNamesMap) {
|
|
61
|
-
Object.entries(
|
|
62
|
-
var key = _a[0],
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
Object.entries(headerNamesMap).forEach(function (_a) {
|
|
73
|
+
var key = _a[0], headerConversionObject = _a[1];
|
|
74
|
+
if (!headerConversionObject) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
var header = headerConversionObject.header, convertToString = headerConversionObject.convertToString;
|
|
78
|
+
var value = object[key];
|
|
79
|
+
if (value != null) {
|
|
66
80
|
var strValue = convertToString
|
|
67
81
|
? convertToString(value)
|
|
68
82
|
: typeof value === 'string'
|
|
@@ -70,6 +84,10 @@ var GetRiskApiClientV2 = /** @class */ (function (_super) {
|
|
|
70
84
|
: "".concat(value);
|
|
71
85
|
headers[header] = [strValue];
|
|
72
86
|
}
|
|
87
|
+
else {
|
|
88
|
+
// delete so that user cannot spoof
|
|
89
|
+
delete headers[header];
|
|
90
|
+
}
|
|
73
91
|
});
|
|
74
92
|
};
|
|
75
93
|
GetRiskApiClientV2.prototype.createRiskResponse = function (response) {
|
|
@@ -14,4 +14,4 @@ exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
14
14
|
exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
15
15
|
exports.URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
16
16
|
exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
17
|
-
exports.CORE_MODULE_VERSION = 'JS Core 0.26.
|
|
17
|
+
exports.CORE_MODULE_VERSION = 'JS Core 0.26.2';
|
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.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.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");
|
|
@@ -246,3 +246,5 @@ var isNullOrUndefined = function (value) {
|
|
|
246
246
|
return value === null || value === undefined;
|
|
247
247
|
};
|
|
248
248
|
exports.isNullOrUndefined = isNullOrUndefined;
|
|
249
|
+
var isAscii = function (str) { return str.split('').every(function (char) { return char <= '\x7F'; }); };
|
|
250
|
+
exports.isAscii = isAscii;
|
|
@@ -3,6 +3,7 @@ import { AUTHORIZATION_HEADER_NAME, CONTENT_LENGTH_HEADER_NAME, CONTENT_TYPE_HEA
|
|
|
3
3
|
import { GetRiskResponseV2 } from '../risk_response/index.js';
|
|
4
4
|
import { RISK_ACTIVITY_ADDITIONAL_FIELDS_TO_HEADER_NAMES, RISK_ACTIVITY_FIELDS_TO_HEADER_NAMES, RISK_ACTIVITY_REQUEST_FIELDS_TO_HEADER_NAMES, } from '../model/index.js';
|
|
5
5
|
import { createRiskApiActivity } from '../utils.js';
|
|
6
|
+
import { isAscii } from '../../utils/index.js';
|
|
6
7
|
export class GetRiskApiClientV2 extends RiskApiClientBase {
|
|
7
8
|
constructor(config, httpClient) {
|
|
8
9
|
super(config, httpClient);
|
|
@@ -16,32 +17,41 @@ export class GetRiskApiClientV2 extends RiskApiClientBase {
|
|
|
16
17
|
}
|
|
17
18
|
getRiskActivityHeaders(context) {
|
|
18
19
|
const riskHeaders = this.getRiskHeaders();
|
|
19
|
-
const requestHeaders = this.getRequestHeadersForRisk(context);
|
|
20
20
|
const riskActivityHeaders = this.riskActivityToHeaders(createRiskApiActivity(this.config, context));
|
|
21
|
-
return Object.assign(
|
|
21
|
+
return Object.assign(this.finalizeHeaders(riskActivityHeaders), riskHeaders);
|
|
22
22
|
}
|
|
23
|
-
|
|
23
|
+
addHeadersFromRiskActivityHeaderEntries(headers, headerEntries) {
|
|
24
24
|
const HEADERS_TO_DELETE = [CONTENT_LENGTH_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, AUTHORIZATION_HEADER_NAME];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
headers[key] = value.concat();
|
|
25
|
+
headerEntries.forEach(({ name, value }) => {
|
|
26
|
+
if (!HEADERS_TO_DELETE.includes(name.toLowerCase())) {
|
|
27
|
+
headers[name] = [value];
|
|
29
28
|
}
|
|
30
29
|
});
|
|
31
30
|
return headers;
|
|
32
31
|
}
|
|
33
32
|
riskActivityToHeaders(riskActivity) {
|
|
34
33
|
const headers = {};
|
|
34
|
+
// order matters, risk activity field headers should override any request headers with the same name
|
|
35
|
+
this.addHeadersFromRiskActivityHeaderEntries(headers, riskActivity.request.headers);
|
|
35
36
|
this.addHeadersFromObject(headers, riskActivity, RISK_ACTIVITY_FIELDS_TO_HEADER_NAMES);
|
|
36
37
|
this.addHeadersFromObject(headers, riskActivity.request, RISK_ACTIVITY_REQUEST_FIELDS_TO_HEADER_NAMES);
|
|
37
38
|
this.addHeadersFromObject(headers, riskActivity.additional, RISK_ACTIVITY_ADDITIONAL_FIELDS_TO_HEADER_NAMES);
|
|
38
39
|
return headers;
|
|
39
40
|
}
|
|
41
|
+
finalizeHeaders(headers) {
|
|
42
|
+
return Object.fromEntries(Object.entries(headers).filter(([name, value]) => this.shouldFilterHeader(name, value)));
|
|
43
|
+
}
|
|
44
|
+
shouldFilterHeader(headerName, headerValue) {
|
|
45
|
+
return isAscii(headerName) && headerValue.every((value) => isAscii(value));
|
|
46
|
+
}
|
|
40
47
|
addHeadersFromObject(headers, object, headerNamesMap) {
|
|
41
|
-
Object.entries(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
Object.entries(headerNamesMap).forEach(([key, headerConversionObject]) => {
|
|
49
|
+
if (!headerConversionObject) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const { header, convertToString } = headerConversionObject;
|
|
53
|
+
const value = object[key];
|
|
54
|
+
if (value != null) {
|
|
45
55
|
const strValue = convertToString
|
|
46
56
|
? convertToString(value)
|
|
47
57
|
: typeof value === 'string'
|
|
@@ -49,6 +59,10 @@ export class GetRiskApiClientV2 extends RiskApiClientBase {
|
|
|
49
59
|
: `${value}`;
|
|
50
60
|
headers[header] = [strValue];
|
|
51
61
|
}
|
|
62
|
+
else {
|
|
63
|
+
// delete so that user cannot spoof
|
|
64
|
+
delete headers[header];
|
|
65
|
+
}
|
|
52
66
|
});
|
|
53
67
|
}
|
|
54
68
|
createRiskResponse(response) {
|
|
@@ -11,4 +11,4 @@ export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
11
11
|
export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
12
12
|
export const URL_REGEX = /^(https?:)\/\/(([^@\s:\/]+):?([^@\s\/]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)(\/?[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
13
13
|
export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
14
|
-
export const CORE_MODULE_VERSION = 'JS Core 0.26.
|
|
14
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.26.2';
|
package/lib/esm/utils/utils.js
CHANGED
|
@@ -170,3 +170,4 @@ export const telemetryConfigReplacer = (_key, value) => {
|
|
|
170
170
|
};
|
|
171
171
|
export const isValidTokenVersion = (tokenVersion) => Object.values(TokenVersion).includes(tokenVersion);
|
|
172
172
|
export const isNullOrUndefined = (value) => value === null || value === undefined;
|
|
173
|
+
export const isAscii = (str) => str.split('').every((char) => char <= '\x7F');
|
|
@@ -4,12 +4,15 @@ import { IHttpClient, IIncomingResponse, OutgoingRequestImpl, ReadonlyHeaders }
|
|
|
4
4
|
import { ReadonlyContext } from '../../context';
|
|
5
5
|
import { IRiskResponse } from '../risk_response';
|
|
6
6
|
import { RiskActivity } from '../model';
|
|
7
|
+
import { HeaderEntry } from '../../activities';
|
|
7
8
|
export declare class GetRiskApiClientV2<Req, Res, Added, Removed> extends RiskApiClientBase<Req, Res, Added, Removed> {
|
|
8
9
|
constructor(config: IConfiguration<Req, Res, Added, Removed>, httpClient: IHttpClient);
|
|
9
10
|
protected createRiskRequest(context: ReadonlyContext<Req, Res>): OutgoingRequestImpl;
|
|
10
11
|
protected getRiskActivityHeaders(context: ReadonlyContext<Req, Res>): ReadonlyHeaders;
|
|
11
|
-
protected
|
|
12
|
+
protected addHeadersFromRiskActivityHeaderEntries(headers: Record<string, string[]>, headerEntries: HeaderEntry[]): Record<string, string[]>;
|
|
12
13
|
protected riskActivityToHeaders(riskActivity: RiskActivity): Record<string, string[]>;
|
|
14
|
+
protected finalizeHeaders(headers: Record<string, string[]>): Record<string, string[]>;
|
|
15
|
+
protected shouldFilterHeader(headerName: string, headerValue: string[]): boolean;
|
|
13
16
|
private addHeadersFromObject;
|
|
14
17
|
protected createRiskResponse(response: IIncomingResponse): IRiskResponse;
|
|
15
18
|
}
|
|
@@ -11,4 +11,4 @@ export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
|
|
|
11
11
|
export declare const EMAIL_ADDRESS_REGEX: RegExp;
|
|
12
12
|
export declare const URL_REGEX: RegExp;
|
|
13
13
|
export declare const REGEX_STRUCTURE: RegExp;
|
|
14
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.26.
|
|
14
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.26.2";
|
|
@@ -22,3 +22,4 @@ export declare const convertRegexStringToRegex: (regexString: string, logger?: I
|
|
|
22
22
|
export declare const telemetryConfigReplacer: (_key: string, value: any) => string;
|
|
23
23
|
export declare const isValidTokenVersion: (tokenVersion: any) => tokenVersion is TokenVersion;
|
|
24
24
|
export declare const isNullOrUndefined: <T>(value: T | null | undefined) => value is null | undefined;
|
|
25
|
+
export declare const isAscii: (str: string) => boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "perimeterx-js-core",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"typesVersions": {
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"build:esm": "tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json",
|
|
36
36
|
"build:dec": "tsc -p tsconfig.dec.json && tsc-alias -p tsconfig.dec.json",
|
|
37
37
|
"clean": "rm -rf lib",
|
|
38
|
-
"lint": "
|
|
39
|
-
"lint:fix": "
|
|
38
|
+
"lint": "eslint . --ext .ts",
|
|
39
|
+
"lint:fix": "eslint . --ext .ts --fix",
|
|
40
40
|
"test": "mocha",
|
|
41
41
|
"coverage": "nyc npm run test",
|
|
42
42
|
"pre-commit": "./node_modules/.bin/lint-staged",
|
|
@@ -48,18 +48,18 @@
|
|
|
48
48
|
"js-base64": "^3.7.2",
|
|
49
49
|
"phin": "^3.7.0",
|
|
50
50
|
"ts-essentials": "^10.0.0",
|
|
51
|
-
"uuid": "^
|
|
51
|
+
"uuid": "^11.1.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@types/chai": "^
|
|
55
|
-
"@types/chai-as-promised": "^
|
|
54
|
+
"@types/chai": "^5.2.1",
|
|
55
|
+
"@types/chai-as-promised": "^8.0.2",
|
|
56
56
|
"@types/crypto-js": "^4.1.1",
|
|
57
57
|
"@types/mocha": "^10.0.0",
|
|
58
58
|
"@types/sinon": "^17.0.1",
|
|
59
59
|
"@types/uuid": "^10.0.0",
|
|
60
60
|
"@typescript-eslint/eslint-plugin": "^8.26.0",
|
|
61
61
|
"@typescript-eslint/parser": "^8.26.0",
|
|
62
|
-
"chai": "^
|
|
62
|
+
"chai": "^5.2.0",
|
|
63
63
|
"chai-as-promised": "^8.0.0",
|
|
64
64
|
"core-js": "^3.19.1",
|
|
65
65
|
"eslint": "^9.21.0",
|