Skip to content

Commit 60f4bad

Browse files
AlexTugarevroboquat
authored andcommitted
Test if auth host is reachable
1 parent ef13986 commit 60f4bad

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

components/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"google-protobuf": "^3.18.0-rc.2",
6262
"heapdump": "^0.3.15",
6363
"inversify": "^5.0.1",
64+
"is-reachable": "^5.2.1",
6465
"js-yaml": "^3.10.0",
6566
"json-stream": "^1.0.0",
6667
"lodash.debounce": "^4.0.8",

components/server/src/auth/auth-provider-service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { oauthUrls as gitlabUrls } from "../gitlab/gitlab-urls";
1515
import { oauthUrls as bbsUrls } from "../bitbucket-server/bitbucket-server-urls";
1616
import { oauthUrls as bbUrls } from "../bitbucket/bitbucket-urls";
1717
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
18+
import isReachable = require("is-reachable");
1819

1920
@injectable()
2021
export class AuthProviderService {
@@ -172,7 +173,12 @@ export class AuthProviderService {
172173
}
173174

174175
protected callbackUrl = (host: string) => {
175-
const pathname = `/auth/${host}/callback`;
176+
const safeHost = host.replace(":", "_");
177+
const pathname = `/auth/${safeHost}/callback`;
176178
return this.config.hostUrl.with({ pathname }).toString();
177179
};
180+
181+
async isHostReachable(host: string) {
182+
return await isReachable(host, { timeout: 2000 });
183+
}
178184
}

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,14 +2873,6 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
28732873
throw error;
28742874
}
28752875

2876-
// from https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address/106223#106223
2877-
// adapted to allow for hostnames
2878-
// from [foo.bar] pumped up to [foo.(foo.)bar]
2879-
// and also for a trailing path segments
2880-
// for example [foo.bar/gitlab]
2881-
protected validHostNameRegexp =
2882-
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])(\/([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9]))?$/;
2883-
28842876
async updateOwnAuthProvider(
28852877
ctx: TraceContext,
28862878
{ entry }: GitpodServer.UpdateOwnAuthProviderParams,
@@ -2905,9 +2897,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
29052897

29062898
const host = safeProvider.host && safeProvider.host.toLowerCase();
29072899

2908-
if (!this.validHostNameRegexp.exec(host)) {
2909-
log.debug(`Invalid auth provider host.`, { entry, safeProvider });
2910-
throw new Error("Invalid host name.");
2900+
if (!(await this.authProviderService.isHostReachable(host))) {
2901+
log.debug(`Host could not be reached.`, { entry, safeProvider });
2902+
throw new Error("Host could not be reached.");
29112903
}
29122904

29132905
const hostContext = this.hostContextProvider.get(host);

yarn.lock

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10086,11 +10086,30 @@ is-plain-object@^5.0.0:
1008610086
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344"
1008710087
integrity sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==
1008810088

10089+
is-port-reachable@^3.0.0:
10090+
version "3.1.0"
10091+
resolved "https://registry.yarnpkg.com/is-port-reachable/-/is-port-reachable-3.1.0.tgz#f6668d3bca9c36b07f737c48a8f875ab0653cd2b"
10092+
integrity sha512-vjc0SSRNZ32s9SbZBzGaiP6YVB+xglLShhgZD/FHMZUXBvQWaV9CtzgeVhjccFJrI6RAMV+LX7NYxueW/A8W5A==
10093+
1008910094
is-potential-custom-element-name@^1.0.1:
1009010095
version "1.0.1"
1009110096
resolved "https://registry.yarnpkg.com/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz#171ed6f19e3ac554394edf78caa05784a45bebb5"
1009210097
integrity sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==
1009310098

10099+
is-reachable@^5.2.1:
10100+
version "5.2.1"
10101+
resolved "https://registry.yarnpkg.com/is-reachable/-/is-reachable-5.2.1.tgz#4bba5ba32f60723404d5f95b7ecd895644c776f3"
10102+
integrity sha512-ViPrrlmt9FTTclYbz6mL/PFyF1TXSpJ9y/zw9QMVJxbhU/7DFkvk/5cTv7S0sXtqbJj32zZ+jKpNAjrYTUZBPQ==
10103+
dependencies:
10104+
arrify "^2.0.1"
10105+
got "^11.7.0"
10106+
is-port-reachable "^3.0.0"
10107+
p-any "^3.0.0"
10108+
p-timeout "^3.2.0"
10109+
prepend-http "^3.0.1"
10110+
router-ips "^1.0.0"
10111+
url-parse "^1.5.10"
10112+
1009410113
is-regex@^1.0.3, is-regex@^1.0.4, is-regex@^1.1.1, is-regex@^1.1.4:
1009510114
version "1.1.4"
1009610115
resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.1.4.tgz#eef5663cd59fa4c0ae339505323df6854bb15958"
@@ -12686,6 +12705,14 @@ ospath@^1.2.2:
1268612705
resolved "https://registry.yarnpkg.com/ospath/-/ospath-1.2.2.tgz#1276639774a3f8ef2572f7fe4280e0ea4550c07b"
1268712706
integrity sha1-EnZjl3Sj+O8lcvf+QoDg6kVQwHs=
1268812707

12708+
p-any@^3.0.0:
12709+
version "3.0.0"
12710+
resolved "https://registry.yarnpkg.com/p-any/-/p-any-3.0.0.tgz#79847aeed70b5d3a10ea625296c0c3d2e90a87b9"
12711+
integrity sha512-5rqbqfsRWNb0sukt0awwgJMlaep+8jV45S15SKKB34z4UuzjcofIfnriCBhWjZP2jbVtjt9yRl7buB6RlKsu9w==
12712+
dependencies:
12713+
p-cancelable "^2.0.0"
12714+
p-some "^5.0.0"
12715+
1268912716
p-cancelable@^1.0.0:
1269012717
version "1.1.0"
1269112718
resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-1.1.0.tgz#d078d15a3af409220c886f1d9a0ca2e441ab26cc"
@@ -12777,11 +12804,26 @@ p-retry@^3.0.1:
1277712804
dependencies:
1277812805
retry "^0.12.0"
1277912806

12807+
p-some@^5.0.0:
12808+
version "5.0.0"
12809+
resolved "https://registry.yarnpkg.com/p-some/-/p-some-5.0.0.tgz#8b730c74b4fe5169d7264a240ad010b6ebc686a4"
12810+
integrity sha512-Js5XZxo6vHjB9NOYAzWDYAIyyiPvva0DWESAIWIK7uhSpGsyg5FwUPxipU/SOQx5x9EqhOh545d1jo6cVkitig==
12811+
dependencies:
12812+
aggregate-error "^3.0.0"
12813+
p-cancelable "^2.0.0"
12814+
1278012815
p-throttle@^4.1.1:
1278112816
version "4.1.1"
1278212817
resolved "https://registry.yarnpkg.com/p-throttle/-/p-throttle-4.1.1.tgz#80b1fbd358af40a8bfa1667f9dc8b72b714ad692"
1278312818
integrity sha512-TuU8Ato+pRTPJoDzYD4s7ocJYcNSEZRvlxoq3hcPI2kZDZ49IQ1Wkj7/gDJc3X7XiEAAvRGtDzdXJI0tC3IL1g==
1278412819

12820+
p-timeout@^3.2.0:
12821+
version "3.2.0"
12822+
resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-3.2.0.tgz#c7e17abc971d2a7962ef83626b35d635acf23dfe"
12823+
integrity sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==
12824+
dependencies:
12825+
p-finally "^1.0.0"
12826+
1278512827
p-try@^1.0.0:
1278612828
version "1.0.0"
1278712829
resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3"
@@ -14216,6 +14258,11 @@ prepend-http@^2.0.0:
1421614258
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
1421714259
integrity sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=
1421814260

14261+
prepend-http@^3.0.1:
14262+
version "3.0.1"
14263+
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-3.0.1.tgz#3e724d58fd5867465b300bb9615009fa2f8ee3b6"
14264+
integrity sha512-BLxfZh+m6UiAiCPZFJ4+vYoL7NrRs5XgCTRrjseATAggXhdZKKxn+JUNmuVYWY23bDHgaEHodxw8mnmtVEDtHw==
14265+
1421914266
pretty-bytes@^5.3.0, pretty-bytes@^5.6.0:
1422014267
version "5.6.0"
1422114268
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb"
@@ -15422,6 +15469,11 @@ rollup@^1.31.1:
1542215469
"@types/node" "*"
1542315470
acorn "^7.1.0"
1542415471

15472+
router-ips@^1.0.0:
15473+
version "1.0.0"
15474+
resolved "https://registry.yarnpkg.com/router-ips/-/router-ips-1.0.0.tgz#44e00858ebebc0133d58e40b2cd8a1fbb04203f5"
15475+
integrity sha512-yBo6F52Un/WYioXbedBGvrKIiofbwt+4cUhdqDb9fNMJBI4D4jOy7jlxxaRVEvICPKU7xMmJDtDFR6YswX/sFQ==
15476+
1542515477
rsvp@^4.8.4:
1542615478
version "4.8.5"
1542715479
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"
@@ -17517,6 +17569,14 @@ url-parse@^1.4.3, url-parse@^1.5.3, url-parse@~1.5.1:
1751717569
querystringify "^2.1.1"
1751817570
requires-port "^1.0.0"
1751917571

17572+
url-parse@^1.5.10:
17573+
version "1.5.10"
17574+
resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
17575+
integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==
17576+
dependencies:
17577+
querystringify "^2.1.1"
17578+
requires-port "^1.0.0"
17579+
1752017580
url-template@^2.0.8:
1752117581
version "2.0.8"
1752217582
resolved "https://registry.yarnpkg.com/url-template/-/url-template-2.0.8.tgz#fc565a3cccbff7730c775f5641f9555791439f21"

0 commit comments

Comments
 (0)