@forge/egress 1.0.1-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 +6 -0
- package/out/egress/egress-filtering-service.d.ts +11 -0
- package/out/egress/egress-filtering-service.d.ts.map +1 -0
- package/out/egress/egress-filtering-service.js +46 -0
- package/out/egress/index.d.ts +3 -0
- package/out/egress/index.d.ts.map +1 -0
- package/out/egress/index.js +5 -0
- package/out/egress/utils.d.ts +3 -0
- package/out/egress/utils.d.ts.map +1 -0
- package/out/egress/utils.js +31 -0
- package/out/index.d.ts +2 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +4 -0
- package/package.json +19 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class EgressFilteringService {
|
|
2
|
+
private readonly URLs;
|
|
3
|
+
private readonly wildcardDomains;
|
|
4
|
+
private readonly allowsEverything;
|
|
5
|
+
constructor(allowList: string[]);
|
|
6
|
+
private safeURL;
|
|
7
|
+
isValidUrl(url: string): boolean;
|
|
8
|
+
private domainCheck;
|
|
9
|
+
private domainIsAllowed;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=egress-filtering-service.d.ts.map
|
|
@@ -0,0 +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;IAY/B,OAAO,CAAC,OAAO;IAOR,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAQvC,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,eAAe;CAWxB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EgressFilteringService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
class EgressFilteringService {
|
|
8
|
+
constructor(allowList) {
|
|
9
|
+
this.URLs = allowList
|
|
10
|
+
.filter((domainOrURL) => !domainOrURL.startsWith('*'))
|
|
11
|
+
.map((url) => this.safeURL(url));
|
|
12
|
+
this.wildcardDomains = allowList
|
|
13
|
+
.filter((domainOrURL) => domainOrURL !== '*')
|
|
14
|
+
.map((url) => this.safeURL(url))
|
|
15
|
+
.filter((url) => url.hostname.startsWith('*'));
|
|
16
|
+
this.allowsEverything = allowList.includes('*');
|
|
17
|
+
}
|
|
18
|
+
safeURL(url, defaultProtocol = 'https://') {
|
|
19
|
+
const protocolRegex = /^(.*:\/\/)/;
|
|
20
|
+
return new url_1.URL(protocolRegex.test(url) ? url : `${defaultProtocol}${url}`);
|
|
21
|
+
}
|
|
22
|
+
isValidUrl(url) {
|
|
23
|
+
if (this.allowsEverything) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
return this.domainIsAllowed(this.safeURL(url));
|
|
27
|
+
}
|
|
28
|
+
domainCheck(domain, allowList) {
|
|
29
|
+
const hostnameMatchedProtocol = allowList
|
|
30
|
+
.filter((allowed) => allowed.protocol === domain.protocol)
|
|
31
|
+
.map((url) => url.hostname);
|
|
32
|
+
return (micromatch_1.default([domain.hostname], hostnameMatchedProtocol, {
|
|
33
|
+
dot: true
|
|
34
|
+
}).length > 0);
|
|
35
|
+
}
|
|
36
|
+
domainIsAllowed(domain) {
|
|
37
|
+
if (this.domainCheck(domain, this.URLs)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (this.domainCheck(domain, this.wildcardDomains)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.EgressFilteringService = EgressFilteringService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/egress/index.ts"],"names":[],"mappings":"AAEA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/egress/utils.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,qCAAqC,oBAAqB,MAAM,EAAE,KAAG,KAAK,CAAC,MAAM,CA2BtF,CAAC;AAEF,OAAO,EAAE,qCAAqC,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortAndGroupEgressPermissionsByDomain = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
6
|
+
const url_1 = require("url");
|
|
7
|
+
const sortAndGroupEgressPermissionsByDomain = (egressAddresses) => {
|
|
8
|
+
const protocolRegex = /^(.*?:\/\/)/;
|
|
9
|
+
const domainSet = new Set();
|
|
10
|
+
const groupSet = new Set();
|
|
11
|
+
const removeSet = new Set();
|
|
12
|
+
if ((egressAddresses === null || egressAddresses === void 0 ? void 0 : egressAddresses.length) === 0) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
egressAddresses.forEach((item) => {
|
|
16
|
+
const itemWithProtocol = protocolRegex.test(item) ? item : `https://${item}`;
|
|
17
|
+
const url = new url_1.URL(itemWithProtocol);
|
|
18
|
+
if (url.hostname.startsWith('*')) {
|
|
19
|
+
groupSet.add(url.hostname.substring(2));
|
|
20
|
+
removeSet.add('!' + url.hostname);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
domainSet.add(url.hostname);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
if (removeSet.size === 0) {
|
|
27
|
+
return [...domainSet];
|
|
28
|
+
}
|
|
29
|
+
return [...new Set(micromatch_1.default([...domainSet], [...removeSet]).concat([...groupSet]))].sort();
|
|
30
|
+
};
|
|
31
|
+
exports.sortAndGroupEgressPermissionsByDomain = sortAndGroupEgressPermissionsByDomain;
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
package/out/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@forge/egress",
|
|
3
|
+
"version": "1.0.1-next.0",
|
|
4
|
+
"description": "Helpers and utils for egress implementation in Forge apps",
|
|
5
|
+
"main": "out/index.js",
|
|
6
|
+
"author": "Atlassian",
|
|
7
|
+
"license": "UNLICENSED",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "yarn run clean && yarn run compile",
|
|
10
|
+
"compile": "tsc -b -v",
|
|
11
|
+
"clean": "rm -rf ./out && rm -f tsconfig.tsbuildinfo"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/jest": "^26.0.0"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"micromatch": "^4.0.2"
|
|
18
|
+
}
|
|
19
|
+
}
|