perimeterx-js-core 0.16.0 → 0.17.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 (101) hide show
  1. package/lib/cjs/activities/HttpActivityClient.js +27 -7
  2. package/lib/cjs/activities/utils.js +8 -6
  3. package/lib/cjs/config/defaults/constants.js +0 -0
  4. package/lib/cjs/context/ContextJson.js +2 -0
  5. package/lib/cjs/context/DefaultContext.js +41 -20
  6. package/lib/cjs/context/SerializedContext.js +66 -0
  7. package/lib/cjs/context/index.js +2 -0
  8. package/lib/cjs/enforcer/EnforcerBase.js +2 -101
  9. package/lib/cjs/enforcer/index.js +3 -3
  10. package/lib/cjs/enforcer/utils.js +96 -0
  11. package/lib/cjs/impl/url/UrlImpl.js +3 -0
  12. package/lib/cjs/products/bot_defender/first_party/IDefaultBotDefenderFirstPartyConfiguration.js +0 -0
  13. package/lib/cjs/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +4 -6
  14. package/lib/cjs/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +1 -11
  15. package/lib/cjs/products/hype_sale_challenge/HypeSaleChallenge.js +1 -1
  16. package/lib/cjs/risk_api/risk_response/RiskResponseBase.js +14 -0
  17. package/lib/cjs/risk_api/risk_response/index.js +1 -0
  18. package/lib/cjs/risk_api/risk_response/serialize/RiskResponseJson.js +2 -0
  19. package/lib/cjs/risk_api/risk_response/serialize/SerializedRiskResponse.js +22 -0
  20. package/lib/cjs/risk_api/risk_response/serialize/index.js +18 -0
  21. package/lib/cjs/risk_token/parser/TokenParserBase.js +1 -1
  22. package/lib/cjs/risk_token/token/TokenBase.js +31 -7
  23. package/lib/cjs/risk_token/token/index.js +19 -9
  24. package/lib/cjs/risk_token/token/serialize/SerializedToken.js +30 -0
  25. package/lib/cjs/risk_token/token/serialize/TokenJson.js +2 -0
  26. package/lib/cjs/risk_token/token/serialize/index.js +18 -0
  27. package/lib/cjs/risk_token/token/v2/index.js +18 -0
  28. package/lib/cjs/risk_token/token/v3/DefaultTokenV3.js +3 -2
  29. package/lib/cjs/risk_token/token/v3/index.js +19 -0
  30. package/lib/cjs/utils/constants.js +1 -1
  31. package/lib/cjs/utils/cookie_parser/StringSplitCookieParser.js +20 -4
  32. package/lib/esm/activities/HttpActivityClient.js +27 -7
  33. package/lib/esm/activities/utils.js +8 -6
  34. package/lib/esm/config/defaults/constants.js +0 -0
  35. package/lib/esm/context/ContextJson.js +1 -0
  36. package/lib/esm/context/DefaultContext.js +36 -13
  37. package/lib/esm/context/SerializedContext.js +87 -0
  38. package/lib/esm/context/index.js +2 -0
  39. package/lib/esm/enforcer/EnforcerBase.js +2 -89
  40. package/lib/esm/enforcer/index.js +3 -1
  41. package/lib/esm/enforcer/utils.js +79 -0
  42. package/lib/esm/impl/url/UrlImpl.js +3 -0
  43. package/lib/esm/products/bot_defender/first_party/IDefaultBotDefenderFirstPartyConfiguration.js +0 -0
  44. package/lib/esm/products/credential_intelligence/endpoint/extractor/BodyCredentialExtractor.js +6 -8
  45. package/lib/esm/products/credential_intelligence/endpoint/extractor/CustomCredentialExtractor.js +1 -6
  46. package/lib/esm/products/hype_sale_challenge/HypeSaleChallenge.js +1 -1
  47. package/lib/esm/risk_api/risk_response/RiskResponseBase.js +14 -0
  48. package/lib/esm/risk_api/risk_response/index.js +1 -0
  49. package/lib/esm/risk_api/risk_response/serialize/RiskResponseJson.js +1 -0
  50. package/lib/esm/risk_api/risk_response/serialize/SerializedRiskResponse.js +27 -0
  51. package/lib/esm/risk_api/risk_response/serialize/index.js +2 -0
  52. package/lib/esm/risk_token/parser/TokenParserBase.js +1 -1
  53. package/lib/esm/risk_token/token/TokenBase.js +19 -4
  54. package/lib/esm/risk_token/token/index.js +5 -4
  55. package/lib/esm/risk_token/token/serialize/SerializedToken.js +36 -0
  56. package/lib/esm/risk_token/token/serialize/TokenJson.js +1 -0
  57. package/lib/esm/risk_token/token/serialize/index.js +2 -0
  58. package/lib/esm/risk_token/token/v2/index.js +2 -0
  59. package/lib/esm/risk_token/token/v3/DefaultTokenV3.js +2 -2
  60. package/lib/esm/risk_token/token/v3/index.js +3 -0
  61. package/lib/esm/utils/constants.js +1 -1
  62. package/lib/esm/utils/cookie_parser/StringSplitCookieParser.js +16 -3
  63. package/lib/types/activities/HttpActivityClient.d.ts +6 -0
  64. package/lib/types/activities/utils.d.ts +92 -61
  65. package/lib/types/blocker/utils.d.ts +9 -6
  66. package/lib/types/config/defaults/constants.d.ts +0 -0
  67. package/lib/types/context/ContextJson.d.ts +41 -0
  68. package/lib/types/context/DefaultContext.d.ts +5 -3
  69. package/lib/types/context/SerializedContext.d.ts +46 -0
  70. package/lib/types/context/index.d.ts +2 -0
  71. package/lib/types/enforcer/EnforcerBase.d.ts +2 -13
  72. package/lib/types/enforcer/index.d.ts +3 -2
  73. package/lib/types/enforcer/utils.d.ts +7 -0
  74. package/lib/types/impl/url/UrlImpl.d.ts +1 -0
  75. package/lib/types/monitored_request/MonitoredRequestUtils.d.ts +27 -18
  76. package/lib/types/phase/flow/EndEnforcerFlow.d.ts +1 -1
  77. package/lib/types/phase/flow/EnforceFlow.d.ts +3 -1
  78. package/lib/types/phase/flow/PostEnforceFlow.d.ts +1 -1
  79. package/lib/types/products/bot_defender/first_party/IDefaultBotDefenderFirstPartyConfiguration.d.ts +0 -0
  80. package/lib/types/products/bot_defender/first_party/utils.d.ts +7 -6
  81. package/lib/types/pxhd/PXHDUtils.d.ts +18 -12
  82. package/lib/types/risk_api/risk_response/RiskResponseBase.d.ts +2 -0
  83. package/lib/types/risk_api/risk_response/index.d.ts +1 -0
  84. package/lib/types/risk_api/risk_response/serialize/RiskResponseJson.d.ts +15 -0
  85. package/lib/types/risk_api/risk_response/serialize/SerializedRiskResponse.d.ts +19 -0
  86. package/lib/types/risk_api/risk_response/serialize/index.d.ts +2 -0
  87. package/lib/types/risk_token/token/IToken.d.ts +3 -3
  88. package/lib/types/risk_token/token/TokenBase.d.ts +6 -4
  89. package/lib/types/risk_token/token/index.d.ts +5 -7
  90. package/lib/types/risk_token/token/serialize/SerializedToken.d.ts +23 -0
  91. package/lib/types/risk_token/token/serialize/TokenJson.d.ts +13 -0
  92. package/lib/types/risk_token/token/serialize/index.d.ts +2 -0
  93. package/lib/types/risk_token/token/v2/index.d.ts +2 -0
  94. package/lib/types/risk_token/token/v3/DefaultTokenV3.d.ts +1 -1
  95. package/lib/types/risk_token/token/v3/index.d.ts +3 -0
  96. package/lib/types/sensitive_request/SensitiveRequestUtils.d.ts +18 -12
  97. package/lib/types/utils/constants.d.ts +1 -1
  98. package/lib/types/utils/cookie_parser/ICookieParser.d.ts +1 -1
  99. package/lib/types/utils/cookie_parser/StringSplitCookieParser.d.ts +5 -2
  100. package/lib/types/utils/url/IUrl.d.ts +1 -0
  101. package/package.json +1 -1
@@ -39,12 +39,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.TokenBase = void 0;
40
40
  var TokenParseResult_1 = require("../TokenParseResult");
41
41
  var TokenBase = /** @class */ (function () {
42
- function TokenBase(config, cookieString) {
42
+ function TokenBase(config, cookieString, isValidated, payload) {
43
+ if (isValidated === void 0) { isValidated = false; }
43
44
  this.config = config;
44
45
  this.cookieSecret = config.cookieSecret;
45
46
  this.cookieMaxLength = config.riskCookieMaxLength;
46
47
  this.cookieString = cookieString;
47
- this.isValidated = false;
48
+ this.isValidated = isValidated;
49
+ this.payload = payload;
48
50
  }
49
51
  TokenBase.prototype.verify = function (context) {
50
52
  return __awaiter(this, void 0, void 0, function () {
@@ -87,11 +89,33 @@ var TokenBase = /** @class */ (function () {
87
89
  TokenBase.prototype.isValid = function () {
88
90
  return this.isValidated;
89
91
  };
90
- TokenBase.prototype.getTokenString = function () {
91
- return this.cookieString;
92
- };
93
- TokenBase.prototype.getPayloadString = function () {
94
- return this.payload ? JSON.stringify(this.payload) : '';
92
+ Object.defineProperty(TokenBase.prototype, "tokenString", {
93
+ get: function () {
94
+ return this.cookieString;
95
+ },
96
+ enumerable: false,
97
+ configurable: true
98
+ });
99
+ Object.defineProperty(TokenBase.prototype, "payloadString", {
100
+ get: function () {
101
+ return this.payload ? JSON.stringify(this.payload) : '';
102
+ },
103
+ enumerable: false,
104
+ configurable: true
105
+ });
106
+ TokenBase.prototype.toJSON = function () {
107
+ return {
108
+ action: this.action,
109
+ cpa: this.cpa,
110
+ hmac: this.hmac,
111
+ isValidated: this.isValidated,
112
+ payloadString: this.payloadString,
113
+ score: this.score,
114
+ timestamp: this.timestamp,
115
+ tokenString: this.tokenString,
116
+ uuid: this.uuid,
117
+ vid: this.vid,
118
+ };
95
119
  };
96
120
  return TokenBase;
97
121
  }());
@@ -1,11 +1,21 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenSignField = exports.DefaultTokenV3 = exports.DefaultTokenV2 = exports.TokenBase = void 0;
4
- var TokenBase_1 = require("./TokenBase");
5
- Object.defineProperty(exports, "TokenBase", { enumerable: true, get: function () { return TokenBase_1.TokenBase; } });
6
- var DefaultTokenV2_1 = require("./v2/DefaultTokenV2");
7
- Object.defineProperty(exports, "DefaultTokenV2", { enumerable: true, get: function () { return DefaultTokenV2_1.DefaultTokenV2; } });
8
- var DefaultTokenV3_1 = require("./v3/DefaultTokenV3");
9
- Object.defineProperty(exports, "DefaultTokenV3", { enumerable: true, get: function () { return DefaultTokenV3_1.DefaultTokenV3; } });
10
- var TokenSignField_1 = require("./v3/TokenSignField");
11
- Object.defineProperty(exports, "TokenSignField", { enumerable: true, get: function () { return TokenSignField_1.TokenSignField; } });
17
+ __exportStar(require("./IToken"), exports);
18
+ __exportStar(require("./TokenBase"), exports);
19
+ __exportStar(require("./v2"), exports);
20
+ __exportStar(require("./v3"), exports);
21
+ __exportStar(require("./serialize"), exports);
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SerializedToken = void 0;
4
+ var TokenParseResult_1 = require("../../TokenParseResult");
5
+ var SerializedToken = /** @class */ (function () {
6
+ function SerializedToken(config, serializedToken) {
7
+ this.blockingScore = config.blockingScore;
8
+ this.action = serializedToken.action;
9
+ this.cpa = serializedToken.cpa;
10
+ this.hmac = serializedToken.hmac;
11
+ this.isValidated = serializedToken.isValidated;
12
+ this.payloadString = serializedToken.payloadString;
13
+ this.score = serializedToken.score;
14
+ this.timestamp = serializedToken.timestamp;
15
+ this.tokenString = serializedToken.tokenString;
16
+ this.uuid = serializedToken.uuid;
17
+ this.vid = serializedToken.vid;
18
+ }
19
+ SerializedToken.prototype.isExpired = function () {
20
+ return Date.now() >= this.timestamp;
21
+ };
22
+ SerializedToken.prototype.isHighScore = function () {
23
+ return this.score >= this.blockingScore;
24
+ };
25
+ SerializedToken.prototype.verify = function (context) {
26
+ return TokenParseResult_1.TokenParseResult.NONE;
27
+ };
28
+ return SerializedToken;
29
+ }());
30
+ exports.SerializedToken = SerializedToken;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./SerializedToken"), exports);
18
+ __exportStar(require("./TokenJson"), exports);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./TokenV2Payload"), exports);
18
+ __exportStar(require("./DefaultTokenV2"), exports);
@@ -58,8 +58,9 @@ var TokenSignField_1 = require("./TokenSignField");
58
58
  var TokenBase_1 = require("../TokenBase");
59
59
  var DefaultTokenV3 = /** @class */ (function (_super) {
60
60
  __extends(DefaultTokenV3, _super);
61
- function DefaultTokenV3(config, cookieString, cipherUtils, hmacUtils) {
62
- var _this = _super.call(this, config, cookieString) || this;
61
+ function DefaultTokenV3(config, cookieString, cipherUtils, hmacUtils, isValidated, payload) {
62
+ if (isValidated === void 0) { isValidated = false; }
63
+ var _this = _super.call(this, config, cookieString, isValidated, payload) || this;
63
64
  _this.maxIterations = config.riskCookieMaxIterations;
64
65
  _this.minIterations = config.riskCookieMinIterations;
65
66
  _this.blockingScore = config.blockingScore;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./DefaultTokenV3"), exports);
18
+ __exportStar(require("./TokenV3Payload"), exports);
19
+ __exportStar(require("./TokenSignField"), exports);
@@ -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.16.0';
16
+ exports.CORE_MODULE_VERSION = 'JS Core 0.17.0';
@@ -2,14 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringSplitCookieParser = void 0;
4
4
  var StringSplitCookieParser = /** @class */ (function () {
5
- function StringSplitCookieParser() {
5
+ function StringSplitCookieParser(cookieDelimiter) {
6
+ if (cookieDelimiter === void 0) { cookieDelimiter = ';'; }
7
+ this.cookieDelimiter = cookieDelimiter;
6
8
  }
7
- StringSplitCookieParser.prototype.parseCookies = function (cookieHeaderValue) {
9
+ StringSplitCookieParser.prototype.parseCookies = function () {
10
+ var _this = this;
11
+ var cookieHeaderValues = [];
12
+ for (var _i = 0; _i < arguments.length; _i++) {
13
+ cookieHeaderValues[_i] = arguments[_i];
14
+ }
15
+ var cookies = {};
16
+ if (!cookieHeaderValues) {
17
+ return cookies;
18
+ }
19
+ cookieHeaderValues.forEach(function (value) {
20
+ Object.assign(cookies, _this.parseCookieHeaderValue(value));
21
+ });
22
+ return cookies;
23
+ };
24
+ StringSplitCookieParser.prototype.parseCookieHeaderValue = function (cookieHeaderValue) {
8
25
  if (!cookieHeaderValue || typeof cookieHeaderValue !== 'string') {
9
26
  return {};
10
27
  }
11
- var COOKIE_DELIMITER = ';';
12
- var cookieEntries = cookieHeaderValue.split(COOKIE_DELIMITER).map(this.getCookieParts).filter(Boolean);
28
+ var cookieEntries = cookieHeaderValue.split(this.cookieDelimiter).map(this.getCookieParts).filter(Boolean);
13
29
  var cookies = {};
14
30
  cookieEntries.forEach(function (_a) {
15
31
  var cookieName = _a[0], cookieValue = _a[1];
@@ -23,17 +23,37 @@ export class HttpActivityClient {
23
23
  }
24
24
  createActivities(context) {
25
25
  const activities = [];
26
- if (context.action === Action.BLOCK || context.action === Action.SIMULATED_BLOCK) {
27
- activities.push(createAsyncActivity(ActivityType.BLOCK, this.config, context));
26
+ if (this.shouldCreateBlockActivity(context)) {
27
+ activities.push(this.createBlockActivity(context));
28
28
  }
29
- else if (context.action === Action.PASS_REQUEST) {
30
- activities.push(createAsyncActivity(ActivityType.PAGE_REQUESTED, this.config, context));
31
- if (context.productData.ci && this.config.ciAutomaticAdditionalS2SEnabled) {
32
- activities.push(createAsyncActivity(ActivityType.ADDITIONAL_S2S, this.config, context));
33
- }
29
+ if (this.shouldCreatePageRequestedActivity(context)) {
30
+ activities.push(this.createPageRequestedActivity(context));
31
+ }
32
+ if (this.shouldCreateAdditionalS2SActivity(context)) {
33
+ activities.push(this.createAdditionalS2SActivity(context));
34
34
  }
35
35
  return activities.map(this.finalizeActivity);
36
36
  }
37
+ shouldCreateBlockActivity(context) {
38
+ return context.action === Action.BLOCK || context.action === Action.SIMULATED_BLOCK;
39
+ }
40
+ shouldCreatePageRequestedActivity(context) {
41
+ return context.action === Action.PASS_REQUEST;
42
+ }
43
+ shouldCreateAdditionalS2SActivity(context) {
44
+ return (this.shouldCreatePageRequestedActivity(context) &&
45
+ context.productData.ci &&
46
+ this.config.ciAutomaticAdditionalS2SEnabled);
47
+ }
48
+ createBlockActivity(context) {
49
+ return createAsyncActivity(ActivityType.BLOCK, this.config, context);
50
+ }
51
+ createPageRequestedActivity(context) {
52
+ return createAsyncActivity(ActivityType.PAGE_REQUESTED, this.config, context);
53
+ }
54
+ createAdditionalS2SActivity(context) {
55
+ return createAsyncActivity(ActivityType.ADDITIONAL_S2S, this.config, context);
56
+ }
37
57
  /**
38
58
  * Allows for expansions or alterations to the async activity if needed.
39
59
  * @param activity
@@ -123,12 +123,12 @@ export const addRequestDataToDetails = (details, requestData) => {
123
123
  };
124
124
  export const addTokenDataToDetails = (details, { token, mobileData }) => {
125
125
  if (token) {
126
- if (token.isValid()) {
127
- details.px_cookie = token.getPayloadString();
126
+ if (token.isValidated) {
127
+ details.px_cookie = token.payloadString;
128
128
  details.px_cookie_hmac = token.hmac;
129
129
  }
130
130
  else {
131
- details.px_orig_cookie = token.getTokenString();
131
+ details.px_orig_cookie = token.tokenString;
132
132
  }
133
133
  }
134
134
  if (mobileData) {
@@ -158,9 +158,11 @@ export const addRiskApiDataToAsyncActivityCommonDetails = (details, context) =>
158
158
  }
159
159
  };
160
160
  export const addResponseDataToAsyncActivityCommonDetails = (details, context) => {
161
- transferExistingProperties(context.response, details, {
162
- status: 'http_status_code',
163
- });
161
+ if (context.action !== Action.BLOCK) {
162
+ transferExistingProperties(context.response, details, {
163
+ status: 'http_status_code',
164
+ });
165
+ }
164
166
  };
165
167
  export const createPageRequestedActivityDetails = (context) => {
166
168
  const details = {};
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -28,11 +28,12 @@ export class DefaultContext {
28
28
  pxde;
29
29
  pxdeVerified;
30
30
  customParameters;
31
+ graphqlData;
31
32
  response;
32
33
  enforcerStartTime;
34
+ logger;
33
35
  config;
34
36
  urlUtils;
35
- contextLogger;
36
37
  constructor(config, request, options) {
37
38
  this.enforcerStartTime = Date.now();
38
39
  this.config = config;
@@ -51,16 +52,13 @@ export class DefaultContext {
51
52
  this.pxdeVerified = false;
52
53
  this.isRemoteConfigUpdateRequest = RemoteConfigUtils.isRemoteConfigUpdateRequest(request);
53
54
  this.shouldSendLogs = this.isRemoteConfigUpdateRequest || this.isHeaderBasedLoggerRequest(config, request);
54
- this.contextLogger = this.createContextLogger(config, this.shouldSendLogs);
55
+ this.logger = this.createContextLogger(config, this.shouldSendLogs);
55
56
  this.requestData = this.createRequestData(config, request, options.cookieParser);
56
57
  this.tokenOrigin = this.getTokenOrigin(request);
57
58
  if (!this.isMobile) {
58
59
  this.setCookiesOnContext();
59
60
  }
60
61
  }
61
- get logger() {
62
- return this.contextLogger;
63
- }
64
62
  get isMobile() {
65
63
  return this.tokenOrigin === TokenOrigin.HEADER;
66
64
  }
@@ -72,7 +70,7 @@ export class DefaultContext {
72
70
  const url = this.normalizeUrl(rawUrl);
73
71
  const isUrlDifferentFromRawUrl = rawUrl !== url.href;
74
72
  const method = request.method;
75
- const cookies = DefaultContext.getCookies(cookieParser, request.headers.get(COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
73
+ const cookies = cookieParser.parseCookies(request.headers.get(COOKIE_HEADER_NAME), request.headers.get(config.customCookieHeader));
76
74
  const requestCookieNames = Object.keys(cookies);
77
75
  const readOnlyHeaders = toReadonlyHeaders(request.headers);
78
76
  const userAgent = this.extractUserAgentFromHeader(config, readOnlyHeaders);
@@ -92,13 +90,6 @@ export class DefaultContext {
92
90
  isUrlDifferentFromRawUrl,
93
91
  };
94
92
  }
95
- static getCookies(cookieParser, ...cookieHeaderValues) {
96
- const cookies = {};
97
- cookieHeaderValues.forEach((value) => {
98
- Object.assign(cookies, value ? cookieParser.parseCookies(value) : null);
99
- });
100
- return cookies;
101
- }
102
93
  normalizeUrl(rawUrl) {
103
94
  let url = this.urlUtils.createUrl(rawUrl);
104
95
  if (this.config.urlDecodeReservedCharacters) {
@@ -146,4 +137,36 @@ export class DefaultContext {
146
137
  isHeaderBasedLoggerRequest(config, request) {
147
138
  return config.loggerAuthToken && config.loggerAuthToken === request.headers.get(X_PX_ENFORCER_LOG_HEADER);
148
139
  }
140
+ toJSON() {
141
+ return {
142
+ action: this.action,
143
+ reasons: this.reasons,
144
+ isMobile: this.isMobile,
145
+ isRemoteConfigUpdateRequest: this.isRemoteConfigUpdateRequest,
146
+ productData: this.productData,
147
+ requestData: {
148
+ ...this.requestData,
149
+ request: undefined,
150
+ url: this.requestData.url.href,
151
+ },
152
+ requestId: this.requestId,
153
+ riskApiData: this.riskApiData,
154
+ serverData: this.serverData,
155
+ shouldSendLogs: this.shouldSendLogs,
156
+ tlsData: this.tlsData,
157
+ tokenData: this.tokenData,
158
+ tokenOrigin: this.tokenOrigin,
159
+ pxhd: this.pxhd,
160
+ pxde: this.pxde,
161
+ score: this.score,
162
+ customParameters: this.customParameters,
163
+ graphqlData: this.graphqlData,
164
+ vid: this.vid,
165
+ vidSource: this.vidSource,
166
+ uuid: this.uuid,
167
+ enforcerStartTime: this.enforcerStartTime,
168
+ blockAction: this.blockAction,
169
+ pxdeVerified: this.pxdeVerified,
170
+ };
171
+ }
149
172
  }
@@ -0,0 +1,87 @@
1
+ import { DefaultLogger } from '../logger';
2
+ import { SerializedToken } from '../risk_token';
3
+ import { SerializedRiskResponse } from '../risk_api';
4
+ export class SerializedContext {
5
+ isMobile;
6
+ isRemoteConfigUpdateRequest;
7
+ logger;
8
+ productData;
9
+ requestData;
10
+ requestId;
11
+ riskApiData;
12
+ serverData;
13
+ shouldSendLogs;
14
+ tlsData;
15
+ tokenData;
16
+ enforcerStartTime;
17
+ action;
18
+ score;
19
+ reasons;
20
+ blockAction;
21
+ pxhd;
22
+ pxde;
23
+ pxdeVerified;
24
+ customParameters;
25
+ graphqlData;
26
+ vid;
27
+ vidSource;
28
+ tokenOrigin;
29
+ uuid;
30
+ constructor(config, contextJson, request, urlUtils) {
31
+ this.action = contextJson.action;
32
+ this.reasons = contextJson.reasons;
33
+ this.isMobile = contextJson.isMobile;
34
+ this.requestId = contextJson.requestId;
35
+ this.isRemoteConfigUpdateRequest = contextJson.isRemoteConfigUpdateRequest;
36
+ this.logger = this.createLogger(config, contextJson.shouldSendLogs);
37
+ this.productData = contextJson.productData;
38
+ this.requestData = this.createRequestData(contextJson, request, urlUtils);
39
+ this.riskApiData = this.createRiskApiData(contextJson);
40
+ this.serverData = contextJson.serverData;
41
+ this.shouldSendLogs = contextJson.shouldSendLogs;
42
+ this.tlsData = contextJson.tlsData;
43
+ this.tokenData = this.createTokenData(contextJson, config);
44
+ this.tokenOrigin = contextJson.tokenOrigin;
45
+ this.uuid = contextJson.uuid;
46
+ this.vid = contextJson.vid;
47
+ this.vidSource = contextJson.vidSource;
48
+ this.pxhd = contextJson.pxhd;
49
+ this.pxde = contextJson.pxde;
50
+ this.pxdeVerified = contextJson.pxdeVerified;
51
+ this.score = contextJson.score;
52
+ this.customParameters = contextJson.customParameters;
53
+ this.graphqlData = contextJson.graphqlData;
54
+ this.enforcerStartTime = contextJson.enforcerStartTime;
55
+ this.blockAction = contextJson.blockAction;
56
+ }
57
+ createRequestData({ requestData }, request, urlUtils) {
58
+ return {
59
+ ...requestData,
60
+ url: urlUtils.createUrl(requestData.url),
61
+ request,
62
+ };
63
+ }
64
+ createTokenData({ tokenData }, config) {
65
+ return {
66
+ ...tokenData,
67
+ token: tokenData.token ? new SerializedToken(config, tokenData.token) : undefined,
68
+ mobileData: tokenData.mobileData
69
+ ? {
70
+ ...tokenData.mobileData,
71
+ originalToken: tokenData.mobileData.originalToken
72
+ ? new SerializedToken(config, tokenData.mobileData.originalToken)
73
+ : undefined,
74
+ }
75
+ : {},
76
+ };
77
+ }
78
+ createRiskApiData({ riskApiData }) {
79
+ return {
80
+ ...riskApiData,
81
+ riskResponse: riskApiData.riskResponse ? new SerializedRiskResponse(riskApiData.riskResponse) : undefined,
82
+ };
83
+ }
84
+ createLogger(config, shouldSendLogs) {
85
+ return new DefaultLogger(config.loggerSeverity, shouldSendLogs);
86
+ }
87
+ }
@@ -1,2 +1,4 @@
1
1
  export * from './interfaces';
2
2
  export * from './DefaultContext';
3
+ export * from './ContextJson';
4
+ export * from './SerializedContext';
@@ -1,15 +1,5 @@
1
- import { HttpRemoteConfigServiceClient, DefaultRemoteConfigUpdater } from '../config';
2
- import { DefaultDataEnrichment } from '../pxde';
3
- import { DefaultTelemetry } from '../telemetry';
4
- import { DefaultTokenV2Parser, DefaultTokenV3Parser, TokenVersion } from '../risk_token';
5
- import { DefaultCors } from '../cors';
6
- import { PostRiskApiClientV2, PostRiskApiClientV3 } from '../risk_api';
7
1
  import { EndEnforcerFlow, EnforceFlow, FilterFlow, PostEnforceFlow } from '../phase';
8
- import { AccountDefender, BotDefender, CredentialIntelligence, ProductName } from '../products';
9
- import { HttpActivityClient, HttpBatchedActivityClient } from '../activities';
10
- import { DefaultGraphQLParser } from '../graphql';
11
- import { HttpLogServiceClient } from '../logger';
12
- import { HypeSaleChallenge } from '../products';
2
+ import { createEnforcerInitializationBlock } from './utils';
13
3
  export class EnforcerBase {
14
4
  config;
15
5
  filterFlow;
@@ -25,7 +15,7 @@ export class EnforcerBase {
25
15
  */
26
16
  constructor(config, options) {
27
17
  this.config = config;
28
- const initializationBlock = this.getInitializationBlock(config, options);
18
+ const initializationBlock = createEnforcerInitializationBlock(config, options);
29
19
  this.activityClient = initializationBlock.activityClient;
30
20
  this.filterFlow = this.createFilterFlow(config, initializationBlock);
31
21
  this.enforceFlow = this.createEnforceFlow(config, initializationBlock);
@@ -119,81 +109,4 @@ export class EnforcerBase {
119
109
  await this.activityClient.sendActivities(context);
120
110
  }
121
111
  }
122
- /**
123
- * Returns the components needed to initialize the enforcer according to the provided options. If no
124
- * component is provided in the options, a default one is generated and returned.
125
- * @param config
126
- * @param options
127
- * @returns Required<EnforcerBaseOptions>
128
- * @protected
129
- */
130
- getInitializationBlock(config, options) {
131
- const { tokenVersion, httpClient, base64Utils, hmacUtils, hashUtils, urlUtils, ipRangeChecker } = options;
132
- const cipherUtils = tokenVersion === TokenVersion.V2 ? null : options.cipherUtils;
133
- const cors = options.cors || new DefaultCors(config);
134
- const telemetry = options.telemetry || new DefaultTelemetry(config, httpClient, base64Utils, hmacUtils);
135
- const dataEnrichment = options.dataEnrichment || new DefaultDataEnrichment(config, base64Utils, hmacUtils);
136
- const graphQLParser = options.graphQLParser || new DefaultGraphQLParser(config);
137
- const tokenParser = options.tokenParser ||
138
- (tokenVersion === TokenVersion.V2
139
- ? new DefaultTokenV2Parser(config, { base64Utils, hmacUtils })
140
- : new DefaultTokenV3Parser(config, { cipherUtils, hmacUtils }));
141
- const riskApiClient = options.riskApiClient ||
142
- (tokenVersion === TokenVersion.V2
143
- ? new PostRiskApiClientV2(config, httpClient)
144
- : new PostRiskApiClientV3(config, httpClient));
145
- const activityClient = options.activityClient ||
146
- (config.maxActivityBatchSize > 1
147
- ? new HttpBatchedActivityClient(config, httpClient)
148
- : new HttpActivityClient(config, httpClient));
149
- const logServiceClient = options.logServiceClient || (config.loggerAuthToken ? new HttpLogServiceClient(config, httpClient) : null);
150
- const remoteConfigStorageClient = options.remoteConfigStorageClient;
151
- const remoteConfigServiceClient = options.remoteConfigServiceClient ||
152
- (config.remoteConfigAuthToken ? new HttpRemoteConfigServiceClient(config, httpClient) : null);
153
- const remoteConfigUpdater = options.remoteConfigUpdater ||
154
- (remoteConfigStorageClient && remoteConfigServiceClient
155
- ? new DefaultRemoteConfigUpdater(config, {
156
- serviceClient: remoteConfigServiceClient,
157
- storageClient: remoteConfigStorageClient,
158
- base64Utils,
159
- hmacUtils,
160
- })
161
- : null);
162
- const allOptions = {
163
- httpClient,
164
- base64Utils,
165
- hmacUtils,
166
- hashUtils,
167
- urlUtils,
168
- ipRangeChecker,
169
- cors,
170
- telemetry,
171
- dataEnrichment,
172
- graphQLParser,
173
- tokenParser,
174
- riskApiClient,
175
- activityClient,
176
- logServiceClient,
177
- remoteConfigStorageClient,
178
- remoteConfigServiceClient,
179
- remoteConfigUpdater,
180
- };
181
- const products = this.initializeProducts(config, options.products, base64Utils, hashUtils, urlUtils, ipRangeChecker);
182
- return { products, ...allOptions };
183
- }
184
- initializeProducts(config, products, base64Utils, hashUtils, urlUtils, ipRangeChecker) {
185
- const botDefender = products?.bd || new BotDefender(config, { base64Utils, ipRangeChecker, urlUtils });
186
- const accountDefender = products?.ad || new AccountDefender(config, { base64Utils });
187
- const credentialIntelligence = config.ciEnabled
188
- ? products?.ci || new CredentialIntelligence(config, { hashUtils, urlUtils })
189
- : null;
190
- const hypeSaleChallenge = products?.hsc || new HypeSaleChallenge(config, { base64Utils });
191
- return {
192
- [ProductName.BOT_DEFENDER]: botDefender,
193
- [ProductName.ACCOUNT_DEFENDER]: accountDefender,
194
- [ProductName.CODE_DEFENDER]: products?.cd,
195
- [ProductName.CREDENTIAL_INTELLIGENCE]: credentialIntelligence,
196
- [ProductName.HYPE_SALE_CHALLENGE]: hypeSaleChallenge,
197
- };
198
- }
199
112
  }
@@ -1,2 +1,4 @@
1
- export { EnforcerBase } from './EnforcerBase';
1
+ export * from './IEnforcer';
2
+ export * from './EnforcerBase';
2
3
  export * from './options';
4
+ export * from './utils';