perimeterx-js-core 0.18.2 → 0.19.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/additional_activity_handler/AdditionalActivityHandlerUtils.js +1 -1
- package/lib/cjs/blocker/utils.js +1 -3
- package/lib/cjs/config/ConfigurationBase.js +98 -91
- package/lib/cjs/config/ConfigurationBuilderBase.js +8 -7
- package/lib/cjs/config/defaults/DefaultStaticConfigurationParams.js +0 -1
- package/lib/cjs/config/remote_config/DefaultRemoteConfigUpdater.js +1 -1
- package/lib/cjs/config/remote_config/RemoteConfigUtils.js +1 -1
- package/lib/cjs/context/DefaultContext.js +4 -1
- package/lib/cjs/custom_parameters/CustomParametersUtils.js +1 -1
- package/lib/cjs/telemetry/DefaultTelemetry.js +14 -4
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/cjs/utils/utils.js +25 -1
- package/lib/esm/additional_activity_handler/AdditionalActivityHandlerUtils.js +1 -1
- package/lib/esm/blocker/utils.js +1 -2
- package/lib/esm/config/ConfigurationBase.js +100 -91
- package/lib/esm/config/ConfigurationBuilderBase.js +7 -6
- package/lib/esm/config/defaults/DefaultStaticConfigurationParams.js +0 -1
- package/lib/esm/config/remote_config/DefaultRemoteConfigUpdater.js +1 -1
- package/lib/esm/config/remote_config/RemoteConfigUtils.js +1 -1
- package/lib/esm/context/DefaultContext.js +5 -2
- package/lib/esm/custom_parameters/CustomParametersUtils.js +1 -1
- package/lib/esm/telemetry/DefaultTelemetry.js +15 -5
- package/lib/esm/utils/constants.js +1 -1
- package/lib/esm/utils/utils.js +23 -0
- package/lib/types/config/ConfigurationBase.d.ts +8 -3
- package/lib/types/config/IConfiguration.d.ts +14 -6
- package/lib/types/config/params/StaticConfigurationParams.d.ts +0 -1
- package/lib/types/telemetry/model/TelemetryActivity.d.ts +7 -2
- package/lib/types/utils/constants.d.ts +1 -1
- package/lib/types/utils/utils.d.ts +1 -0
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ export var CustomParametersUtils;
|
|
|
4
4
|
CustomParametersUtils.createCustomParameters = async (config, context) => {
|
|
5
5
|
if (config.enrichCustomParameters && typeof config.enrichCustomParameters === 'function') {
|
|
6
6
|
try {
|
|
7
|
-
const parameters = await config.enrichCustomParameters(config.
|
|
7
|
+
const parameters = await config.enrichCustomParameters(config.getActiveConfig(), context.requestData.request.getUnderlyingRequest());
|
|
8
8
|
return CustomParametersUtils.normalizeCustomParams(parameters);
|
|
9
9
|
}
|
|
10
10
|
catch (e) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AUTHORIZATION_HEADER_NAME, CONTENT_TYPE_HEADER_NAME, ContentType, HttpMethod, OutgoingRequestImpl, } from '../http';
|
|
2
2
|
import { ActivityType } from '../activities';
|
|
3
|
-
import { getAuthorizationHeader, removeSensitiveFields, transferExistingProperties, DefaultTimestampHmacHeaderValidator, } from '../utils';
|
|
3
|
+
import { getAuthorizationHeader, removeSensitiveFields, transferExistingProperties, DefaultTimestampHmacHeaderValidator, telemetryConfigReplacer, } from '../utils';
|
|
4
4
|
import { TELEMETRY_ENDPOINT, TELEMETRY_HEADER_NAME, TELEMETRY_UPDATE_REASON } from './constants';
|
|
5
5
|
export class DefaultTelemetry {
|
|
6
6
|
config;
|
|
@@ -49,16 +49,26 @@ export class DefaultTelemetry {
|
|
|
49
49
|
[AUTHORIZATION_HEADER_NAME]: [getAuthorizationHeader(this.config.authToken)],
|
|
50
50
|
};
|
|
51
51
|
const activity = this.createTelemetryActivity(context);
|
|
52
|
-
|
|
52
|
+
context.logger.debug(`created telemetry activity config - ${JSON.stringify(activity.details.enforcer_configs, telemetryConfigReplacer)}`);
|
|
53
|
+
return new OutgoingRequestImpl({
|
|
54
|
+
url: url,
|
|
55
|
+
method: method,
|
|
56
|
+
headers: headers,
|
|
57
|
+
body: JSON.stringify(activity, telemetryConfigReplacer),
|
|
58
|
+
});
|
|
53
59
|
}
|
|
54
60
|
createTelemetryActivity(context) {
|
|
55
61
|
const SENSITIVE_CONFIG_FIELDS = [
|
|
56
62
|
'px_auth_token',
|
|
57
63
|
'px_cookie_secret',
|
|
58
64
|
'px_logger_auth_token',
|
|
65
|
+
'px_remote_config_auth_token',
|
|
59
66
|
];
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
const telemetryConfig = {
|
|
68
|
+
active_config: removeSensitiveFields(this.config.getActiveConfig(), SENSITIVE_CONFIG_FIELDS),
|
|
69
|
+
static_config: removeSensitiveFields(this.config.getStaticConfig(), SENSITIVE_CONFIG_FIELDS),
|
|
70
|
+
remote_config: removeSensitiveFields(this.config.getRemoteConfig(), SENSITIVE_CONFIG_FIELDS),
|
|
71
|
+
};
|
|
62
72
|
const activity = {
|
|
63
73
|
type: ActivityType.ENFORCER_TELEMETRY,
|
|
64
74
|
timestamp: Date.now(),
|
|
@@ -66,7 +76,7 @@ export class DefaultTelemetry {
|
|
|
66
76
|
details: {
|
|
67
77
|
update_reason: TELEMETRY_UPDATE_REASON,
|
|
68
78
|
module_version: this.config.moduleVersion,
|
|
69
|
-
enforcer_configs:
|
|
79
|
+
enforcer_configs: telemetryConfig,
|
|
70
80
|
},
|
|
71
81
|
};
|
|
72
82
|
transferExistingProperties(context.serverData, activity.details, {
|
|
@@ -10,4 +10,4 @@ export const PUSH_DATA_HMAC_HEADER_NAME = 'x-px-pushdata';
|
|
|
10
10
|
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]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
13
|
-
export const CORE_MODULE_VERSION = 'JS Core 0.
|
|
13
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.19.0';
|
package/lib/esm/utils/utils.js
CHANGED
|
@@ -115,3 +115,26 @@ export const algoToCryptoString = (algo) => {
|
|
|
115
115
|
return 'sha256';
|
|
116
116
|
}
|
|
117
117
|
};
|
|
118
|
+
// Hash based on https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
|
|
119
|
+
const toHash = (string) => {
|
|
120
|
+
let hash = 0;
|
|
121
|
+
if (string.length === 0) {
|
|
122
|
+
return hash.toString();
|
|
123
|
+
}
|
|
124
|
+
for (let i = 0; i < string.length; i++) {
|
|
125
|
+
const char = string.charCodeAt(i);
|
|
126
|
+
hash = (hash << 5) - hash + char;
|
|
127
|
+
hash = hash & hash;
|
|
128
|
+
}
|
|
129
|
+
return hash.toString();
|
|
130
|
+
};
|
|
131
|
+
export const telemetryConfigReplacer = (key, value) => {
|
|
132
|
+
if (value instanceof RegExp) {
|
|
133
|
+
return '_REGEXP ' + value.toString();
|
|
134
|
+
}
|
|
135
|
+
if (value instanceof Function) {
|
|
136
|
+
return '_FUNCTION_HASH' + toHash(value.toString()); // NOTE: Do not log functions
|
|
137
|
+
}
|
|
138
|
+
else
|
|
139
|
+
return value;
|
|
140
|
+
};
|
|
@@ -8,7 +8,10 @@ import { ModuleMode } from '../utils';
|
|
|
8
8
|
import { CredentialEndpointConfiguration, CredentialIntelligenceVersion, CustomLoginSuccessfulCallback, LoginSuccessfulReportingMethod } from '../products';
|
|
9
9
|
import { CustomRequestFunction } from './CustomRequestFunction';
|
|
10
10
|
export declare abstract class ConfigurationBase<Req, Res, ParamsType extends ConfigurationParams<Req, Res> = ConfigurationParams<Req, Res>> implements IConfiguration<Req, Res, ParamsType> {
|
|
11
|
-
protected
|
|
11
|
+
protected activeConfigParams: ParamsType;
|
|
12
|
+
protected readonly staticConfigParams: ParamsType;
|
|
13
|
+
protected remoteConfigParams: ParamsType;
|
|
14
|
+
protected readonly defaultConfigParams: ParamsType;
|
|
12
15
|
protected internalLogger: ILogger;
|
|
13
16
|
protected abstract getModuleVersion(): string;
|
|
14
17
|
protected constructor(params: ParamsType, defaultParams?: Partial<ParamsType>);
|
|
@@ -18,7 +21,10 @@ export declare abstract class ConfigurationBase<Req, Res, ParamsType extends Con
|
|
|
18
21
|
protected isValidConfigValue(params: ParamsType, defaultParams: ParamsType, key: keyof ParamsType): boolean;
|
|
19
22
|
protected getDefaultConfigurationValue<K extends keyof ParamsType, V extends ParamsType[K]>(params: ParamsType, defaultParams: ParamsType, key: K): V;
|
|
20
23
|
protected createInternalLogger(loggerSeverity: LoggerSeverity): ILogger;
|
|
21
|
-
|
|
24
|
+
addRemoteConfig(remoteConfigParams: ParamsType): void;
|
|
25
|
+
getActiveConfig(): ParamsType;
|
|
26
|
+
getStaticConfig(): ParamsType;
|
|
27
|
+
getRemoteConfig(): ParamsType;
|
|
22
28
|
get moduleVersion(): string;
|
|
23
29
|
get logger(): ILogger;
|
|
24
30
|
get appId(): string;
|
|
@@ -97,7 +103,6 @@ export declare abstract class ConfigurationBase<Req, Res, ParamsType extends Con
|
|
|
97
103
|
get ciDefaultLoginSuccessfulHeaderValue(): string;
|
|
98
104
|
get ciDefaultLoginSuccessfulCustomCallback(): CustomLoginSuccessfulCallback<Res>;
|
|
99
105
|
get remoteConfigAuthToken(): string;
|
|
100
|
-
get remoteConfigSecret(): string;
|
|
101
106
|
get remoteConfigVersion(): number;
|
|
102
107
|
get remoteConfigId(): string;
|
|
103
108
|
get remoteConfigRetryIntervalMs(): number;
|
|
@@ -2,7 +2,7 @@ import { ModuleMode } from '../utils';
|
|
|
2
2
|
import { ILogger, LoggerSeverity } from '../logger';
|
|
3
3
|
import { CustomParametersFunction } from '../custom_parameters';
|
|
4
4
|
import { AdditionalActivityHandler } from '../additional_activity_handler';
|
|
5
|
-
import { ConfigurationParams } from './params';
|
|
5
|
+
import { ConfigurationParams, RemoteConfigurationParams } from './params';
|
|
6
6
|
import { CustomPreflightHandler, CustomBlockResponseHeadersHandler } from '../cors';
|
|
7
7
|
import { CredentialEndpointConfiguration, CredentialIntelligenceVersion, CustomLoginSuccessfulCallback, LoginSuccessfulReportingMethod } from '../products';
|
|
8
8
|
import { CustomRequestFunction } from './CustomRequestFunction';
|
|
@@ -333,10 +333,6 @@ export interface IConfiguration<Req, Res, ParamsType extends ConfigurationParams
|
|
|
333
333
|
* The authentication token for the remote configuration service.
|
|
334
334
|
*/
|
|
335
335
|
readonly remoteConfigAuthToken: string;
|
|
336
|
-
/**
|
|
337
|
-
* The secret used for validating remote config update requests.
|
|
338
|
-
*/
|
|
339
|
-
readonly remoteConfigSecret: string;
|
|
340
336
|
/**
|
|
341
337
|
* The ID of the remote configuration.
|
|
342
338
|
*/
|
|
@@ -364,5 +360,17 @@ export interface IConfiguration<Req, Res, ParamsType extends ConfigurationParams
|
|
|
364
360
|
/**
|
|
365
361
|
* Returns an object representation of the current configuration.
|
|
366
362
|
*/
|
|
367
|
-
|
|
363
|
+
getActiveConfig(): ParamsType;
|
|
364
|
+
/**
|
|
365
|
+
* Returns an object representation of the static configuration.
|
|
366
|
+
*/
|
|
367
|
+
getStaticConfig(): ParamsType;
|
|
368
|
+
/**
|
|
369
|
+
* Returns an object representation of the remote configuration.
|
|
370
|
+
*/
|
|
371
|
+
getRemoteConfig(): ParamsType;
|
|
372
|
+
/**
|
|
373
|
+
* Adds a remote configuration to the current configuration.
|
|
374
|
+
*/
|
|
375
|
+
addRemoteConfig(remoteConfigurationParams: RemoteConfigurationParams): void;
|
|
368
376
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ActivityType } from '../../activities';
|
|
2
|
-
import { ConfigurationParams } from '../../config';
|
|
2
|
+
import { CommonConfigurationParams, ConfigurationParams, RemoteConfigurationParams, StaticConfigurationParams } from '../../config';
|
|
3
3
|
export type TelemetryActivityDetails = {
|
|
4
|
-
enforcer_configs:
|
|
4
|
+
enforcer_configs: TelemetryEnforcerConfiguration;
|
|
5
5
|
module_version: string;
|
|
6
6
|
update_reason: 'command';
|
|
7
7
|
node_name?: string;
|
|
@@ -13,3 +13,8 @@ export type TelemetryActivity = {
|
|
|
13
13
|
px_app_id: string;
|
|
14
14
|
details: TelemetryActivityDetails;
|
|
15
15
|
};
|
|
16
|
+
export type TelemetryEnforcerConfiguration = {
|
|
17
|
+
active_config: ConfigurationParams<unknown, unknown>;
|
|
18
|
+
static_config: StaticConfigurationParams & CommonConfigurationParams<unknown, unknown>;
|
|
19
|
+
remote_config: RemoteConfigurationParams & CommonConfigurationParams<unknown, unknown>;
|
|
20
|
+
};
|
|
@@ -10,4 +10,4 @@ export declare const PUSH_DATA_HMAC_HEADER_NAME = "x-px-pushdata";
|
|
|
10
10
|
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
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.
|
|
13
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.19.0";
|
|
@@ -20,3 +20,4 @@ export declare const getPropertyFromObject: <T>(object: any, ...keys: Array<stri
|
|
|
20
20
|
export declare const sleep: (ms: number) => Promise<void>;
|
|
21
21
|
export declare const algoToSubtleCryptoString: (algo: Algorithm) => string;
|
|
22
22
|
export declare const algoToCryptoString: (algo: Algorithm) => string;
|
|
23
|
+
export declare const telemetryConfigReplacer: (key: string, value: any) => string;
|