@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
|
@@ -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
|
|
7
|
+
private parseUrl;
|
|
7
8
|
isValidUrl(url: string): boolean;
|
|
8
|
-
private
|
|
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;
|
|
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.
|
|
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.
|
|
13
|
+
.map((url) => this.parseUrl(url))
|
|
13
14
|
.filter((url) => decodeURIComponent(url.hostname).startsWith('*'));
|
|
14
15
|
this.allowsEverything = allowList.includes('*');
|
|
15
16
|
}
|
|
16
|
-
|
|
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 : `${
|
|
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
|
-
|
|
26
|
+
const parsedUrl = this.parseUrl(url);
|
|
27
|
+
return this.allowedDomain(parsedUrl, this.URLs) || this.allowedDomain(parsedUrl, this.wildcardDomains);
|
|
26
28
|
}
|
|
27
|
-
|
|
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;
|