From f8b0caa8c2ab761b8467a42c86744a2ef1b7d255 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 17 Jul 2023 16:50:58 -0700 Subject: [PATCH] serve: fix hostname for custom http ports When using a custom http port like 8080, this was resulting in a constructed hostname of `host.tailnet.ts.net:8080.tailnet.ts.net` when looking up the serve handler. Instead, strip off the port before adding the MagicDNS suffix. Also use the actual hostname in `serve status` rather than the literal string "host". Fixes #8635 Signed-off-by: Will Norris --- cmd/tailscale/cli/serve.go | 2 +- ipn/ipnlocal/serve.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/tailscale/cli/serve.go b/cmd/tailscale/cli/serve.go index 572e2148b..3ad0bb432 100644 --- a/cmd/tailscale/cli/serve.go +++ b/cmd/tailscale/cli/serve.go @@ -699,7 +699,7 @@ func (e *serveEnv) printWebStatusTree(sc *ipn.ServeConfig, hp ipn.HostPort) erro portPart = "" } if scheme == "http" { - hostname, _, _ := strings.Cut("host", ".") + hostname, _, _ := strings.Cut(host, ".") printf("%s://%s%s (%s)\n", scheme, hostname, portPart, fStatus) } printf("%s://%s%s (%s)\n", scheme, host, portPart, fStatus) diff --git a/ipn/ipnlocal/serve.go b/ipn/ipnlocal/serve.go index a6a7d1421..aa2c1a605 100644 --- a/ipn/ipnlocal/serve.go +++ b/ipn/ipnlocal/serve.go @@ -415,6 +415,9 @@ func (b *LocalBackend) getServeHandler(r *http.Request) (_ ipn.HTTPHandlerView, hostname := r.Host if r.TLS == nil { tcd := "." + b.Status().CurrentTailnet.MagicDNSSuffix + if host, _, err := net.SplitHostPort(hostname); err == nil { + hostname = host + } if !strings.HasSuffix(hostname, tcd) { hostname += tcd }