perimeterx-js-core 0.32.1 → 0.34.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/activities/utils.js +5 -0
- package/lib/cjs/context/DefaultContext.js +2 -2
- package/lib/cjs/context/SerializedContext.js +1 -1
- package/lib/cjs/phase/impl/IdentifyTelemetryRequestPhase.js +1 -1
- package/lib/cjs/phase/impl/RiskApiPhase.js +1 -1
- package/lib/cjs/phase/impl/SendTelemetryActivityPhase.js +1 -1
- package/lib/cjs/risk_api/model/GetRiskRequestHeaders.js +4 -0
- package/lib/cjs/telemetry/DefaultTelemetry.js +3 -0
- package/lib/cjs/telemetry/index.js +1 -0
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/esm/activities/utils.js +5 -0
- package/lib/esm/context/DefaultContext.js +3 -3
- package/lib/esm/context/SerializedContext.js +2 -2
- package/lib/esm/phase/impl/IdentifyTelemetryRequestPhase.js +1 -1
- package/lib/esm/phase/impl/RiskApiPhase.js +1 -1
- package/lib/esm/phase/impl/SendTelemetryActivityPhase.js +1 -1
- package/lib/esm/risk_api/model/GetRiskRequestHeaders.js +4 -0
- package/lib/esm/telemetry/DefaultTelemetry.js +3 -0
- package/lib/esm/telemetry/index.js +1 -0
- package/lib/esm/utils/constants.js +1 -1
- package/lib/types/activities/model/CommonActivityDetails.d.ts +1 -0
- package/lib/types/context/ContextJson.d.ts +2 -1
- package/lib/types/context/DefaultContext.d.ts +2 -1
- package/lib/types/context/SerializedContext.d.ts +2 -1
- package/lib/types/context/interfaces/IContext.d.ts +3 -2
- package/lib/types/risk_api/utils.d.ts +1 -0
- package/lib/types/telemetry/index.d.ts +1 -1
- package/lib/types/telemetry/model/TelemetryActivity.d.ts +3 -1
- package/lib/types/utils/constants.d.ts +1 -1
- package/package.json +1 -1
|
@@ -156,6 +156,11 @@ var addProductDataToDetails = function (details, productData) {
|
|
|
156
156
|
details.cpa = productData.hsc.isTokenHscApproved;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
+
if (productData.bd) {
|
|
160
|
+
if (typeof productData.bd.isSensitiveRequest === 'boolean') {
|
|
161
|
+
details.is_sensitive_route = productData.bd.isSensitiveRequest;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
159
164
|
};
|
|
160
165
|
exports.addProductDataToDetails = addProductDataToDetails;
|
|
161
166
|
var addTlsDataToDetails = function (details, tlsData) {
|
|
@@ -54,7 +54,7 @@ var DefaultContext = /** @class */ (function () {
|
|
|
54
54
|
if (!this.isMobile) {
|
|
55
55
|
this.setCookiesOnContext();
|
|
56
56
|
}
|
|
57
|
-
this.
|
|
57
|
+
this.telemetryUpdateReason = undefined;
|
|
58
58
|
}
|
|
59
59
|
Object.defineProperty(DefaultContext.prototype, "shouldSendLogs", {
|
|
60
60
|
get: function () {
|
|
@@ -189,7 +189,7 @@ var DefaultContext = /** @class */ (function () {
|
|
|
189
189
|
enforcerStartTime: this.enforcerStartTime,
|
|
190
190
|
blockAction: this.blockAction,
|
|
191
191
|
pxdeVerified: this.pxdeVerified,
|
|
192
|
-
|
|
192
|
+
telemetryUpdateReason: this.telemetryUpdateReason,
|
|
193
193
|
logger: this.shouldSendLogs
|
|
194
194
|
? {
|
|
195
195
|
logs: this.logger.getLogs(),
|
|
@@ -48,7 +48,7 @@ var SerializedContext = /** @class */ (function () {
|
|
|
48
48
|
this.graphqlData = contextJson.graphqlData;
|
|
49
49
|
this.enforcerStartTime = contextJson.enforcerStartTime;
|
|
50
50
|
this.blockAction = contextJson.blockAction;
|
|
51
|
-
this.
|
|
51
|
+
this.telemetryUpdateReason = contextJson.telemetryUpdateReason;
|
|
52
52
|
}
|
|
53
53
|
SerializedContext.prototype.createRequestData = function (_a, request, urlUtils) {
|
|
54
54
|
var requestData = _a.requestData;
|
|
@@ -53,7 +53,7 @@ var IdentifyTelemetryRequestPhase = /** @class */ (function () {
|
|
|
53
53
|
case 0: return [4 /*yield*/, this.telemetry.isValidTelemetryRequest(context)];
|
|
54
54
|
case 1:
|
|
55
55
|
if (_a.sent()) {
|
|
56
|
-
context.
|
|
56
|
+
context.telemetryUpdateReason = 'command';
|
|
57
57
|
return [2 /*return*/, { done: true }];
|
|
58
58
|
}
|
|
59
59
|
return [2 /*return*/, { done: false }];
|
|
@@ -139,7 +139,7 @@ var RiskApiPhase = /** @class */ (function (_super) {
|
|
|
139
139
|
context.uuid = riskResponse.uuid;
|
|
140
140
|
}
|
|
141
141
|
if (riskResponse.telemetryRequested) {
|
|
142
|
-
context.
|
|
142
|
+
context.telemetryUpdateReason = 'risk';
|
|
143
143
|
}
|
|
144
144
|
if (riskResponse.dataEnrichment) {
|
|
145
145
|
context.pxde = riskResponse.dataEnrichment;
|
|
@@ -51,7 +51,7 @@ var SendTelemetryActivityPhase = /** @class */ (function () {
|
|
|
51
51
|
return __generator(this, function (_a) {
|
|
52
52
|
switch (_a.label) {
|
|
53
53
|
case 0:
|
|
54
|
-
if (!context.
|
|
54
|
+
if (!context.telemetryUpdateReason) return [3 /*break*/, 2];
|
|
55
55
|
promise = this.telemetry.sendTelemetry(context);
|
|
56
56
|
if (!this.config.awaitAsyncHttpRequests) return [3 /*break*/, 2];
|
|
57
57
|
return [4 /*yield*/, promise];
|
|
@@ -182,4 +182,8 @@ exports.RISK_ACTIVITY_ADDITIONAL_FIELDS_TO_HEADER_NAMES = {
|
|
|
182
182
|
s2s_call_reason: {
|
|
183
183
|
header: 'x-px-add-s2s-call-reason',
|
|
184
184
|
},
|
|
185
|
+
is_sensitive_route: {
|
|
186
|
+
header: 'x-px-add-is-sensitive-route',
|
|
187
|
+
convertToString: function (value) { return "".concat(value); },
|
|
188
|
+
},
|
|
185
189
|
};
|
|
@@ -156,6 +156,9 @@ var DefaultTelemetry = /** @class */ (function () {
|
|
|
156
156
|
enforcer_configs: telemetryConfig,
|
|
157
157
|
},
|
|
158
158
|
};
|
|
159
|
+
if (context.requestId) {
|
|
160
|
+
activity.details.request_id = context.requestId;
|
|
161
|
+
}
|
|
159
162
|
if (context.serverData.osName) {
|
|
160
163
|
activity.details.os_name = context.serverData.osName;
|
|
161
164
|
}
|
|
@@ -17,4 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.DefaultTelemetry = void 0;
|
|
18
18
|
var DefaultTelemetry_1 = require("./DefaultTelemetry.js");
|
|
19
19
|
Object.defineProperty(exports, "DefaultTelemetry", { enumerable: true, get: function () { return DefaultTelemetry_1.DefaultTelemetry; } });
|
|
20
|
+
__exportStar(require("./model/TelemetryActivity.js"), exports);
|
|
20
21
|
__exportStar(require("./constants.js"), exports);
|
|
@@ -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.34.0';
|
|
@@ -143,6 +143,11 @@ export const addProductDataToDetails = (details, productData) => {
|
|
|
143
143
|
details.cpa = productData.hsc.isTokenHscApproved;
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
+
if (productData.bd) {
|
|
147
|
+
if (typeof productData.bd.isSensitiveRequest === 'boolean') {
|
|
148
|
+
details.is_sensitive_route = productData.bd.isSensitiveRequest;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
146
151
|
};
|
|
147
152
|
export const addTlsDataToDetails = (details, tlsData) => {
|
|
148
153
|
if (tlsData.tlsCipher) {
|
|
@@ -36,7 +36,7 @@ export class DefaultContext {
|
|
|
36
36
|
enforcerStartTime;
|
|
37
37
|
logger;
|
|
38
38
|
usedCookieSecret;
|
|
39
|
-
|
|
39
|
+
telemetryUpdateReason;
|
|
40
40
|
_shouldSendLogs = false;
|
|
41
41
|
config;
|
|
42
42
|
urlUtils;
|
|
@@ -68,7 +68,7 @@ export class DefaultContext {
|
|
|
68
68
|
if (!this.isMobile) {
|
|
69
69
|
this.setCookiesOnContext();
|
|
70
70
|
}
|
|
71
|
-
this.
|
|
71
|
+
this.telemetryUpdateReason = undefined;
|
|
72
72
|
}
|
|
73
73
|
get shouldSendLogs() {
|
|
74
74
|
return this._shouldSendLogs;
|
|
@@ -195,7 +195,7 @@ export class DefaultContext {
|
|
|
195
195
|
enforcerStartTime: this.enforcerStartTime,
|
|
196
196
|
blockAction: this.blockAction,
|
|
197
197
|
pxdeVerified: this.pxdeVerified,
|
|
198
|
-
|
|
198
|
+
telemetryUpdateReason: this.telemetryUpdateReason,
|
|
199
199
|
logger: this.shouldSendLogs
|
|
200
200
|
? {
|
|
201
201
|
logs: this.logger.getLogs(),
|
|
@@ -32,7 +32,7 @@ export class SerializedContext {
|
|
|
32
32
|
vidSource;
|
|
33
33
|
tokenOrigin;
|
|
34
34
|
uuid;
|
|
35
|
-
|
|
35
|
+
telemetryUpdateReason;
|
|
36
36
|
constructor(config, contextJson, request, urlUtils) {
|
|
37
37
|
this.action = contextJson.action;
|
|
38
38
|
this.reasons = contextJson.reasons;
|
|
@@ -59,7 +59,7 @@ export class SerializedContext {
|
|
|
59
59
|
this.graphqlData = contextJson.graphqlData;
|
|
60
60
|
this.enforcerStartTime = contextJson.enforcerStartTime;
|
|
61
61
|
this.blockAction = contextJson.blockAction;
|
|
62
|
-
this.
|
|
62
|
+
this.telemetryUpdateReason = contextJson.telemetryUpdateReason;
|
|
63
63
|
}
|
|
64
64
|
createRequestData({ requestData }, request, urlUtils) {
|
|
65
65
|
return {
|
|
@@ -10,7 +10,7 @@ export class IdentifyTelemetryRequestPhase {
|
|
|
10
10
|
}
|
|
11
11
|
async execute(context) {
|
|
12
12
|
if (await this.telemetry.isValidTelemetryRequest(context)) {
|
|
13
|
-
context.
|
|
13
|
+
context.telemetryUpdateReason = 'command';
|
|
14
14
|
return { done: true };
|
|
15
15
|
}
|
|
16
16
|
return { done: false };
|
|
@@ -51,7 +51,7 @@ export class RiskApiPhase extends DecideActionPhase {
|
|
|
51
51
|
context.uuid = riskResponse.uuid;
|
|
52
52
|
}
|
|
53
53
|
if (riskResponse.telemetryRequested) {
|
|
54
|
-
context.
|
|
54
|
+
context.telemetryUpdateReason = 'risk';
|
|
55
55
|
}
|
|
56
56
|
if (riskResponse.dataEnrichment) {
|
|
57
57
|
context.pxde = riskResponse.dataEnrichment;
|
|
@@ -9,7 +9,7 @@ export class SendTelemetryActivityPhase {
|
|
|
9
9
|
this.telemetry = telemetry;
|
|
10
10
|
}
|
|
11
11
|
async execute(context) {
|
|
12
|
-
if (context.
|
|
12
|
+
if (context.telemetryUpdateReason) {
|
|
13
13
|
// ensure error handling is done in the sendTelemetry method
|
|
14
14
|
const promise = this.telemetry.sendTelemetry(context);
|
|
15
15
|
if (this.config.awaitAsyncHttpRequests) {
|
|
@@ -179,4 +179,8 @@ export const RISK_ACTIVITY_ADDITIONAL_FIELDS_TO_HEADER_NAMES = {
|
|
|
179
179
|
s2s_call_reason: {
|
|
180
180
|
header: 'x-px-add-s2s-call-reason',
|
|
181
181
|
},
|
|
182
|
+
is_sensitive_route: {
|
|
183
|
+
header: 'x-px-add-is-sensitive-route',
|
|
184
|
+
convertToString: (value) => `${value}`,
|
|
185
|
+
},
|
|
182
186
|
};
|
|
@@ -78,6 +78,9 @@ export class DefaultTelemetry {
|
|
|
78
78
|
enforcer_configs: telemetryConfig,
|
|
79
79
|
},
|
|
80
80
|
};
|
|
81
|
+
if (context.requestId) {
|
|
82
|
+
activity.details.request_id = context.requestId;
|
|
83
|
+
}
|
|
81
84
|
if (context.serverData.osName) {
|
|
82
85
|
activity.details.os_name = context.serverData.osName;
|
|
83
86
|
}
|
|
@@ -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.34.0';
|
|
@@ -9,6 +9,7 @@ import { CustomParameters } from '../custom_parameters';
|
|
|
9
9
|
import { GraphQLData } from '../graphql';
|
|
10
10
|
import { RemoteConfigUpdateData, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
|
|
11
11
|
import { LogRecord } from '../logger';
|
|
12
|
+
import { TelemetryUpdateReason } from '../telemetry';
|
|
12
13
|
type RequestDataJson<Req> = Omit<RequestData<Req>, 'url' | 'request'> & {
|
|
13
14
|
url: string;
|
|
14
15
|
request: undefined;
|
|
@@ -45,6 +46,6 @@ export type ContextJson<Req = unknown, Res = unknown> = {
|
|
|
45
46
|
logger?: {
|
|
46
47
|
logs: LogRecord[];
|
|
47
48
|
};
|
|
48
|
-
|
|
49
|
+
telemetryUpdateReason?: TelemetryUpdateReason;
|
|
49
50
|
};
|
|
50
51
|
export {};
|
|
@@ -12,6 +12,7 @@ import { ILogger } from '../logger';
|
|
|
12
12
|
import { IContext, RemoteConfigUpdateData, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
|
|
13
13
|
import { ContextJson } from './ContextJson';
|
|
14
14
|
import { GraphQLData } from '../graphql';
|
|
15
|
+
import { TelemetryUpdateReason } from '../telemetry';
|
|
15
16
|
export type DefaultContextOptions = {
|
|
16
17
|
cookieParser?: ICookieParser;
|
|
17
18
|
requestIdGenerator: IRequestIdGenerator;
|
|
@@ -47,7 +48,7 @@ export declare class DefaultContext<Req, Res, Supported extends string, Added> i
|
|
|
47
48
|
enforcerStartTime?: number;
|
|
48
49
|
logger: ILogger;
|
|
49
50
|
usedCookieSecret?: string;
|
|
50
|
-
|
|
51
|
+
telemetryUpdateReason?: TelemetryUpdateReason;
|
|
51
52
|
protected _shouldSendLogs: boolean;
|
|
52
53
|
protected readonly config: IConfiguration<Req, Res, Supported, Added>;
|
|
53
54
|
protected readonly urlUtils: IUrlUtils;
|
|
@@ -12,6 +12,7 @@ import { CustomParameters } from '../custom_parameters';
|
|
|
12
12
|
import { GraphQLData } from '../graphql';
|
|
13
13
|
import { IContext, RemoteConfigUpdateData, RequestData, RiskApiData, ServerData, TlsData, TokenData } from './interfaces';
|
|
14
14
|
import { ContextJson } from './ContextJson';
|
|
15
|
+
import { TelemetryUpdateReason } from '../telemetry';
|
|
15
16
|
/**
|
|
16
17
|
* Implements the `IContext` interface based an already serialized `ContextJson`. This class does not extract data from the
|
|
17
18
|
* incoming request, but rather uses already-extracted data from the `ContextJson` (likely returned from the `DefaultContext.toJSON()`
|
|
@@ -43,7 +44,7 @@ export declare class SerializedContext<Req, Res, Supported extends string, Added
|
|
|
43
44
|
vidSource?: VidSource;
|
|
44
45
|
tokenOrigin: TokenOrigin;
|
|
45
46
|
uuid?: string;
|
|
46
|
-
|
|
47
|
+
telemetryUpdateReason?: TelemetryUpdateReason;
|
|
47
48
|
constructor(config: IConfiguration<Req, Res, Supported, Added>, contextJson: ContextJson<Req, Res>, request: IIncomingRequest<Req>, urlUtils: IUrlUtils);
|
|
48
49
|
protected createRequestData({ requestData }: ContextJson<Req, Res>, request: IIncomingRequest<Req>, urlUtils: IUrlUtils): RequestData<Req>;
|
|
49
50
|
protected createTokenData({ tokenData }: ContextJson<Req, Res>, config: IConfiguration<Req, Res, Supported, Added>): TokenData<Req, Res>;
|
|
@@ -15,6 +15,7 @@ import { GraphQLData } from '../../graphql';
|
|
|
15
15
|
import { PXHD } from '../../pxhd';
|
|
16
16
|
import { ILogger } from '../../logger';
|
|
17
17
|
import { RemoteConfigUpdateData } from './RemoteConfigUpdateData';
|
|
18
|
+
import { TelemetryUpdateReason } from '../../telemetry';
|
|
18
19
|
export interface IContext<Req, Res> {
|
|
19
20
|
/**
|
|
20
21
|
* Logger for recording messages related to the request flow.
|
|
@@ -138,7 +139,7 @@ export interface IContext<Req, Res> {
|
|
|
138
139
|
*/
|
|
139
140
|
readonly enforcerStartTime?: number;
|
|
140
141
|
/**
|
|
141
|
-
*
|
|
142
|
+
* The reason why a telemetry activity should be sent (undefined if no telemetry activity is triggered)
|
|
142
143
|
*/
|
|
143
|
-
|
|
144
|
+
telemetryUpdateReason?: TelemetryUpdateReason;
|
|
144
145
|
}
|
|
@@ -53,6 +53,7 @@ export declare const createRiskApiActivity: <Req, Res, Supported extends string,
|
|
|
53
53
|
enforcer_start_time: number;
|
|
54
54
|
raw_url?: string;
|
|
55
55
|
used_cookie_secret?: string;
|
|
56
|
+
is_sensitive_route?: boolean;
|
|
56
57
|
custom_param1?: any;
|
|
57
58
|
custom_param2?: any;
|
|
58
59
|
custom_param3?: any;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ActivityType } from '../../activities';
|
|
2
2
|
import { RemoteConfigurationParams, StaticConfigurationParams, ActiveConfigurationParams, CoreConfigurationParamsKeys } from '../../config';
|
|
3
|
+
export type TelemetryUpdateReason = 'command' | 'risk';
|
|
3
4
|
export type TelemetryActivityDetails<Req, Res, Supported extends CoreConfigurationParamsKeys, Added> = {
|
|
4
5
|
enforcer_configs: TelemetryEnforcerConfiguration<Req, Res, Supported, Added>;
|
|
5
6
|
module_version: string;
|
|
6
|
-
update_reason:
|
|
7
|
+
update_reason: TelemetryUpdateReason;
|
|
7
8
|
node_name?: string;
|
|
8
9
|
os_name?: string;
|
|
9
10
|
remote_config_id?: string;
|
|
10
11
|
remote_config_version?: number;
|
|
12
|
+
request_id?: string;
|
|
11
13
|
};
|
|
12
14
|
export type TelemetryActivity<Req, Res, Supported extends CoreConfigurationParamsKeys, Added> = {
|
|
13
15
|
type: ActivityType.ENFORCER_TELEMETRY;
|
|
@@ -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.34.0";
|