@forge/egress 1.1.2 → 1.1.3-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @forge/egress
2
2
 
3
+ ## 1.1.3-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 0da2b48: Removed support for the CLI running on node 14
8
+
3
9
  ## 1.1.2
4
10
 
5
11
  ### Patch Changes
@@ -2,10 +2,10 @@ export declare class EgressFilteringService {
2
2
  private readonly URLs;
3
3
  private readonly wildcardDomains;
4
4
  private readonly allowsEverything;
5
+ private readonly DEFAULT_PROTOCOL;
5
6
  constructor(allowList: string[]);
6
- private safeURL;
7
+ private parseUrl;
7
8
  isValidUrl(url: string): boolean;
8
- private domainCheck;
9
- private domainIsAllowed;
9
+ private allowedDomain;
10
10
  }
11
11
  //# sourceMappingURL=egress-filtering-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"egress-filtering-service.d.ts","sourceRoot":"","sources":["../../src/egress/egress-filtering-service.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;gBAE/B,SAAS,EAAE,MAAM,EAAE;IAU/B,OAAO,CAAC,OAAO;IAQR,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAQvC,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,eAAe;CAWxB"}
1
+ {"version":3,"file":"egress-filtering-service.d.ts","sourceRoot":"","sources":["../../src/egress/egress-filtering-service.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAc;gBAEnC,SAAS,EAAE,MAAM,EAAE;IAU/B,OAAO,CAAC,QAAQ;IAQT,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IASvC,OAAO,CAAC,aAAa;CAKtB"}
@@ -6,37 +6,30 @@ const minimatch_1 = tslib_1.__importDefault(require("minimatch"));
6
6
  const url_1 = require("url");
7
7
  class EgressFilteringService {
8
8
  constructor(allowList) {
9
- this.URLs = allowList.filter((domainOrURL) => !domainOrURL.startsWith('*')).map((url) => this.safeURL(url));
9
+ this.DEFAULT_PROTOCOL = 'https://';
10
+ this.URLs = allowList.filter((domainOrURL) => !domainOrURL.startsWith('*')).map((url) => this.parseUrl(url));
10
11
  this.wildcardDomains = allowList
11
12
  .filter((domainOrURL) => domainOrURL !== '*')
12
- .map((url) => this.safeURL(url))
13
+ .map((url) => this.parseUrl(url))
13
14
  .filter((url) => decodeURIComponent(url.hostname).startsWith('*'));
14
15
  this.allowsEverything = allowList.includes('*');
15
16
  }
16
- safeURL(url, defaultProtocol = 'https://') {
17
+ parseUrl(url) {
17
18
  const protocolRegex = /^(.*:\/\/)/;
18
19
  const urlParser = url_1.URL !== null && url_1.URL !== void 0 ? url_1.URL : window.URL;
19
- return new urlParser(protocolRegex.test(url) ? url : `${defaultProtocol}${url}`);
20
+ return new urlParser(protocolRegex.test(url) ? url : `${this.DEFAULT_PROTOCOL}${url}`);
20
21
  }
21
22
  isValidUrl(url) {
22
23
  if (this.allowsEverything) {
23
24
  return true;
24
25
  }
25
- return this.domainIsAllowed(this.safeURL(url));
26
+ const parsedUrl = this.parseUrl(url);
27
+ return this.allowedDomain(parsedUrl, this.URLs) || this.allowedDomain(parsedUrl, this.wildcardDomains);
26
28
  }
27
- domainCheck(domain, allowList) {
29
+ allowedDomain(domain, allowList) {
28
30
  return allowList
29
31
  .filter((allowed) => allowed.protocol === domain.protocol)
30
32
  .some((url) => (0, minimatch_1.default)(domain.hostname, decodeURIComponent(url.hostname)));
31
33
  }
32
- domainIsAllowed(domain) {
33
- if (this.domainCheck(domain, this.URLs)) {
34
- return true;
35
- }
36
- if (this.domainCheck(domain, this.wildcardDomains)) {
37
- return true;
38
- }
39
- return false;
40
- }
41
34
  }
42
35
  exports.EgressFilteringService = EgressFilteringService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/egress",
3
- "version": "1.1.2",
3
+ "version": "1.1.3-next.0",
4
4
  "description": "Helpers and utils for egress implementation in Forge apps",
5
5
  "main": "out/index.js",
6
6
  "author": "Atlassian",