perimeterx-js-core 0.6.0 → 0.6.1

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.
@@ -2,7 +2,7 @@ import { CompositePhase, EnrichContextFromResponsePhase, ModifyOutgoingResponseP
2
2
  export class PostEnforceFlow extends CompositePhase {
3
3
  constructor(config, { products, activityClient }) {
4
4
  super([
5
- new EnrichContextFromResponsePhase(products),
5
+ new EnrichContextFromResponsePhase(config, products),
6
6
  new ModifyOutgoingResponsePhase(Object.values(products)),
7
7
  new SendAsyncActivitiesOnResponsePhase(activityClient),
8
8
  ]);
@@ -22,6 +22,7 @@ export class CreateBlockResponsePhase {
22
22
  if (context.action !== Action.BLOCK) {
23
23
  return { done: false };
24
24
  }
25
+ this.config.logger.debug('create block response phase');
25
26
  let response = this.createBlockResponse(context);
26
27
  if (!response) {
27
28
  return { done: false };
@@ -18,6 +18,7 @@ export class EnrichContextFromRequestPhase extends DecideActionPhase {
18
18
  }
19
19
  execute(context) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
+ this.config.logger.debug('enrich context from request phase');
21
22
  yield this.addPxdeToContext(context);
22
23
  yield this.addGraphQLDataToContext(context);
23
24
  yield this.addProductDataToContext(context);
@@ -2,9 +2,11 @@ import { IContext } from '../../context';
2
2
  import { Products } from '../../products';
3
3
  import { IPhase } from '../IPhase';
4
4
  import { PhaseResult } from '../PhaseResult';
5
+ import { IConfiguration } from '../../config';
5
6
  export declare class EnrichContextFromResponsePhase<Req, Res> implements IPhase<Req, Res> {
7
+ protected readonly config: IConfiguration<Req, Res>;
6
8
  protected readonly products: Products<Req, Res>;
7
- constructor(products: Products<Req, Res>);
9
+ constructor(config: IConfiguration<Req, Res>, products: Products<Req, Res>);
8
10
  execute(context: IContext<Req, Res>): Promise<PhaseResult>;
9
11
  protected addProductDataToContext(context: IContext<Req, Res>): Promise<void>;
10
12
  }
@@ -8,11 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  export class EnrichContextFromResponsePhase {
11
- constructor(products) {
11
+ constructor(config, products) {
12
+ this.config = config;
12
13
  this.products = products;
13
14
  }
14
15
  execute(context) {
15
16
  return __awaiter(this, void 0, void 0, function* () {
17
+ this.config.logger.debug('enrich context from response phase');
16
18
  yield this.addProductDataToContext(context);
17
19
  return { done: false };
18
20
  });
@@ -11,6 +11,7 @@ import { removeSensitiveHeaders } from '../../../utils';
11
11
  import { COOKIE_HEADER_NAME, HOST_HEADER_NAME, X_FORWARDED_FOR_HEADER_NAME, OutgoingRequestImpl, MinimalResponseImpl, toMutableHeaders, } from '../../../http';
12
12
  import { getFirstPartyCaptchaScriptPathPrefixes, getFirstPartySensorScriptPaths, getFirstPartyXhrPathPrefixes, } from './utils';
13
13
  import { DEFAULT_CLIENT_RESPONSE_OPTIONS, DEFAULT_GIF_RESPONSE, DEFAULT_XHR_RESPONSE, FIRST_PARTY_HEADER_NAME, FIRST_PARTY_HEADER_VALUE, X_PX_ENFORCER_TRUE_IP_HEADER_NAME, } from './constants';
14
+ import { FirstPartySuffix } from './FirstPartySuffix';
14
15
  export class DefaultBotDefenderFirstParty {
15
16
  constructor(config) {
16
17
  this.config = config;
@@ -27,7 +28,7 @@ export class DefaultBotDefenderFirstParty {
27
28
  }
28
29
  const captchaPrefix = getFirstPartyCaptchaScriptPathPrefixes(this.config).find((prefix) => pathname.startsWith(prefix));
29
30
  if (captchaPrefix) {
30
- return yield this.proxyCaptchaScriptRequest(context, captchaPrefix);
31
+ return yield this.proxyCaptchaScriptRequest(context);
31
32
  }
32
33
  return null;
33
34
  });
@@ -40,6 +41,7 @@ export class DefaultBotDefenderFirstParty {
40
41
  }
41
42
  const url = this.getThirdPartySensorScriptUrl();
42
43
  const request = yield this.getOutgoingRequest(url, context);
44
+ this.config.logger.debug(`proxying sensor script ${context.requestData.url.pathname} to ${url}`);
43
45
  return { request, defaultResponse };
44
46
  });
45
47
  }
@@ -51,6 +53,7 @@ export class DefaultBotDefenderFirstParty {
51
53
  }
52
54
  const url = this.getThirdPartyXhrUrl(context, prefix);
53
55
  const request = yield this.getOutgoingRequest(url, context);
56
+ this.config.logger.debug(`proxying XHR request ${context.requestData.url.pathname} to ${url}`);
54
57
  return { request, defaultResponse };
55
58
  });
56
59
  }
@@ -62,14 +65,15 @@ export class DefaultBotDefenderFirstParty {
62
65
  headers: options.headers,
63
66
  });
64
67
  }
65
- proxyCaptchaScriptRequest(context, prefix) {
68
+ proxyCaptchaScriptRequest(context) {
66
69
  return __awaiter(this, void 0, void 0, function* () {
67
70
  const defaultResponse = new MinimalResponseImpl(DEFAULT_CLIENT_RESPONSE_OPTIONS);
68
71
  if (!this.config.firstPartyEnabled) {
69
72
  return { defaultResponse };
70
73
  }
71
- const url = this.getThirdPartyCaptchaScriptUrl(context, prefix);
74
+ const url = this.getThirdPartyCaptchaScriptUrl(context);
72
75
  const request = yield this.getOutgoingRequest(url, context);
76
+ this.config.logger.debug(`proxying captcha script ${context.requestData.url.pathname} to ${url}`);
73
77
  return { request, defaultResponse };
74
78
  });
75
79
  }
@@ -114,12 +118,10 @@ export class DefaultBotDefenderFirstParty {
114
118
  getThirdPartySensorScriptUrl() {
115
119
  return `${this.config.backendClientUrl}/${this.config.appId}/main.min.js`;
116
120
  }
117
- getThirdPartyCaptchaScriptUrl(context, prefix) {
121
+ getThirdPartyCaptchaScriptUrl(context) {
118
122
  const originalUrl = context.requestData.url;
119
123
  const { appId, backendCaptchaUrl } = this.config;
120
- const regExString = `${originalUrl.origin}${prefix}`;
121
- const regEx = new RegExp(regExString, 'ig');
122
- return `${backendCaptchaUrl}/${appId}${originalUrl.href.replace(regEx, '')}`;
124
+ return `${backendCaptchaUrl}/${appId}${FirstPartySuffix.CAPTCHA}.js${originalUrl.search}`;
123
125
  }
124
126
  getThirdPartyXhrUrl(context, prefix) {
125
127
  const originalUrl = context.requestData.url;
@@ -2,7 +2,7 @@ import { IDataEnrichment } from './IDataEnrichment';
2
2
  import { IConfiguration } from '../config';
3
3
  import { ReadonlyContext } from '../context';
4
4
  import { IBase64Utils, IHmacUtils } from '../utils';
5
- import { PxdeData } from './model/PxdeData';
5
+ import { PxdeData } from './model';
6
6
  export declare class DefaultDataEnrichment<Req, Res> implements IDataEnrichment<Req, Res> {
7
7
  private readonly config;
8
8
  private readonly base64Utils;
@@ -8,4 +8,4 @@ export declare const X_PX_AUTHORIZATION_HEADER_NAME = "x-px-authorization";
8
8
  export declare const X_PX_ORIGINAL_TOKEN_HEADER_NAME = "x-px-original-token";
9
9
  export declare const X_PX_BYPASS_REASON_HEADER_NAME = "x-px-bypass-reason";
10
10
  export declare const EMAIL_ADDRESS_REGEX: RegExp;
11
- export declare const CORE_MODULE_VERSION = "JS Core 0.6.0";
11
+ export declare const CORE_MODULE_VERSION = "JS Core 0.6.1";
@@ -8,4 +8,4 @@ export const X_PX_AUTHORIZATION_HEADER_NAME = 'x-px-authorization';
8
8
  export const X_PX_ORIGINAL_TOKEN_HEADER_NAME = 'x-px-original-token';
9
9
  export const X_PX_BYPASS_REASON_HEADER_NAME = 'x-px-bypass-reason';
10
10
  export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
11
- export const CORE_MODULE_VERSION = 'JS Core 0.6.0';
11
+ export const CORE_MODULE_VERSION = 'JS Core 0.6.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perimeterx-js-core",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",