perimeterx-js-core 0.1.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 (288) hide show
  1. package/README.md +158 -0
  2. package/lib/activities/ActivityType.d.ts +6 -0
  3. package/lib/activities/ActivityType.js +10 -0
  4. package/lib/activities/HttpActivityClient.d.ts +12 -0
  5. package/lib/activities/HttpActivityClient.js +107 -0
  6. package/lib/activities/IActivityClient.d.ts +8 -0
  7. package/lib/activities/IActivityClient.js +2 -0
  8. package/lib/activities/constants.d.ts +1 -0
  9. package/lib/activities/constants.js +4 -0
  10. package/lib/activities/index.d.ts +5 -0
  11. package/lib/activities/index.js +7 -0
  12. package/lib/activities/model/Activity.d.ts +13 -0
  13. package/lib/activities/model/Activity.js +2 -0
  14. package/lib/activities/model/ActivityDetails.d.ts +41 -0
  15. package/lib/activities/model/ActivityDetails.js +2 -0
  16. package/lib/activities/utils.d.ts +10 -0
  17. package/lib/activities/utils.js +88 -0
  18. package/lib/additional_activity_handler/AdditionalActivityHandler.d.ts +3 -0
  19. package/lib/additional_activity_handler/AdditionalActivityHandler.js +2 -0
  20. package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.d.ts +5 -0
  21. package/lib/additional_activity_handler/AdditionalActivityHandlerUtils.js +64 -0
  22. package/lib/additional_activity_handler/index.d.ts +2 -0
  23. package/lib/additional_activity_handler/index.js +5 -0
  24. package/lib/block_handler/BlockAction.d.ts +6 -0
  25. package/lib/block_handler/BlockAction.js +21 -0
  26. package/lib/block_handler/BlockReason.d.ts +4 -0
  27. package/lib/block_handler/BlockReason.js +8 -0
  28. package/lib/block_handler/DefaultBlockResponseGenerator.d.ts +14 -0
  29. package/lib/block_handler/DefaultBlockResponseGenerator.js +44 -0
  30. package/lib/block_handler/IBlockResponseGenerator.d.ts +14 -0
  31. package/lib/block_handler/IBlockResponseGenerator.js +2 -0
  32. package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.d.ts +14 -0
  33. package/lib/block_handler/captcha/CaptchaBlockResponseGenerator.js +30 -0
  34. package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.d.ts +10 -0
  35. package/lib/block_handler/captcha/HtmlCaptchaResponseGenerator.js +25 -0
  36. package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.d.ts +10 -0
  37. package/lib/block_handler/captcha/JsonCaptchaResponseGenerator.js +44 -0
  38. package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.d.ts +12 -0
  39. package/lib/block_handler/captcha/MobileCaptchaResponseGenerator.js +36 -0
  40. package/lib/block_handler/index.d.ts +13 -0
  41. package/lib/block_handler/index.js +21 -0
  42. package/lib/block_handler/model/BlockData.d.ts +16 -0
  43. package/lib/block_handler/model/BlockData.js +2 -0
  44. package/lib/block_handler/model/JsonBlockPayload.d.ts +11 -0
  45. package/lib/block_handler/model/JsonBlockPayload.js +2 -0
  46. package/lib/block_handler/model/MobileBlockPayload.d.ts +8 -0
  47. package/lib/block_handler/model/MobileBlockPayload.js +2 -0
  48. package/lib/block_handler/templates/captcha_template.d.ts +1 -0
  49. package/lib/block_handler/templates/captcha_template.js +4 -0
  50. package/lib/block_handler/templates/rate_limit_template.d.ts +1 -0
  51. package/lib/block_handler/templates/rate_limit_template.js +4 -0
  52. package/lib/block_handler/utils.d.ts +5 -0
  53. package/lib/block_handler/utils.js +48 -0
  54. package/lib/config/ConfigurationParams.d.ts +65 -0
  55. package/lib/config/ConfigurationParams.js +2 -0
  56. package/lib/config/DefaultConfigurations.d.ts +2 -0
  57. package/lib/config/DefaultConfigurations.js +107 -0
  58. package/lib/config/IConfiguration.d.ts +172 -0
  59. package/lib/config/IConfiguration.js +2 -0
  60. package/lib/config/StaticConfigurationBase.d.ts +57 -0
  61. package/lib/config/StaticConfigurationBase.js +355 -0
  62. package/lib/config/index.d.ts +4 -0
  63. package/lib/config/index.js +7 -0
  64. package/lib/context/ContextBase.d.ts +55 -0
  65. package/lib/context/ContextBase.js +206 -0
  66. package/lib/context/DefaultTokenV2Context.d.ts +13 -0
  67. package/lib/context/DefaultTokenV2Context.js +35 -0
  68. package/lib/context/DefaultTokenV3Context.d.ts +13 -0
  69. package/lib/context/DefaultTokenV3Context.js +35 -0
  70. package/lib/context/IContext.d.ts +256 -0
  71. package/lib/context/IContext.js +2 -0
  72. package/lib/context/index.d.ts +4 -0
  73. package/lib/context/index.js +9 -0
  74. package/lib/custom_parameters/CustomParameters.d.ts +12 -0
  75. package/lib/custom_parameters/CustomParameters.js +2 -0
  76. package/lib/custom_parameters/CustomParametersFunction.d.ts +4 -0
  77. package/lib/custom_parameters/CustomParametersFunction.js +2 -0
  78. package/lib/custom_parameters/CustomParametersUtils.d.ts +4 -0
  79. package/lib/custom_parameters/CustomParametersUtils.js +19 -0
  80. package/lib/custom_parameters/index.d.ts +3 -0
  81. package/lib/custom_parameters/index.js +5 -0
  82. package/lib/enforcer/EnforcerBase.d.ts +139 -0
  83. package/lib/enforcer/EnforcerBase.js +376 -0
  84. package/lib/enforcer/IEnforcer.d.ts +4 -0
  85. package/lib/enforcer/IEnforcer.js +2 -0
  86. package/lib/enforcer/index.d.ts +2 -0
  87. package/lib/enforcer/index.js +5 -0
  88. package/lib/filter/DefaultFilter.d.ts +16 -0
  89. package/lib/filter/DefaultFilter.js +59 -0
  90. package/lib/filter/FilterReason.d.ts +8 -0
  91. package/lib/filter/FilterReason.js +12 -0
  92. package/lib/filter/IFilter.d.ts +8 -0
  93. package/lib/filter/IFilter.js +2 -0
  94. package/lib/filter/index.d.ts +3 -0
  95. package/lib/filter/index.js +7 -0
  96. package/lib/first_party/DefaultFirstParty.d.ts +22 -0
  97. package/lib/first_party/DefaultFirstParty.js +215 -0
  98. package/lib/first_party/IFirstParty.d.ts +9 -0
  99. package/lib/first_party/IFirstParty.js +2 -0
  100. package/lib/first_party/constants.d.ts +32 -0
  101. package/lib/first_party/constants.js +39 -0
  102. package/lib/first_party/index.d.ts +4 -0
  103. package/lib/first_party/index.js +21 -0
  104. package/lib/first_party/utils.d.ts +8 -0
  105. package/lib/first_party/utils.js +27 -0
  106. package/lib/http/IHttpClient.d.ts +10 -0
  107. package/lib/http/IHttpClient.js +2 -0
  108. package/lib/http/body_reader/IBodyReader.d.ts +5 -0
  109. package/lib/http/body_reader/IBodyReader.js +2 -0
  110. package/lib/http/body_reader/StringBodyReader.d.ts +8 -0
  111. package/lib/http/body_reader/StringBodyReader.js +70 -0
  112. package/lib/http/index.d.ts +10 -0
  113. package/lib/http/index.js +28 -0
  114. package/lib/http/request/DefaultHttpRequest.d.ts +5 -0
  115. package/lib/http/request/DefaultHttpRequest.js +42 -0
  116. package/lib/http/request/HttpRequestBase.d.ts +24 -0
  117. package/lib/http/request/HttpRequestBase.js +77 -0
  118. package/lib/http/request/IHttpRequest.d.ts +31 -0
  119. package/lib/http/request/IHttpRequest.js +2 -0
  120. package/lib/http/response/DefaultHttpResponse.d.ts +5 -0
  121. package/lib/http/response/DefaultHttpResponse.js +32 -0
  122. package/lib/http/response/HttpResponseBase.d.ts +17 -0
  123. package/lib/http/response/HttpResponseBase.js +75 -0
  124. package/lib/http/response/IHttpResponse.d.ts +26 -0
  125. package/lib/http/response/IHttpResponse.js +2 -0
  126. package/lib/http/utils/ContentType.d.ts +9 -0
  127. package/lib/http/utils/ContentType.js +13 -0
  128. package/lib/http/utils/HttpBody.d.ts +4 -0
  129. package/lib/http/utils/HttpBody.js +2 -0
  130. package/lib/http/utils/HttpHeaders.d.ts +51 -0
  131. package/lib/http/utils/HttpHeaders.js +106 -0
  132. package/lib/http/utils/HttpMethod.d.ts +11 -0
  133. package/lib/http/utils/HttpMethod.js +15 -0
  134. package/lib/http/utils/constants.d.ts +9 -0
  135. package/lib/http/utils/constants.js +12 -0
  136. package/lib/http/utils/index.d.ts +5 -0
  137. package/lib/http/utils/index.js +24 -0
  138. package/lib/index.d.ts +17 -0
  139. package/lib/index.js +33 -0
  140. package/lib/logger/DefaultLogger.d.ts +7 -0
  141. package/lib/logger/DefaultLogger.js +31 -0
  142. package/lib/logger/ILogger.d.ts +24 -0
  143. package/lib/logger/ILogger.js +2 -0
  144. package/lib/logger/LoggerBase.d.ts +11 -0
  145. package/lib/logger/LoggerBase.js +28 -0
  146. package/lib/logger/LoggerSeverity.d.ts +5 -0
  147. package/lib/logger/LoggerSeverity.js +9 -0
  148. package/lib/logger/index.d.ts +4 -0
  149. package/lib/logger/index.js +9 -0
  150. package/lib/pxde/DefaultDataEnrichment.d.ts +14 -0
  151. package/lib/pxde/DefaultDataEnrichment.js +133 -0
  152. package/lib/pxde/IDataEnrichment.d.ts +9 -0
  153. package/lib/pxde/IDataEnrichment.js +2 -0
  154. package/lib/pxde/constants.d.ts +4 -0
  155. package/lib/pxde/constants.js +7 -0
  156. package/lib/pxde/index.d.ts +4 -0
  157. package/lib/pxde/index.js +20 -0
  158. package/lib/pxde/model/PXDE.d.ts +9 -0
  159. package/lib/pxde/model/PXDE.js +2 -0
  160. package/lib/pxhd/PXHDUtils.d.ts +8 -0
  161. package/lib/pxhd/PXHDUtils.js +20 -0
  162. package/lib/pxhd/index.d.ts +1 -0
  163. package/lib/pxhd/index.js +5 -0
  164. package/lib/risk_api/PostRiskApiClient.d.ts +27 -0
  165. package/lib/risk_api/PostRiskApiClient.js +232 -0
  166. package/lib/risk_api/S2SCallReason.d.ts +12 -0
  167. package/lib/risk_api/S2SCallReason.js +16 -0
  168. package/lib/risk_api/S2SErrorHandler.d.ts +9 -0
  169. package/lib/risk_api/S2SErrorHandler.js +121 -0
  170. package/lib/risk_api/S2SErrorReason.d.ts +8 -0
  171. package/lib/risk_api/S2SErrorReason.js +12 -0
  172. package/lib/risk_api/constants.d.ts +1 -0
  173. package/lib/risk_api/constants.js +4 -0
  174. package/lib/risk_api/index.d.ts +13 -0
  175. package/lib/risk_api/index.js +34 -0
  176. package/lib/risk_api/model/RiskActivity.d.ts +50 -0
  177. package/lib/risk_api/model/RiskActivity.js +2 -0
  178. package/lib/risk_api/model/RiskResponseV2.d.ts +10 -0
  179. package/lib/risk_api/model/RiskResponseV2.js +2 -0
  180. package/lib/risk_api/model/RiskResponseV3.d.ts +12 -0
  181. package/lib/risk_api/model/RiskResponseV3.js +2 -0
  182. package/lib/risk_api/model/RiskStatus.d.ts +4 -0
  183. package/lib/risk_api/model/RiskStatus.js +8 -0
  184. package/lib/risk_api/risk_response_handler/IRiskResponseHandler.d.ts +5 -0
  185. package/lib/risk_api/risk_response_handler/IRiskResponseHandler.js +2 -0
  186. package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.d.ts +16 -0
  187. package/lib/risk_api/risk_response_handler/RiskResponseHandlerBase.js +73 -0
  188. package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.d.ts +10 -0
  189. package/lib/risk_api/risk_response_handler/RiskResponseV2Handler.js +46 -0
  190. package/lib/risk_api/risk_response_handler/RiskResponseV3Handler.d.ts +10 -0
  191. package/lib/risk_api/risk_response_handler/RiskResponseV3Handler.js +47 -0
  192. package/lib/risk_token/MobileError.d.ts +6 -0
  193. package/lib/risk_token/MobileError.js +10 -0
  194. package/lib/risk_token/MobileErrorHandler.d.ts +9 -0
  195. package/lib/risk_token/MobileErrorHandler.js +100 -0
  196. package/lib/risk_token/RiskTokenScoreRetriever.d.ts +14 -0
  197. package/lib/risk_token/RiskTokenScoreRetriever.js +148 -0
  198. package/lib/risk_token/TokenOrigin.d.ts +4 -0
  199. package/lib/risk_token/TokenOrigin.js +8 -0
  200. package/lib/risk_token/TokenVerificationResult.d.ts +6 -0
  201. package/lib/risk_token/TokenVerificationResult.js +10 -0
  202. package/lib/risk_token/TokenVersion.d.ts +4 -0
  203. package/lib/risk_token/TokenVersion.js +8 -0
  204. package/lib/risk_token/constants.d.ts +9 -0
  205. package/lib/risk_token/constants.js +12 -0
  206. package/lib/risk_token/index.d.ts +9 -0
  207. package/lib/risk_token/index.js +32 -0
  208. package/lib/risk_token/token/BotDefenderTokenBase.d.ts +27 -0
  209. package/lib/risk_token/token/BotDefenderTokenBase.js +94 -0
  210. package/lib/risk_token/token/IBotDefenderToken.d.ts +54 -0
  211. package/lib/risk_token/token/IBotDefenderToken.js +2 -0
  212. package/lib/risk_token/token/index.d.ts +7 -0
  213. package/lib/risk_token/token/index.js +11 -0
  214. package/lib/risk_token/token/v2/BotDefenderTokenV2Payload.d.ts +6 -0
  215. package/lib/risk_token/token/v2/BotDefenderTokenV2Payload.js +2 -0
  216. package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.d.ts +28 -0
  217. package/lib/risk_token/token/v2/DefaultBotDefenderTokenV2.js +199 -0
  218. package/lib/risk_token/token/v3/BotDefenderTokenV3Payload.d.ts +9 -0
  219. package/lib/risk_token/token/v3/BotDefenderTokenV3Payload.js +2 -0
  220. package/lib/risk_token/token/v3/DefaultBotDefenderTokenV3.d.ts +31 -0
  221. package/lib/risk_token/token/v3/DefaultBotDefenderTokenV3.js +231 -0
  222. package/lib/risk_token/token/v3/TokenSignField.d.ts +4 -0
  223. package/lib/risk_token/token/v3/TokenSignField.js +8 -0
  224. package/lib/risk_token/utils.d.ts +2 -0
  225. package/lib/risk_token/utils.js +16 -0
  226. package/lib/telemetry/DefaultTelemetry.d.ts +19 -0
  227. package/lib/telemetry/DefaultTelemetry.js +176 -0
  228. package/lib/telemetry/ITelemetry.d.ts +13 -0
  229. package/lib/telemetry/ITelemetry.js +2 -0
  230. package/lib/telemetry/constants.d.ts +7 -0
  231. package/lib/telemetry/constants.js +10 -0
  232. package/lib/telemetry/index.d.ts +4 -0
  233. package/lib/telemetry/index.js +20 -0
  234. package/lib/telemetry/model/TelemetryActivity.d.ts +15 -0
  235. package/lib/telemetry/model/TelemetryActivity.js +2 -0
  236. package/lib/utils/Algorithm.d.ts +4 -0
  237. package/lib/utils/Algorithm.js +8 -0
  238. package/lib/utils/EnforcerException.d.ts +3 -0
  239. package/lib/utils/EnforcerException.js +26 -0
  240. package/lib/utils/IScoreRetriever.d.ts +14 -0
  241. package/lib/utils/IScoreRetriever.js +2 -0
  242. package/lib/utils/ModuleMode.d.ts +4 -0
  243. package/lib/utils/ModuleMode.js +8 -0
  244. package/lib/utils/PassReason.d.ts +6 -0
  245. package/lib/utils/PassReason.js +10 -0
  246. package/lib/utils/VidSource.d.ts +4 -0
  247. package/lib/utils/VidSource.js +8 -0
  248. package/lib/utils/base64/DefaultBase64Utils.d.ts +5 -0
  249. package/lib/utils/base64/DefaultBase64Utils.js +16 -0
  250. package/lib/utils/base64/IBase64Utils.d.ts +4 -0
  251. package/lib/utils/base64/IBase64Utils.js +2 -0
  252. package/lib/utils/base64/index.d.ts +2 -0
  253. package/lib/utils/base64/index.js +5 -0
  254. package/lib/utils/cipher/ICipherUtils.d.ts +7 -0
  255. package/lib/utils/cipher/ICipherUtils.js +2 -0
  256. package/lib/utils/cipher/index.d.ts +1 -0
  257. package/lib/utils/cipher/index.js +2 -0
  258. package/lib/utils/constants.d.ts +10 -0
  259. package/lib/utils/constants.js +13 -0
  260. package/lib/utils/cookie_parser/DefaultCookieParser.d.ts +4 -0
  261. package/lib/utils/cookie_parser/DefaultCookieParser.js +13 -0
  262. package/lib/utils/cookie_parser/ICookieParser.d.ts +3 -0
  263. package/lib/utils/cookie_parser/ICookieParser.js +2 -0
  264. package/lib/utils/cookie_parser/index.d.ts +2 -0
  265. package/lib/utils/cookie_parser/index.js +5 -0
  266. package/lib/utils/hash/DefaultHashUtils.d.ts +5 -0
  267. package/lib/utils/hash/DefaultHashUtils.js +19 -0
  268. package/lib/utils/hash/IHashUtils.d.ts +4 -0
  269. package/lib/utils/hash/IHashUtils.js +2 -0
  270. package/lib/utils/hash/index.d.ts +2 -0
  271. package/lib/utils/hash/index.js +5 -0
  272. package/lib/utils/index.d.ts +14 -0
  273. package/lib/utils/index.js +35 -0
  274. package/lib/utils/ip_range_checker/DefaultIpRangeChecker.d.ts +4 -0
  275. package/lib/utils/ip_range_checker/DefaultIpRangeChecker.js +13 -0
  276. package/lib/utils/ip_range_checker/IIpRangeChecker.d.ts +3 -0
  277. package/lib/utils/ip_range_checker/IIpRangeChecker.js +2 -0
  278. package/lib/utils/ip_range_checker/index.d.ts +2 -0
  279. package/lib/utils/ip_range_checker/index.js +5 -0
  280. package/lib/utils/utils.d.ts +13 -0
  281. package/lib/utils/utils.js +91 -0
  282. package/lib/utils/uuid_generator/DefaultUuidGenerator.d.ts +4 -0
  283. package/lib/utils/uuid_generator/DefaultUuidGenerator.js +13 -0
  284. package/lib/utils/uuid_generator/IUuidGenerator.d.ts +3 -0
  285. package/lib/utils/uuid_generator/IUuidGenerator.js +2 -0
  286. package/lib/utils/uuid_generator/index.d.ts +2 -0
  287. package/lib/utils/uuid_generator/index.js +5 -0
  288. package/package.json +52 -0
@@ -0,0 +1,14 @@
1
+ import { IContext } from '../context';
2
+ import { IConfiguration } from '../config';
3
+ import { IHttpResponse } from '../http';
4
+ import { IBase64Utils } from '../utils';
5
+ import { IBlockResponseGenerator } from './IBlockResponseGenerator';
6
+ export declare class DefaultBlockResponseGenerator implements IBlockResponseGenerator {
7
+ private readonly config;
8
+ private readonly captchaResponseGenerator;
9
+ constructor(config: IConfiguration, base64Utils: IBase64Utils);
10
+ shouldGenerate(context: IContext): boolean;
11
+ generateBlockResponse(context: IContext): IHttpResponse;
12
+ private generateRateLimitResponse;
13
+ private generateCaptchaResponse;
14
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultBlockResponseGenerator = void 0;
4
+ var pxhd_1 = require("../pxhd");
5
+ var http_1 = require("../http");
6
+ var BlockAction_1 = require("./BlockAction");
7
+ var CaptchaBlockResponseGenerator_1 = require("./captcha/CaptchaBlockResponseGenerator");
8
+ var rate_limit_template_1 = require("./templates/rate_limit_template");
9
+ var DefaultBlockResponseGenerator = /** @class */ (function () {
10
+ function DefaultBlockResponseGenerator(config, base64Utils) {
11
+ this.config = config;
12
+ this.captchaResponseGenerator = new CaptchaBlockResponseGenerator_1.CaptchaBlockResponseGenerator(config, base64Utils);
13
+ }
14
+ DefaultBlockResponseGenerator.prototype.shouldGenerate = function (context) {
15
+ return !context.isMonitoredRequest && !!context.blockReason;
16
+ };
17
+ DefaultBlockResponseGenerator.prototype.generateBlockResponse = function (context) {
18
+ var res;
19
+ switch (context.blockAction) {
20
+ case BlockAction_1.BlockAction.RATE_LIMIT:
21
+ res = this.generateRateLimitResponse();
22
+ break;
23
+ case BlockAction_1.BlockAction.CHALLENGE:
24
+ case BlockAction_1.BlockAction.CAPTCHA:
25
+ default:
26
+ res = this.generateCaptchaResponse(context);
27
+ break;
28
+ }
29
+ return pxhd_1.PXHDUtils.addPxhdToResponse(context, res);
30
+ };
31
+ DefaultBlockResponseGenerator.prototype.generateRateLimitResponse = function () {
32
+ var _a;
33
+ var status = 429;
34
+ var headers = (_a = {},
35
+ _a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.TEXT_HTML],
36
+ _a);
37
+ return new http_1.DefaultHttpResponse(rate_limit_template_1.RATE_LIMIT_TEMPLATE, { status: status, headers: headers });
38
+ };
39
+ DefaultBlockResponseGenerator.prototype.generateCaptchaResponse = function (context) {
40
+ return this.captchaResponseGenerator.generateBlockResponse(context);
41
+ };
42
+ return DefaultBlockResponseGenerator;
43
+ }());
44
+ exports.DefaultBlockResponseGenerator = DefaultBlockResponseGenerator;
@@ -0,0 +1,14 @@
1
+ import { IContext } from '../context';
2
+ import { IHttpResponse } from '../http';
3
+ export interface IBlockResponseGenerator {
4
+ /**
5
+ * @param context - The request context.
6
+ * @returns boolean - Whether or not a block response should be generated.
7
+ */
8
+ shouldGenerate(context: IContext): boolean;
9
+ /**
10
+ * @param context - The request context.
11
+ * @returns IHttpResponse - The block response that should be returned to the end-user.
12
+ */
13
+ generateBlockResponse(context: IContext): IHttpResponse;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import { IConfiguration } from '../../config';
2
+ import { IContext } from '../../context';
3
+ import { IHttpResponse } from '../../http';
4
+ import { IBase64Utils } from '../../utils';
5
+ import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
6
+ export declare class CaptchaBlockResponseGenerator implements IBlockResponseGenerator {
7
+ private readonly config;
8
+ private readonly jsonCaptchaGenerator;
9
+ private readonly mobileCaptchaGenerator;
10
+ private readonly htmlCaptchaGenerator;
11
+ constructor(config: IConfiguration, base64Utils: IBase64Utils);
12
+ shouldGenerate({ blockAction }: IContext): boolean;
13
+ generateBlockResponse(context: IContext): IHttpResponse;
14
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CaptchaBlockResponseGenerator = void 0;
4
+ var BlockAction_1 = require("../BlockAction");
5
+ var JsonCaptchaResponseGenerator_1 = require("./JsonCaptchaResponseGenerator");
6
+ var MobileCaptchaResponseGenerator_1 = require("./MobileCaptchaResponseGenerator");
7
+ var HtmlCaptchaResponseGenerator_1 = require("./HtmlCaptchaResponseGenerator");
8
+ var CaptchaBlockResponseGenerator = /** @class */ (function () {
9
+ function CaptchaBlockResponseGenerator(config, base64Utils) {
10
+ this.config = config;
11
+ this.jsonCaptchaGenerator = new JsonCaptchaResponseGenerator_1.JsonCaptchaResponseGenerator(config);
12
+ this.mobileCaptchaGenerator = new MobileCaptchaResponseGenerator_1.MobileCaptchaResponseGenerator(config, base64Utils);
13
+ this.htmlCaptchaGenerator = new HtmlCaptchaResponseGenerator_1.HtmlCaptchaResponseGenerator(config);
14
+ }
15
+ CaptchaBlockResponseGenerator.prototype.shouldGenerate = function (_a) {
16
+ var blockAction = _a.blockAction;
17
+ return blockAction === BlockAction_1.BlockAction.CAPTCHA || !Object.values(BlockAction_1.BlockAction).includes(blockAction);
18
+ };
19
+ CaptchaBlockResponseGenerator.prototype.generateBlockResponse = function (context) {
20
+ if (this.mobileCaptchaGenerator.shouldGenerate(context)) {
21
+ return this.mobileCaptchaGenerator.generateBlockResponse(context);
22
+ }
23
+ if (this.jsonCaptchaGenerator.shouldGenerate(context)) {
24
+ return this.jsonCaptchaGenerator.generateBlockResponse(context);
25
+ }
26
+ return this.htmlCaptchaGenerator.generateBlockResponse(context);
27
+ };
28
+ return CaptchaBlockResponseGenerator;
29
+ }());
30
+ exports.CaptchaBlockResponseGenerator = CaptchaBlockResponseGenerator;
@@ -0,0 +1,10 @@
1
+ import { IConfiguration } from '../../config';
2
+ import { IContext } from '../../context';
3
+ import { IHttpResponse } from '../../http';
4
+ import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
5
+ export declare class HtmlCaptchaResponseGenerator implements IBlockResponseGenerator {
6
+ private readonly config;
7
+ constructor(config: IConfiguration);
8
+ shouldGenerate(context: IContext): boolean;
9
+ generateBlockResponse(context: IContext): IHttpResponse;
10
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlCaptchaResponseGenerator = void 0;
4
+ var http_1 = require("../../http");
5
+ var utils_1 = require("../utils");
6
+ var captcha_template_1 = require("../templates/captcha_template");
7
+ var HtmlCaptchaResponseGenerator = /** @class */ (function () {
8
+ function HtmlCaptchaResponseGenerator(config) {
9
+ this.config = config;
10
+ }
11
+ HtmlCaptchaResponseGenerator.prototype.shouldGenerate = function (context) {
12
+ return true;
13
+ };
14
+ HtmlCaptchaResponseGenerator.prototype.generateBlockResponse = function (context) {
15
+ var _a;
16
+ var status = 403;
17
+ var headers = (_a = {},
18
+ _a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.TEXT_HTML],
19
+ _a);
20
+ var body = (0, utils_1.renderHtml)(captcha_template_1.CAPTCHA_TEMPLATE, (0, utils_1.createBlockData)(this.config, context));
21
+ return new http_1.DefaultHttpResponse(body, { status: status, headers: headers });
22
+ };
23
+ return HtmlCaptchaResponseGenerator;
24
+ }());
25
+ exports.HtmlCaptchaResponseGenerator = HtmlCaptchaResponseGenerator;
@@ -0,0 +1,10 @@
1
+ import { IConfiguration } from '../../config';
2
+ import { IContext } from '../../context';
3
+ import { IHttpResponse } from '../../http';
4
+ import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
5
+ export declare class JsonCaptchaResponseGenerator implements IBlockResponseGenerator {
6
+ private readonly config;
7
+ constructor(config: IConfiguration);
8
+ shouldGenerate(context: IContext): boolean;
9
+ generateBlockResponse(context: IContext): IHttpResponse;
10
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonCaptchaResponseGenerator = void 0;
4
+ var BlockAction_1 = require("../BlockAction");
5
+ var http_1 = require("../../http");
6
+ var utils_1 = require("../utils");
7
+ var JsonCaptchaResponseGenerator = /** @class */ (function () {
8
+ function JsonCaptchaResponseGenerator(config) {
9
+ this.config = config;
10
+ }
11
+ JsonCaptchaResponseGenerator.prototype.shouldGenerate = function (context) {
12
+ var _a, _b;
13
+ if (!this.config.advancedBlockingResponseEnabled) {
14
+ return false;
15
+ }
16
+ var acceptHeaderValue = ((_a = context.requestData.headers.get(http_1.ACCEPT_HEADER_NAME)) === null || _a === void 0 ? void 0 : _a[0]) ||
17
+ ((_b = context.requestData.headers.get(http_1.CONTENT_TYPE_HEADER_NAME)) === null || _b === void 0 ? void 0 : _b[0]) ||
18
+ '';
19
+ var acceptHeaderContainsJson = acceptHeaderValue === null || acceptHeaderValue === void 0 ? void 0 : acceptHeaderValue.split(',').some(function (value) { return value.toLowerCase() === http_1.ContentType.APPLICATION_JSON; });
20
+ return !context.isMobile && context.blockAction !== BlockAction_1.BlockAction.RATE_LIMIT && acceptHeaderContainsJson;
21
+ };
22
+ JsonCaptchaResponseGenerator.prototype.generateBlockResponse = function (context) {
23
+ var _a;
24
+ var status = 403;
25
+ var headers = (_a = {},
26
+ _a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.APPLICATION_JSON],
27
+ _a);
28
+ var blockData = (0, utils_1.createBlockData)(this.config, context);
29
+ var jsonBlockPayload = {
30
+ appId: blockData.appId,
31
+ jsClientSrc: blockData.jsClientSrc,
32
+ customLogo: blockData.customLogo,
33
+ firstPartyEnabled: blockData.firstPartyEnabled,
34
+ vid: blockData.vid,
35
+ uuid: blockData.uuid,
36
+ hostUrl: blockData.hostUrl,
37
+ blockScript: blockData.blockScript,
38
+ altBlockScript: blockData.altBlockScript,
39
+ };
40
+ return new http_1.DefaultHttpResponse(JSON.stringify(jsonBlockPayload), { status: status, headers: headers });
41
+ };
42
+ return JsonCaptchaResponseGenerator;
43
+ }());
44
+ exports.JsonCaptchaResponseGenerator = JsonCaptchaResponseGenerator;
@@ -0,0 +1,12 @@
1
+ import { IConfiguration } from '../../config';
2
+ import { IContext } from '../../context';
3
+ import { IHttpResponse } from '../../http';
4
+ import { IBase64Utils } from '../../utils';
5
+ import { IBlockResponseGenerator } from '../IBlockResponseGenerator';
6
+ export declare class MobileCaptchaResponseGenerator implements IBlockResponseGenerator {
7
+ private readonly config;
8
+ private readonly base64Utils;
9
+ constructor(config: IConfiguration, base64Utils: IBase64Utils);
10
+ shouldGenerate(context: IContext): boolean;
11
+ generateBlockResponse(context: IContext): IHttpResponse;
12
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MobileCaptchaResponseGenerator = void 0;
4
+ var http_1 = require("../../http");
5
+ var BlockAction_1 = require("../BlockAction");
6
+ var utils_1 = require("../utils");
7
+ var captcha_template_1 = require("../templates/captcha_template");
8
+ var MobileCaptchaResponseGenerator = /** @class */ (function () {
9
+ function MobileCaptchaResponseGenerator(config, base64Utils) {
10
+ this.config = config;
11
+ this.base64Utils = base64Utils;
12
+ }
13
+ MobileCaptchaResponseGenerator.prototype.shouldGenerate = function (context) {
14
+ return context.isMobile;
15
+ };
16
+ MobileCaptchaResponseGenerator.prototype.generateBlockResponse = function (context) {
17
+ var _a;
18
+ var status = 403;
19
+ var headers = (_a = {},
20
+ _a[http_1.CONTENT_TYPE_HEADER_NAME] = [http_1.ContentType.APPLICATION_JSON],
21
+ _a);
22
+ var blockData = (0, utils_1.createBlockData)(this.config, context);
23
+ var captchaPage = (0, utils_1.renderHtml)(captcha_template_1.CAPTCHA_TEMPLATE, blockData);
24
+ var mobileBlockPayload = {
25
+ action: (0, BlockAction_1.blockActionToWord)(blockData.blockAction),
26
+ uuid: blockData.uuid,
27
+ vid: blockData.vid,
28
+ appId: blockData.appId,
29
+ page: this.base64Utils.base64Encode(captchaPage),
30
+ collectorHost: this.config.backendCollectorUrl,
31
+ };
32
+ return new http_1.DefaultHttpResponse(JSON.stringify(mobileBlockPayload), { status: status, headers: headers });
33
+ };
34
+ return MobileCaptchaResponseGenerator;
35
+ }());
36
+ exports.MobileCaptchaResponseGenerator = MobileCaptchaResponseGenerator;
@@ -0,0 +1,13 @@
1
+ export { BlockData } from './model/BlockData';
2
+ export { JsonBlockPayload } from './model/JsonBlockPayload';
3
+ export { MobileBlockPayload } from './model/MobileBlockPayload';
4
+ export { BlockAction } from './BlockAction';
5
+ export { BlockReason } from './BlockReason';
6
+ export { IBlockResponseGenerator } from './IBlockResponseGenerator';
7
+ export { DefaultBlockResponseGenerator } from './DefaultBlockResponseGenerator';
8
+ export { CaptchaBlockResponseGenerator } from './captcha/CaptchaBlockResponseGenerator';
9
+ export { HtmlCaptchaResponseGenerator } from './captcha/HtmlCaptchaResponseGenerator';
10
+ export { JsonCaptchaResponseGenerator } from './captcha/JsonCaptchaResponseGenerator';
11
+ export { MobileCaptchaResponseGenerator } from './captcha/MobileCaptchaResponseGenerator';
12
+ export { CAPTCHA_TEMPLATE } from './templates/captcha_template';
13
+ export { RATE_LIMIT_TEMPLATE } from './templates/rate_limit_template';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RATE_LIMIT_TEMPLATE = exports.CAPTCHA_TEMPLATE = exports.MobileCaptchaResponseGenerator = exports.JsonCaptchaResponseGenerator = exports.HtmlCaptchaResponseGenerator = exports.CaptchaBlockResponseGenerator = exports.DefaultBlockResponseGenerator = exports.BlockReason = exports.BlockAction = void 0;
4
+ var BlockAction_1 = require("./BlockAction");
5
+ Object.defineProperty(exports, "BlockAction", { enumerable: true, get: function () { return BlockAction_1.BlockAction; } });
6
+ var BlockReason_1 = require("./BlockReason");
7
+ Object.defineProperty(exports, "BlockReason", { enumerable: true, get: function () { return BlockReason_1.BlockReason; } });
8
+ var DefaultBlockResponseGenerator_1 = require("./DefaultBlockResponseGenerator");
9
+ Object.defineProperty(exports, "DefaultBlockResponseGenerator", { enumerable: true, get: function () { return DefaultBlockResponseGenerator_1.DefaultBlockResponseGenerator; } });
10
+ var CaptchaBlockResponseGenerator_1 = require("./captcha/CaptchaBlockResponseGenerator");
11
+ Object.defineProperty(exports, "CaptchaBlockResponseGenerator", { enumerable: true, get: function () { return CaptchaBlockResponseGenerator_1.CaptchaBlockResponseGenerator; } });
12
+ var HtmlCaptchaResponseGenerator_1 = require("./captcha/HtmlCaptchaResponseGenerator");
13
+ Object.defineProperty(exports, "HtmlCaptchaResponseGenerator", { enumerable: true, get: function () { return HtmlCaptchaResponseGenerator_1.HtmlCaptchaResponseGenerator; } });
14
+ var JsonCaptchaResponseGenerator_1 = require("./captcha/JsonCaptchaResponseGenerator");
15
+ Object.defineProperty(exports, "JsonCaptchaResponseGenerator", { enumerable: true, get: function () { return JsonCaptchaResponseGenerator_1.JsonCaptchaResponseGenerator; } });
16
+ var MobileCaptchaResponseGenerator_1 = require("./captcha/MobileCaptchaResponseGenerator");
17
+ Object.defineProperty(exports, "MobileCaptchaResponseGenerator", { enumerable: true, get: function () { return MobileCaptchaResponseGenerator_1.MobileCaptchaResponseGenerator; } });
18
+ var captcha_template_1 = require("./templates/captcha_template");
19
+ Object.defineProperty(exports, "CAPTCHA_TEMPLATE", { enumerable: true, get: function () { return captcha_template_1.CAPTCHA_TEMPLATE; } });
20
+ var rate_limit_template_1 = require("./templates/rate_limit_template");
21
+ Object.defineProperty(exports, "RATE_LIMIT_TEMPLATE", { enumerable: true, get: function () { return rate_limit_template_1.RATE_LIMIT_TEMPLATE; } });
@@ -0,0 +1,16 @@
1
+ import { BlockAction } from '../BlockAction';
2
+ export declare type BlockData = {
3
+ appId: string;
4
+ hostUrl: string;
5
+ jsClientSrc: string;
6
+ firstPartyEnabled: boolean;
7
+ blockScript: string;
8
+ altBlockScript: string;
9
+ cssRef?: string;
10
+ vid?: string;
11
+ uuid?: string;
12
+ customLogo?: string;
13
+ jsRef?: string;
14
+ isMobile?: boolean;
15
+ blockAction?: BlockAction;
16
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export declare type JsonBlockPayload = {
2
+ appId: string;
3
+ jsClientSrc: string;
4
+ firstPartyEnabled: boolean;
5
+ vid: string;
6
+ uuid: string;
7
+ hostUrl: string;
8
+ blockScript: string;
9
+ altBlockScript: string;
10
+ customLogo?: string;
11
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export declare type MobileBlockPayload = {
2
+ action: string;
3
+ uuid: string;
4
+ vid: string;
5
+ appId: string;
6
+ page: string;
7
+ collectorHost: string;
8
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare const CAPTCHA_TEMPLATE = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"description\" content=\"px-captcha\">\n <title>Access to this page has been denied</title>\n {{cssRef}}\n</head>\n<body>\n <script>\n /* PerimeterX assignments */\n window._pxVid = '{{vid}}';\n window._pxUuid = '{{uuid}}';\n window._pxAppId = '{{appId}}';\n window._pxMobile = {{isMobile}};\n window._pxHostUrl = '{{hostUrl}}';\n window._pxCustomLogo = '{{customLogo}}';\n window._pxJsClientSrc = '{{jsClientSrc}}';\n window._pxFirstPartyEnabled = {{firstPartyEnabled}};\n var pxCaptchaSrc = '{{blockScript}}';\n\n var script = document.createElement('script');\n script.src = pxCaptchaSrc;\n script.onerror = function () {\n script = document.createElement('script');\n script.src = '{{altBlockScript}}';\n script.onerror = window._pxOnError;\n document.head.appendChild(script);\n };\n window._pxOnError = function () {\n var style = document.createElement('style');\n style.innerText = '@import url(https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap);body{background-color:#fafbfc}.px-captcha-error-container{position:fixed;height:340px;background-color:#fff;font-family:Roboto,sans-serif}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:67px 0 33px;font-weight:500;line-height:.83;text-align:center}.px-captcha-error-message{color:#f0f1f2;font-size:18px;margin:0 0 29px;line-height:1.33;text-align:center}.px-captcha-error-button{text-align:center;line-height:48px;width:253px;margin:auto;border-radius:50px;border:solid 1px #f0f1f2;font-size:20px;color:#f0f1f2}.px-captcha-error-wrapper{margin:18px 0 0}div.px-captcha-error{margin:auto;text-align:center;width:400px;height:30px;font-size:12px;background-color:#fcf0f2;color:#ce0e2d}img.px-captcha-error{margin:6px 8px -2px 0}.px-captcha-error-refid{border-top:solid 1px #f0eeee;height:27px;margin:13px 0 0;border-radius:0 0 3px 3px;background-color:#fafbfc;font-size:10px;line-height:2.5;text-align:center;color:#b1b5b8}@media (min-width:620px){.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (min-width:481px) and (max-width:620px){.px-captcha-error-container{width:85%;top:50%;left:50%;margin-top:-170px;margin-left:-42.5%;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (max-width:480px){body{background-color:#fff}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:55px 0 33px}.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px}.px-captcha-error-refid{position:fixed;width:100%;left:0;bottom:0;border-radius:0;font-size:14px;line-height:2}}@media (max-width:390px){div.px-captcha-error{font-size:10px}.px-captcha-error-refid{font-size:11px;line-height:2.5}}';\n document.head.appendChild(style);\n var div = document.createElement('div');\n div.className = 'px-captcha-error-container';\n div.innerHTML = '<div class=\"px-captcha-error-header\">Before we continue...</div><div class=\"px-captcha-error-message\">Press & Hold to confirm you are<br>a human (and not a bot).</div><div class=\"px-captcha-error-button\">Press & Hold</div><div class=\"px-captcha-error-wrapper\"><div class=\"px-captcha-error\"><img class=\"px-captcha-error\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAQCAMAAADDGrRQAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABFUExURUdwTNYELOEGONQILd0AONwALtwEL+AAL9MFLfkJSNQGLdMJLdQJLdQGLdQKLtYFLNcELdUGLdcBL9gFL88OLdUFLNEOLglBhT4AAAAXdFJOUwC8CqgNIRgRoAS1dWWuR4RTjzgryZpYblfkcAAAAI9JREFUGNNdj+sWhCAIhAdvqGVa1r7/oy6RZ7eaH3D4ZACBIed9wlOOMtUnSrEmZ6cHa9YAIfsbCkWrdpi/c50Bk2CO9mNLdMAu03wJA3HpEnfpxbyOg6ruyx8JJi6KNstnslp1dbPd9GnqmuYq7mmcv1zjnbQw8cV0xzkqo+fX1zkjUOO7wnrInUTxJiruC3vtBNRoQQn2AAAAAElFTkSuQmCC\">Please check your internet connection' + (window._pxMobile ? '' : ' or disable your ad-blocker') + '.</div></div><div class=\"px-captcha-error-refid\">Reference ID ' + window._pxUuid + '</div>';\n document.body.appendChild(div);\n if (window._pxMobile) {\n setTimeout(function() {\n location.href = '/px/captcha_close?status=-1';\n }, 5000);\n }\n };\n document.head.appendChild(script);\n </script>\n {{jsRef}}\n</body>\n</html>\n";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CAPTCHA_TEMPLATE = void 0;
4
+ exports.CAPTCHA_TEMPLATE = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n <meta name=\"description\" content=\"px-captcha\">\n <title>Access to this page has been denied</title>\n {{cssRef}}\n</head>\n<body>\n <script>\n /* PerimeterX assignments */\n window._pxVid = '{{vid}}';\n window._pxUuid = '{{uuid}}';\n window._pxAppId = '{{appId}}';\n window._pxMobile = {{isMobile}};\n window._pxHostUrl = '{{hostUrl}}';\n window._pxCustomLogo = '{{customLogo}}';\n window._pxJsClientSrc = '{{jsClientSrc}}';\n window._pxFirstPartyEnabled = {{firstPartyEnabled}};\n var pxCaptchaSrc = '{{blockScript}}';\n\n var script = document.createElement('script');\n script.src = pxCaptchaSrc;\n script.onerror = function () {\n script = document.createElement('script');\n script.src = '{{altBlockScript}}';\n script.onerror = window._pxOnError;\n document.head.appendChild(script);\n };\n window._pxOnError = function () {\n var style = document.createElement('style');\n style.innerText = '@import url(https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap);body{background-color:#fafbfc}.px-captcha-error-container{position:fixed;height:340px;background-color:#fff;font-family:Roboto,sans-serif}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:67px 0 33px;font-weight:500;line-height:.83;text-align:center}.px-captcha-error-message{color:#f0f1f2;font-size:18px;margin:0 0 29px;line-height:1.33;text-align:center}.px-captcha-error-button{text-align:center;line-height:48px;width:253px;margin:auto;border-radius:50px;border:solid 1px #f0f1f2;font-size:20px;color:#f0f1f2}.px-captcha-error-wrapper{margin:18px 0 0}div.px-captcha-error{margin:auto;text-align:center;width:400px;height:30px;font-size:12px;background-color:#fcf0f2;color:#ce0e2d}img.px-captcha-error{margin:6px 8px -2px 0}.px-captcha-error-refid{border-top:solid 1px #f0eeee;height:27px;margin:13px 0 0;border-radius:0 0 3px 3px;background-color:#fafbfc;font-size:10px;line-height:2.5;text-align:center;color:#b1b5b8}@media (min-width:620px){.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (min-width:481px) and (max-width:620px){.px-captcha-error-container{width:85%;top:50%;left:50%;margin-top:-170px;margin-left:-42.5%;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (max-width:480px){body{background-color:#fff}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:55px 0 33px}.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px}.px-captcha-error-refid{position:fixed;width:100%;left:0;bottom:0;border-radius:0;font-size:14px;line-height:2}}@media (max-width:390px){div.px-captcha-error{font-size:10px}.px-captcha-error-refid{font-size:11px;line-height:2.5}}';\n document.head.appendChild(style);\n var div = document.createElement('div');\n div.className = 'px-captcha-error-container';\n div.innerHTML = '<div class=\"px-captcha-error-header\">Before we continue...</div><div class=\"px-captcha-error-message\">Press & Hold to confirm you are<br>a human (and not a bot).</div><div class=\"px-captcha-error-button\">Press & Hold</div><div class=\"px-captcha-error-wrapper\"><div class=\"px-captcha-error\"><img class=\"px-captcha-error\" src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAQCAMAAADDGrRQAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABFUExURUdwTNYELOEGONQILd0AONwALtwEL+AAL9MFLfkJSNQGLdMJLdQJLdQGLdQKLtYFLNcELdUGLdcBL9gFL88OLdUFLNEOLglBhT4AAAAXdFJOUwC8CqgNIRgRoAS1dWWuR4RTjzgryZpYblfkcAAAAI9JREFUGNNdj+sWhCAIhAdvqGVa1r7/oy6RZ7eaH3D4ZACBIed9wlOOMtUnSrEmZ6cHa9YAIfsbCkWrdpi/c50Bk2CO9mNLdMAu03wJA3HpEnfpxbyOg6ruyx8JJi6KNstnslp1dbPd9GnqmuYq7mmcv1zjnbQw8cV0xzkqo+fX1zkjUOO7wnrInUTxJiruC3vtBNRoQQn2AAAAAElFTkSuQmCC\">Please check your internet connection' + (window._pxMobile ? '' : ' or disable your ad-blocker') + '.</div></div><div class=\"px-captcha-error-refid\">Reference ID ' + window._pxUuid + '</div>';\n document.body.appendChild(div);\n if (window._pxMobile) {\n setTimeout(function() {\n location.href = '/px/captcha_close?status=-1';\n }, 5000);\n }\n };\n document.head.appendChild(script);\n </script>\n {{jsRef}}\n</body>\n</html>\n";
@@ -0,0 +1 @@
1
+ export declare const RATE_LIMIT_TEMPLATE = "<html>\n<head>\n <title>Too Many Requests</title>\n</head>\n<body>\n <h1>Too Many Requests</h1>\n <p>Reached maximum requests limitation, try again soon.</p>\n</body>\n</html>\n";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RATE_LIMIT_TEMPLATE = void 0;
4
+ exports.RATE_LIMIT_TEMPLATE = "<html>\n<head>\n <title>Too Many Requests</title>\n</head>\n<body>\n <h1>Too Many Requests</h1>\n <p>Reached maximum requests limitation, try again soon.</p>\n</body>\n</html>\n";
@@ -0,0 +1,5 @@
1
+ import { IConfiguration } from '../config';
2
+ import { IContext } from '../context';
3
+ import { BlockData } from './model/BlockData';
4
+ export declare const renderHtml: (htmlTemplate: string, blockData?: BlockData) => string;
5
+ export declare const createBlockData: (config: IConfiguration, context: IContext) => BlockData;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBlockData = exports.renderHtml = void 0;
4
+ var utils_1 = require("../utils");
5
+ var first_party_1 = require("../first_party");
6
+ var renderHtml = function (htmlTemplate, blockData) {
7
+ if (!blockData) {
8
+ return htmlTemplate;
9
+ }
10
+ Object.entries(blockData).forEach(function (_a) {
11
+ var key = _a[0], value = _a[1];
12
+ var replace = "{{".concat(key, "}}");
13
+ var regEx = new RegExp(replace, 'g');
14
+ htmlTemplate = htmlTemplate.replace(regEx, "".concat(value));
15
+ });
16
+ return htmlTemplate;
17
+ };
18
+ exports.renderHtml = renderHtml;
19
+ var createBlockData = function (config, context) {
20
+ var _a, _b;
21
+ var captchaParams = "/captcha.js?a=".concat(context.blockAction, "&u=").concat(context.uuid, "&v=").concat(context.vid || '', "&m=").concat(context.isMobile ? '1' : '0');
22
+ var jsClientSrc = "".concat(config.backendClientUrl, "/").concat(config.appId, "/main.min.js");
23
+ var blockScript = "".concat(config.backendCaptchaUrl, "/").concat(config.appId).concat(captchaParams);
24
+ var hostUrl = config.backendCollectorUrl;
25
+ if (config.firstPartyEnabled && !context.isMobile) {
26
+ jsClientSrc = (0, first_party_1.getFirstPartySensorScriptPath)(config.firstPartyPrefix);
27
+ blockScript = "".concat((0, first_party_1.getFirstPartyCaptchaScriptPathPrefix)(config.firstPartyPrefix)).concat(captchaParams);
28
+ hostUrl = (0, first_party_1.getFirstPartyXhrPathPrefix)(config.firstPartyPrefix);
29
+ }
30
+ var cssRef = config.cssRef ? "<link rel=\"stylesheet\" type=\"text/css\" href=\"".concat(config.cssRef, "\" />") : '';
31
+ var jsRef = config.jsRef ? "<script src=\"".concat(config.jsRef, "\"></script>") : '';
32
+ var altBlockScript = "".concat(config.altBackendCaptchaUrl, "/").concat(config.appId).concat(captchaParams);
33
+ return {
34
+ appId: config.appId,
35
+ vid: context.vid || ((_b = (_a = context.requestData) === null || _a === void 0 ? void 0 : _a.cookies) === null || _b === void 0 ? void 0 : _b[utils_1.PXVID_COOKIE_NAME]) || '',
36
+ uuid: context.uuid || '',
37
+ isMobile: context.isMobile,
38
+ customLogo: config.customLogo || '',
39
+ hostUrl: hostUrl,
40
+ cssRef: cssRef,
41
+ jsRef: jsRef,
42
+ jsClientSrc: jsClientSrc,
43
+ firstPartyEnabled: config.firstPartyEnabled,
44
+ blockScript: blockScript,
45
+ altBlockScript: altBlockScript,
46
+ };
47
+ };
48
+ exports.createBlockData = createBlockData;
@@ -0,0 +1,65 @@
1
+ import { CustomParametersFunction } from '../custom_parameters';
2
+ import { AdditionalActivityHandler } from '../additional_activity_handler';
3
+ export declare type ConfigurationParams = {
4
+ px_app_id: string;
5
+ px_auth_token: string;
6
+ px_cookie_secret: string;
7
+ px_s2s_timeout?: number;
8
+ px_backend_url?: string;
9
+ px_blocking_score?: number;
10
+ px_user_agent_max_length?: number;
11
+ px_risk_cookie_max_length?: number;
12
+ px_risk_cookie_min_iterations?: number;
13
+ px_risk_cookie_max_iterations?: number;
14
+ px_logger_severity?: 'debug' | 'error' | 'none';
15
+ px_ip_headers?: string[];
16
+ px_module_enabled?: boolean;
17
+ px_module_mode?: 'monitor' | 'active_blocking';
18
+ px_advanced_blocking_response_enabled?: boolean;
19
+ px_max_activity_batch_size?: number;
20
+ px_batch_activities_timeout_ms?: number;
21
+ px_bypass_monitor_header?: string;
22
+ px_csp_enabled?: boolean;
23
+ px_csp_no_updates_max_interval_minutes?: number;
24
+ px_csp_policy_refresh_interval_minutes?: number;
25
+ px_enforced_routes?: string[];
26
+ px_first_party_enabled?: boolean;
27
+ px_first_party_prefix?: string;
28
+ px_backend_captcha_url?: string;
29
+ px_backend_client_url?: string;
30
+ px_backend_collector_url?: string;
31
+ px_login_credentials_extraction_enabled?: boolean;
32
+ px_login_credentials_extraction?: object[];
33
+ px_credentials_intelligence_version?: 'v2' | 'multistep_sso';
34
+ px_compromised_credentials_header?: string;
35
+ px_send_raw_username_on_additional_s2s_activity?: boolean;
36
+ px_additional_s2s_activity_header_enabled?: boolean;
37
+ px_login_successful_reporting_method?: '' | 'status' | 'body' | 'header' | 'custom';
38
+ px_login_successful_body_regex?: string;
39
+ px_login_successful_header_name?: string;
40
+ px_login_successful_header_value?: string;
41
+ px_login_successful_status?: number[];
42
+ px_monitored_routes?: string[];
43
+ px_sensitive_headers?: string[];
44
+ px_sensitive_routes?: string[];
45
+ px_filter_by_extension?: string[];
46
+ px_filter_by_http_method?: string[];
47
+ px_filter_by_ip?: string[];
48
+ px_filter_by_route?: string[];
49
+ px_filter_by_user_agent?: string[];
50
+ px_css_ref?: string;
51
+ px_js_ref?: string;
52
+ px_custom_cookie_header?: string;
53
+ px_custom_logo?: string;
54
+ px_proxy_url?: string;
55
+ px_jwt_cookie_name?: string;
56
+ px_jwt_cookie_user_id_field_name?: string;
57
+ px_jwt_cookie_additional_field_names?: string[];
58
+ px_jwt_header_name?: string;
59
+ px_jwt_header_user_id_field_name?: string;
60
+ px_jwt_header_additional_field_names?: string[];
61
+ px_extract_ip?: () => {};
62
+ px_additional_activity_handler?: AdditionalActivityHandler;
63
+ px_enrich_custom_parameters?: CustomParametersFunction;
64
+ px_login_successful_custom_callback?: () => {};
65
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { ConfigurationParams } from './ConfigurationParams';
2
+ export declare const DEFAULT_CONFIGURATIONS: ConfigurationParams;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_CONFIGURATIONS = void 0;
4
+ var LoggerSeverity_1 = require("../logger/LoggerSeverity");
5
+ var ModuleMode_1 = require("../utils/ModuleMode");
6
+ exports.DEFAULT_CONFIGURATIONS = {
7
+ px_app_id: '',
8
+ px_auth_token: '',
9
+ px_cookie_secret: '',
10
+ px_s2s_timeout: 1000,
11
+ px_blocking_score: 100,
12
+ px_user_agent_max_length: 8528,
13
+ px_risk_cookie_max_length: 2048,
14
+ px_risk_cookie_min_iterations: 500,
15
+ px_risk_cookie_max_iterations: 5000,
16
+ px_logger_severity: LoggerSeverity_1.LoggerSeverity.ERROR,
17
+ px_ip_headers: [],
18
+ px_extract_ip: null,
19
+ px_module_enabled: true,
20
+ px_module_mode: ModuleMode_1.ModuleMode.MONITOR,
21
+ px_additional_activity_handler: null,
22
+ px_advanced_blocking_response_enabled: true,
23
+ px_max_activity_batch_size: 20,
24
+ px_batch_activities_timeout_ms: 1000,
25
+ px_bypass_monitor_header: '',
26
+ px_csp_enabled: false,
27
+ px_csp_no_updates_max_interval_minutes: 60,
28
+ px_csp_policy_refresh_interval_minutes: 5,
29
+ px_enforced_routes: [],
30
+ px_first_party_enabled: true,
31
+ px_first_party_prefix: '',
32
+ px_backend_url: '',
33
+ px_backend_collector_url: '',
34
+ px_backend_captcha_url: 'https://captcha.px-cdn.net',
35
+ px_backend_client_url: 'https://client.perimeterx.net',
36
+ px_login_credentials_extraction_enabled: false,
37
+ px_login_credentials_extraction: [],
38
+ px_credentials_intelligence_version: 'v2',
39
+ px_compromised_credentials_header: 'px-compromised-credentials',
40
+ px_send_raw_username_on_additional_s2s_activity: false,
41
+ px_additional_s2s_activity_header_enabled: false,
42
+ px_login_successful_reporting_method: '',
43
+ px_login_successful_body_regex: '',
44
+ px_login_successful_header_name: '',
45
+ px_login_successful_header_value: '',
46
+ px_login_successful_status: [],
47
+ px_login_successful_custom_callback: null,
48
+ px_monitored_routes: [],
49
+ px_sensitive_headers: ['cookie', 'cookies'],
50
+ px_sensitive_routes: [],
51
+ px_filter_by_extension: [
52
+ '.css',
53
+ '.bmp',
54
+ '.tif',
55
+ '.ttf',
56
+ '.docx',
57
+ '.woff2',
58
+ '.js',
59
+ '.pict',
60
+ '.tiff',
61
+ '.eot',
62
+ '.xlsx',
63
+ '.jpg',
64
+ '.csv',
65
+ '.eps',
66
+ '.woff',
67
+ '.xls',
68
+ '.jpeg',
69
+ '.doc',
70
+ '.ejs',
71
+ '.otf',
72
+ '.pptx',
73
+ '.gif',
74
+ '.pdf',
75
+ '.swf',
76
+ '.svg',
77
+ '.ps',
78
+ '.ico',
79
+ '.pls',
80
+ '.midi',
81
+ '.svgz',
82
+ '.class',
83
+ '.png',
84
+ '.ppt',
85
+ '.mid',
86
+ '.webp',
87
+ '.jar',
88
+ '.json',
89
+ '.xml',
90
+ ],
91
+ px_filter_by_http_method: [],
92
+ px_filter_by_ip: [],
93
+ px_filter_by_route: [],
94
+ px_filter_by_user_agent: [],
95
+ px_css_ref: '',
96
+ px_js_ref: '',
97
+ px_custom_cookie_header: '',
98
+ px_custom_logo: '',
99
+ px_enrich_custom_parameters: null,
100
+ px_proxy_url: '',
101
+ px_jwt_cookie_name: '',
102
+ px_jwt_cookie_user_id_field_name: '',
103
+ px_jwt_cookie_additional_field_names: [],
104
+ px_jwt_header_name: '',
105
+ px_jwt_header_user_id_field_name: '',
106
+ px_jwt_header_additional_field_names: [],
107
+ };