perimeterx-js-core 0.18.2 → 0.20.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.
Files changed (49) hide show
  1. package/lib/cjs/additional_activity_handler/AdditionalActivityHandlerUtils.js +1 -1
  2. package/lib/cjs/blocker/utils.js +1 -3
  3. package/lib/cjs/config/ConfigurationBase.js +112 -91
  4. package/lib/cjs/config/ConfigurationBuilderBase.js +8 -7
  5. package/lib/cjs/config/defaults/DefaultCommonConfigurationParams.js +3 -1
  6. package/lib/cjs/config/defaults/DefaultStaticConfigurationParams.js +0 -1
  7. package/lib/cjs/config/remote_config/DefaultRemoteConfigUpdater.js +1 -1
  8. package/lib/cjs/config/remote_config/RemoteConfigUtils.js +1 -1
  9. package/lib/cjs/context/DefaultContext.js +4 -1
  10. package/lib/cjs/custom_parameters/CustomParametersUtils.js +1 -1
  11. package/lib/cjs/graphql/DefaultGraphQLParser.js +155 -30
  12. package/lib/cjs/graphql/ExtractGraphQLKeywordsFunction.js +2 -0
  13. package/lib/cjs/graphql/index.js +1 -0
  14. package/lib/cjs/telemetry/DefaultTelemetry.js +14 -4
  15. package/lib/cjs/utils/constants.js +1 -1
  16. package/lib/cjs/utils/utils.js +25 -1
  17. package/lib/esm/additional_activity_handler/AdditionalActivityHandlerUtils.js +1 -1
  18. package/lib/esm/blocker/utils.js +1 -2
  19. package/lib/esm/config/ConfigurationBase.js +106 -91
  20. package/lib/esm/config/ConfigurationBuilderBase.js +7 -6
  21. package/lib/esm/config/defaults/DefaultCommonConfigurationParams.js +3 -1
  22. package/lib/esm/config/defaults/DefaultStaticConfigurationParams.js +0 -1
  23. package/lib/esm/config/remote_config/DefaultRemoteConfigUpdater.js +1 -1
  24. package/lib/esm/config/remote_config/RemoteConfigUtils.js +1 -1
  25. package/lib/esm/context/DefaultContext.js +5 -2
  26. package/lib/esm/custom_parameters/CustomParametersUtils.js +1 -1
  27. package/lib/esm/graphql/DefaultGraphQLParser.js +109 -25
  28. package/lib/esm/graphql/ExtractGraphQLKeywordsFunction.js +1 -0
  29. package/lib/esm/graphql/index.js +1 -0
  30. package/lib/esm/telemetry/DefaultTelemetry.js +15 -5
  31. package/lib/esm/utils/constants.js +1 -1
  32. package/lib/esm/utils/utils.js +23 -0
  33. package/lib/types/activities/utils.d.ts +60 -30
  34. package/lib/types/blocker/utils.d.ts +6 -3
  35. package/lib/types/config/ConfigurationBase.d.ts +12 -4
  36. package/lib/types/config/IConfiguration.d.ts +28 -8
  37. package/lib/types/config/params/CommonConfigurationParams.d.ts +4 -1
  38. package/lib/types/config/params/StaticConfigurationParams.d.ts +0 -1
  39. package/lib/types/graphql/DefaultGraphQLParser.d.ts +20 -11
  40. package/lib/types/graphql/ExtractGraphQLKeywordsFunction.d.ts +1 -0
  41. package/lib/types/graphql/index.d.ts +1 -0
  42. package/lib/types/graphql/model/GraphQLData.d.ts +2 -1
  43. package/lib/types/monitored_request/MonitoredRequestUtils.d.ts +18 -9
  44. package/lib/types/pxhd/PXHDUtils.d.ts +12 -6
  45. package/lib/types/sensitive_request/SensitiveRequestUtils.d.ts +12 -6
  46. package/lib/types/telemetry/model/TelemetryActivity.d.ts +7 -2
  47. package/lib/types/utils/constants.d.ts +1 -1
  48. package/lib/types/utils/utils.d.ts +1 -0
  49. package/package.json +1 -1
@@ -54,21 +54,22 @@ var ConfigurationBuilderBase = /** @class */ (function () {
54
54
  }
55
55
  ConfigurationBuilderBase.prototype.build = function (params) {
56
56
  return __awaiter(this, void 0, void 0, function () {
57
- var staticConfig, remoteConfigParams;
57
+ var config, remoteConfigParams;
58
58
  return __generator(this, function (_a) {
59
59
  switch (_a.label) {
60
60
  case 0:
61
- staticConfig = this.createConfiguration(params);
62
- if (!staticConfig.remoteConfigAuthToken) {
63
- return [2 /*return*/, staticConfig];
61
+ config = this.createConfiguration(params);
62
+ if (!config.remoteConfigAuthToken) {
63
+ return [2 /*return*/, config];
64
64
  }
65
- return [4 /*yield*/, this.getRemoteConfigParams(staticConfig)];
65
+ return [4 /*yield*/, this.getRemoteConfigParams(config)];
66
66
  case 1:
67
67
  remoteConfigParams = _a.sent();
68
68
  if (!remoteConfigParams) {
69
- return [2 /*return*/, staticConfig];
69
+ return [2 /*return*/, config];
70
70
  }
71
- return [2 /*return*/, this.createConfiguration(__assign(__assign({}, params), remoteConfigParams))];
71
+ config.addRemoteConfig(remoteConfigParams);
72
+ return [2 /*return*/, config];
72
73
  }
73
74
  });
74
75
  });
@@ -19,7 +19,7 @@ exports.DEFAULT_COMMON_CONFIGURATION_PARAMS = {
19
19
  px_advanced_blocking_response_enabled: true,
20
20
  px_max_activity_batch_size: 0,
21
21
  px_batch_activities_timeout_ms: 1000,
22
- px_bypass_monitor_header: '',
22
+ px_bypass_monitor_header: 'x-px-block',
23
23
  px_enforced_routes: [],
24
24
  px_first_party_enabled: true,
25
25
  px_custom_first_party_prefix: '',
@@ -97,6 +97,7 @@ exports.DEFAULT_COMMON_CONFIGURATION_PARAMS = {
97
97
  px_custom_logo: '',
98
98
  px_graphql_enabled: true,
99
99
  px_graphql_routes: ['/graphql'],
100
+ px_graphql_keywords: [],
100
101
  px_sensitive_graphql_operation_names: [],
101
102
  px_sensitive_graphql_operation_types: [],
102
103
  px_enrich_custom_parameters: null,
@@ -118,4 +119,5 @@ exports.DEFAULT_COMMON_CONFIGURATION_PARAMS = {
118
119
  px_custom_is_monitored_request: null,
119
120
  px_custom_is_enforced_request: null,
120
121
  px_custom_is_filtered_request: null,
122
+ px_extract_graphql_keywords: null,
121
123
  };
@@ -7,5 +7,4 @@ exports.DEFAULT_STATIC_CONFIGURATION_PARAMS = {
7
7
  px_cookie_secret: '',
8
8
  px_logger_auth_token: '',
9
9
  px_remote_config_auth_token: '',
10
- px_remote_config_secret: '',
11
10
  };
@@ -46,7 +46,7 @@ var DefaultRemoteConfigUpdater = /** @class */ (function () {
46
46
  this.storageClient = options.storageClient;
47
47
  this.timestampHmacHeaderValidator =
48
48
  options.timestampHmacHeaderValidator ||
49
- new utils_1.DefaultTimestampHmacHeaderValidator(config, config.remoteConfigSecret, options.base64Utils, options.hmacUtils);
49
+ new utils_1.DefaultTimestampHmacHeaderValidator(config, config.remoteConfigAuthToken, options.base64Utils, options.hmacUtils);
50
50
  }
51
51
  DefaultRemoteConfigUpdater.prototype.isUpdateRemoteConfigRequest = function (context) {
52
52
  return context.isRemoteConfigUpdateRequest;
@@ -7,7 +7,7 @@ var constants_1 = require("./constants");
7
7
  var RemoteConfigUtils;
8
8
  (function (RemoteConfigUtils) {
9
9
  RemoteConfigUtils.isRemoteConfigUpdateRequest = function (request) {
10
- return request.method === http_1.HttpMethod.PATCH &&
10
+ return request.method === http_1.HttpMethod.POST &&
11
11
  request.headers.get(utils_1.PUSH_DATA_FEATURE_HEADER_NAME) === constants_1.REMOTE_CONFIG_PUSH_DATA_FEATURE_NAME &&
12
12
  !!request.headers.get(utils_1.PUSH_DATA_HMAC_HEADER_NAME);
13
13
  };
@@ -119,7 +119,10 @@ var DefaultContext = /** @class */ (function () {
119
119
  return request.headers.get(utils_1.X_PX_AUTHORIZATION_HEADER_NAME) ? risk_token_1.TokenOrigin.HEADER : risk_token_1.TokenOrigin.COOKIE;
120
120
  };
121
121
  DefaultContext.prototype.setCookiesOnContext = function () {
122
- this.vid = this.requestData.cookies[utils_1.PXVID_COOKIE_NAME];
122
+ var vidValue = this.requestData.cookies[utils_1.PXVID_COOKIE_NAME];
123
+ if ((0, utils_1.isValidUuid)(vidValue)) {
124
+ this.vid = vidValue;
125
+ }
123
126
  var pxhdCookie = this.requestData.cookies[utils_1.PXHD_COOKIE_NAME];
124
127
  if (pxhdCookie) {
125
128
  this.pxhd = {
@@ -50,7 +50,7 @@ var CustomParametersUtils;
50
50
  _a.label = 1;
51
51
  case 1:
52
52
  _a.trys.push([1, 3, , 4]);
53
- return [4 /*yield*/, config.enrichCustomParameters(config.toParams(), context.requestData.request.getUnderlyingRequest())];
53
+ return [4 /*yield*/, config.enrichCustomParameters(config.getActiveConfig(), context.requestData.request.getUnderlyingRequest())];
54
54
  case 2:
55
55
  parameters = _a.sent();
56
56
  return [2 /*return*/, CustomParametersUtils.normalizeCustomParams(parameters)];
@@ -42,13 +42,14 @@ var http_1 = require("../http");
42
42
  var model_1 = require("./model");
43
43
  var DefaultGraphQLParser = /** @class */ (function () {
44
44
  function DefaultGraphQLParser(config) {
45
- this.graphqlRoutes = config.graphqlRoutes;
46
- this.sensitiveOperationNames = config.sensitiveGraphqlOperationNames;
47
- this.sensitiveOperationTypes = config.sensitiveGraphqlOperationTypes;
45
+ this.config = config;
46
+ this.maxCharactersInGraphqlKeyword = 100;
47
+ this.maxGraphqlKeywordCount = 500;
48
48
  }
49
49
  DefaultGraphQLParser.prototype.isGraphQLRequest = function (_a) {
50
50
  var requestData = _a.requestData;
51
- return (requestData.method === http_1.HttpMethod.POST && (0, utils_1.isRouteInPatterns)(requestData.url.pathname, this.graphqlRoutes));
51
+ return (requestData.method === http_1.HttpMethod.POST &&
52
+ (0, utils_1.isRouteInPatterns)(requestData.url.pathname, this.config.graphqlRoutes));
52
53
  };
53
54
  DefaultGraphQLParser.prototype.parseGraphQLRequest = function (context) {
54
55
  return __awaiter(this, void 0, void 0, function () {
@@ -56,7 +57,7 @@ var DefaultGraphQLParser = /** @class */ (function () {
56
57
  return __generator(this, function (_a) {
57
58
  switch (_a.label) {
58
59
  case 0:
59
- _a.trys.push([0, 2, , 3]);
60
+ _a.trys.push([0, 3, , 4]);
60
61
  requestData = context.requestData;
61
62
  return [4 /*yield*/, this.getGraphQLOperationsFromBody(requestData.request, context)];
62
63
  case 1:
@@ -65,18 +66,20 @@ var DefaultGraphQLParser = /** @class */ (function () {
65
66
  context.logger.debug('unable to get graphql operations from request body');
66
67
  return [2 /*return*/, null];
67
68
  }
68
- data = this.parseGraphQLOperations(graphQLOperations);
69
+ return [4 /*yield*/, this.parseGraphQLOperations(graphQLOperations, context)];
70
+ case 2:
71
+ data = _a.sent();
69
72
  if (!data || data.length === 0) {
70
73
  context.logger.debug('unable to parse graphql operations');
71
74
  return [2 /*return*/, null];
72
75
  }
73
76
  context.logger.debug("".concat(data.length, " graphql operation").concat(data.length === 1 ? '' : 's', " parsed successfully"));
74
77
  return [2 /*return*/, data];
75
- case 2:
78
+ case 3:
76
79
  e_1 = _a.sent();
77
80
  context.logger.debug("unable to parse graphql request: ".concat(e_1));
78
81
  return [2 /*return*/, null];
79
- case 3: return [2 /*return*/];
82
+ case 4: return [2 /*return*/];
80
83
  }
81
84
  });
82
85
  });
@@ -92,6 +95,7 @@ var DefaultGraphQLParser = /** @class */ (function () {
92
95
  case 1:
93
96
  body = _a.sent();
94
97
  if (!body) {
98
+ context.logger.debug("received empty graphql body when calling .json()");
95
99
  return [2 /*return*/, null];
96
100
  }
97
101
  return [2 /*return*/, Array.isArray(body) ? body : [body]];
@@ -104,19 +108,31 @@ var DefaultGraphQLParser = /** @class */ (function () {
104
108
  });
105
109
  });
106
110
  };
107
- DefaultGraphQLParser.prototype.parseGraphQLOperations = function (operations) {
108
- var _this = this;
109
- return operations.map(function (operation) { return _this.parseGraphQlOperation(operation); }).filter(function (x) { return x; });
111
+ DefaultGraphQLParser.prototype.parseGraphQLOperations = function (operations, context) {
112
+ return __awaiter(this, void 0, void 0, function () {
113
+ var data;
114
+ var _this = this;
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0: return [4 /*yield*/, Promise.all(operations.map(function (operation) { return _this.parseGraphQLOperation(operation, context); }))];
118
+ case 1:
119
+ data = _a.sent();
120
+ return [2 /*return*/, data.filter(Boolean)];
121
+ }
122
+ });
123
+ });
110
124
  };
111
- DefaultGraphQLParser.prototype.parseGraphQlOperation = function (operation) {
125
+ DefaultGraphQLParser.prototype.parseGraphQLOperation = function (operation, context) {
112
126
  if (!operation.query || typeof operation.query !== 'string') {
127
+ context.logger.debug('no query found');
113
128
  return null;
114
129
  }
115
130
  var operationNameToTypeMap = this.getOperationNameToTypeMap(operation.query);
116
131
  if (!operationNameToTypeMap) {
132
+ context.logger.debug('operationNameToTypeMap returned null');
117
133
  return null;
118
134
  }
119
- return this.getGraphQLData(operationNameToTypeMap, operation);
135
+ return this.getGraphQLData(operationNameToTypeMap, operation, context);
120
136
  };
121
137
  DefaultGraphQLParser.prototype.getOperationNameToTypeMap = function (query) {
122
138
  var operationTypesString = Object.values(model_1.GraphQLOperationType).join('|');
@@ -136,28 +152,128 @@ var DefaultGraphQLParser = /** @class */ (function () {
136
152
  }
137
153
  return map;
138
154
  };
139
- DefaultGraphQLParser.prototype.getGraphQLData = function (operationNameToTypeMap, operation) {
140
- var name = operation.operationName ||
141
- (Object.keys(operationNameToTypeMap).length === 1 ? Object.keys(operationNameToTypeMap)[0] : undefined);
142
- var type = operationNameToTypeMap[name];
143
- if (!type && /^\s*{/.test(operation.query)) {
144
- type = model_1.GraphQLOperationType.QUERY;
155
+ DefaultGraphQLParser.prototype.getGraphQLData = function (operationNameToTypeMap, operation, context) {
156
+ return __awaiter(this, void 0, void 0, function () {
157
+ var name, type, data, keywords;
158
+ return __generator(this, function (_a) {
159
+ switch (_a.label) {
160
+ case 0:
161
+ name = this.getOperationName(operationNameToTypeMap, operation);
162
+ type = this.getOperationType(operation, name, operationNameToTypeMap);
163
+ if (!type) {
164
+ return [2 /*return*/, null];
165
+ }
166
+ data = { type: type };
167
+ if (name) {
168
+ data.name = name;
169
+ }
170
+ return [4 /*yield*/, this.getQueryKeywords(operation.query, context)];
171
+ case 1:
172
+ keywords = _a.sent();
173
+ if (keywords) {
174
+ data.keywords = this.cleanKeywords(keywords);
175
+ }
176
+ if (this.isSensitiveOperation(name, type, keywords)) {
177
+ data.sensitive = true;
178
+ }
179
+ if (operation.variables && typeof operation.variables === 'object') {
180
+ data.variables = this.extractGraphQLVariableNames(operation.variables);
181
+ }
182
+ return [2 /*return*/, data];
183
+ }
184
+ });
185
+ });
186
+ };
187
+ DefaultGraphQLParser.prototype.getOperationType = function (operation, operationName, operationNameToTypeMap) {
188
+ if (operationName && operationNameToTypeMap[operationName]) {
189
+ return operationNameToTypeMap[operationName];
145
190
  }
146
- if (!type) {
147
- return null;
191
+ if (this.isGraphqlQueryShorthand(operation.query)) {
192
+ return model_1.GraphQLOperationType.QUERY;
148
193
  }
149
- var data = { name: name, type: type };
150
- if (this.isSensitiveOperation(name, type)) {
151
- data.sensitive = true;
194
+ var match = operation.query.match(new RegExp("^\\s*(".concat(Object.values(model_1.GraphQLOperationType).join('|'), ")(?:\\s|{)")));
195
+ if ((match === null || match === void 0 ? void 0 : match[1]) && !operationName) {
196
+ return match[1];
152
197
  }
153
- if (operation.variables && typeof operation.variables === 'object') {
154
- data.variables = this.extractGraphQLVariableNames(operation.variables);
198
+ return null;
199
+ };
200
+ DefaultGraphQLParser.prototype.isGraphqlQueryShorthand = function (query) {
201
+ return /^\s*{/.test(query);
202
+ };
203
+ DefaultGraphQLParser.prototype.getOperationName = function (operationNameToTypeMap, operation) {
204
+ return (operation.operationName ||
205
+ (Object.keys(operationNameToTypeMap).length === 1 ? Object.keys(operationNameToTypeMap)[0] : undefined));
206
+ };
207
+ DefaultGraphQLParser.prototype.getQueryKeywords = function (query, context) {
208
+ var _a;
209
+ return __awaiter(this, void 0, void 0, function () {
210
+ var keywords;
211
+ return __generator(this, function (_b) {
212
+ switch (_b.label) {
213
+ case 0:
214
+ if (!(this.config.extractGraphQLKeywords && typeof this.config.extractGraphQLKeywords === 'function')) return [3 /*break*/, 2];
215
+ return [4 /*yield*/, this.getQueryKeywordsFromCustomFunction(query, context)];
216
+ case 1:
217
+ keywords = _b.sent();
218
+ if (Array.isArray(keywords)) {
219
+ return [2 /*return*/, keywords];
220
+ }
221
+ _b.label = 2;
222
+ case 2:
223
+ if (((_a = this.config.graphqlKeywords) === null || _a === void 0 ? void 0 : _a.length) > 0) {
224
+ return [2 /*return*/, this.getQueryKeywordsFromArray(query, context)];
225
+ }
226
+ return [2 /*return*/, null];
227
+ }
228
+ });
229
+ });
230
+ };
231
+ DefaultGraphQLParser.prototype.cleanKeywords = function (keywords) {
232
+ var _this = this;
233
+ return keywords
234
+ .slice(0, this.maxGraphqlKeywordCount)
235
+ .map(function (kw) { return kw.trim().substring(0, _this.maxCharactersInGraphqlKeyword); });
236
+ };
237
+ DefaultGraphQLParser.prototype.getQueryKeywordsFromCustomFunction = function (query, context) {
238
+ return __awaiter(this, void 0, void 0, function () {
239
+ return __generator(this, function (_a) {
240
+ try {
241
+ return [2 /*return*/, this.config.extractGraphQLKeywords(query)];
242
+ }
243
+ catch (e) {
244
+ context.logger.debug("unable to extract graphql keywords via custom function: ".concat(e));
245
+ return [2 /*return*/, null];
246
+ }
247
+ return [2 /*return*/];
248
+ });
249
+ });
250
+ };
251
+ DefaultGraphQLParser.prototype.getQueryKeywordsFromArray = function (query, context) {
252
+ var _this = this;
253
+ var keywords = [];
254
+ try {
255
+ this.config.graphqlKeywords.forEach(function (keyword) {
256
+ var pattern = _this.toGlobalRegExp(keyword);
257
+ var matchGroup = query.match(pattern);
258
+ if (!matchGroup) {
259
+ return;
260
+ }
261
+ keywords = keywords.concat(matchGroup);
262
+ });
263
+ }
264
+ catch (e) {
265
+ context.logger.debug("unable to extract graphql keywords via array: ".concat(e));
266
+ return null;
155
267
  }
156
- return data;
268
+ return keywords;
157
269
  };
158
- DefaultGraphQLParser.prototype.isSensitiveOperation = function (operationName, operationType) {
159
- return (this.sensitiveOperationTypes.some(function (type) { return type === operationType; }) ||
160
- this.sensitiveOperationNames.some(function (name) { return name === operationName; }));
270
+ DefaultGraphQLParser.prototype.isSensitiveOperation = function (operationName, operationType, keywords) {
271
+ var _this = this;
272
+ return (this.config.sensitiveGraphqlOperationTypes.some(function (type) { return type === operationType; }) ||
273
+ this.config.sensitiveGraphqlOperationNames.some(function (name) {
274
+ var pattern = _this.toGlobalRegExp(name);
275
+ return pattern.test(operationName) || (keywords === null || keywords === void 0 ? void 0 : keywords.some(function (kw) { return pattern.test(kw); }));
276
+ }));
161
277
  };
162
278
  DefaultGraphQLParser.prototype.extractGraphQLVariableNames = function (variables) {
163
279
  var processVariables = function (variablesObj, prefix) {
@@ -174,6 +290,15 @@ var DefaultGraphQLParser = /** @class */ (function () {
174
290
  };
175
291
  return processVariables(variables, '');
176
292
  };
293
+ DefaultGraphQLParser.prototype.toGlobalRegExp = function (pattern) {
294
+ if (typeof pattern === 'string') {
295
+ return new RegExp(pattern, 'g');
296
+ }
297
+ if (pattern.global) {
298
+ return pattern;
299
+ }
300
+ return new RegExp(pattern, pattern.flags + 'g');
301
+ };
177
302
  return DefaultGraphQLParser;
178
303
  }());
179
304
  exports.DefaultGraphQLParser = DefaultGraphQLParser;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./model"), exports);
18
18
  __exportStar(require("./IGraphQLParser"), exports);
19
19
  __exportStar(require("./DefaultGraphQLParser"), exports);
20
+ __exportStar(require("./ExtractGraphQLKeywordsFunction"), exports);
@@ -127,16 +127,26 @@ var DefaultTelemetry = /** @class */ (function () {
127
127
  _a[http_1.AUTHORIZATION_HEADER_NAME] = [(0, utils_1.getAuthorizationHeader)(this.config.authToken)],
128
128
  _a);
129
129
  var activity = this.createTelemetryActivity(context);
130
- return new http_1.OutgoingRequestImpl({ url: url, method: method, headers: headers, body: JSON.stringify(activity) });
130
+ context.logger.debug("created telemetry activity config - ".concat(JSON.stringify(activity.details.enforcer_configs, utils_1.telemetryConfigReplacer)));
131
+ return new http_1.OutgoingRequestImpl({
132
+ url: url,
133
+ method: method,
134
+ headers: headers,
135
+ body: JSON.stringify(activity, utils_1.telemetryConfigReplacer),
136
+ });
131
137
  };
132
138
  DefaultTelemetry.prototype.createTelemetryActivity = function (context) {
133
139
  var SENSITIVE_CONFIG_FIELDS = [
134
140
  'px_auth_token',
135
141
  'px_cookie_secret',
136
142
  'px_logger_auth_token',
143
+ 'px_remote_config_auth_token',
137
144
  ];
138
- var config = this.config.toParams();
139
- config = (0, utils_1.removeSensitiveFields)(config, SENSITIVE_CONFIG_FIELDS);
145
+ var telemetryConfig = {
146
+ active_config: (0, utils_1.removeSensitiveFields)(this.config.getActiveConfig(), SENSITIVE_CONFIG_FIELDS),
147
+ static_config: (0, utils_1.removeSensitiveFields)(this.config.getStaticConfig(), SENSITIVE_CONFIG_FIELDS),
148
+ remote_config: (0, utils_1.removeSensitiveFields)(this.config.getRemoteConfig(), SENSITIVE_CONFIG_FIELDS),
149
+ };
140
150
  var activity = {
141
151
  type: activities_1.ActivityType.ENFORCER_TELEMETRY,
142
152
  timestamp: Date.now(),
@@ -144,7 +154,7 @@ var DefaultTelemetry = /** @class */ (function () {
144
154
  details: {
145
155
  update_reason: constants_1.TELEMETRY_UPDATE_REASON,
146
156
  module_version: this.config.moduleVersion,
147
- enforcer_configs: config,
157
+ enforcer_configs: telemetryConfig,
148
158
  },
149
159
  };
150
160
  (0, utils_1.transferExistingProperties)(context.serverData, activity.details, {
@@ -13,4 +13,4 @@ exports.PUSH_DATA_HMAC_HEADER_NAME = 'x-px-pushdata';
13
13
  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]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
16
- exports.CORE_MODULE_VERSION = 'JS Core 0.18.2';
16
+ exports.CORE_MODULE_VERSION = 'JS Core 0.20.0';
@@ -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.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.transferExistingProperties = exports.isRouteMatch = exports.isRouteInPatterns = exports.removeSensitiveHeaders = exports.removeSensitiveFields = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
39
+ exports.telemetryConfigReplacer = exports.algoToCryptoString = exports.algoToSubtleCryptoString = exports.sleep = exports.getPropertyFromObject = exports.rejectOnTimeout = exports.transferExistingProperties = exports.isRouteMatch = exports.isRouteInPatterns = exports.removeSensitiveHeaders = exports.removeSensitiveFields = exports.getExtension = exports.getAuthorizationHeader = exports.getCollectorDomain = exports.getScoreApiDomain = exports.isEmailAddress = exports.isValidUuid = exports.isValidEnumValue = void 0;
40
40
  var http_1 = require("../http");
41
41
  var error_1 = require("./error");
42
42
  var constants_1 = require("./constants");
@@ -184,3 +184,27 @@ var algoToCryptoString = function (algo) {
184
184
  }
185
185
  };
186
186
  exports.algoToCryptoString = algoToCryptoString;
187
+ // Hash based on https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
188
+ var toHash = function (string) {
189
+ var hash = 0;
190
+ if (string.length === 0) {
191
+ return hash.toString();
192
+ }
193
+ for (var i = 0; i < string.length; i++) {
194
+ var char = string.charCodeAt(i);
195
+ hash = (hash << 5) - hash + char;
196
+ hash = hash & hash;
197
+ }
198
+ return hash.toString();
199
+ };
200
+ var telemetryConfigReplacer = function (key, value) {
201
+ if (value instanceof RegExp) {
202
+ return '_REGEXP ' + value.toString();
203
+ }
204
+ if (value instanceof Function) {
205
+ return '_FUNCTION_HASH' + toHash(value.toString()); // NOTE: Do not log functions
206
+ }
207
+ else
208
+ return value;
209
+ };
210
+ exports.telemetryConfigReplacer = telemetryConfigReplacer;
@@ -4,7 +4,7 @@ export var AdditionalActivityHandlerUtils;
4
4
  if (config.additionalActivityHandler && typeof config.additionalActivityHandler === 'function') {
5
5
  try {
6
6
  context.logger.debug('calling additional activity handler');
7
- await config.additionalActivityHandler(config.toParams(), context, context.requestData.request.getUnderlyingRequest());
7
+ await config.additionalActivityHandler(config.getActiveConfig(), context, context.requestData.request.getUnderlyingRequest());
8
8
  }
9
9
  catch (e) {
10
10
  context.logger.error(`caught additional activity handler error - ${e}`);
@@ -1,4 +1,3 @@
1
- import { PXVID_COOKIE_NAME } from '../utils';
2
1
  import { FirstPartySuffix, getMostCustomizedFirstPartyPath } from '../products';
3
2
  export const renderHtml = (htmlTemplate, blockData) => {
4
3
  if (!blockData) {
@@ -30,7 +29,7 @@ export const createBlockData = (config, context, base64Utils) => {
30
29
  const jsTemplateScriptSrc = `https://captcha.px-cdn.net/${config.appId}/checkpoint.js`;
31
30
  return {
32
31
  appId: config.appId,
33
- vid: context.vid || context.requestData?.cookies?.[PXVID_COOKIE_NAME] || '',
32
+ vid: context.vid || '',
34
33
  uuid: context.uuid || '',
35
34
  isMobile: context.isMobile,
36
35
  customLogo: config.customLogo || '',