From 1d6ab9f9dbba01988ef8798f76a21d3c88e5a0f9 Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Mon, 20 May 2024 17:38:08 -0700 Subject: [PATCH] cmd/serve: don't convert localhost to 127.0.0.1 This is not valid in many situations, specifically when running a local astro site that listens on localhost, but ignores 127.0.0.1 Fixes: https://github.com/tailscale/tailscale/issues/12201 Signed-off-by: Josh McKinney --- ipn/serve.go | 2 +- ipn/serve_test.go | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/ipn/serve.go b/ipn/serve.go index 3a5abf0e5..5c0a97ed3 100644 --- a/ipn/serve.go +++ b/ipn/serve.go @@ -538,7 +538,7 @@ func ExpandProxyTargetValue(target string, supportedSchemes []string, defaultSch return "", fmt.Errorf("invalid port %q", u.Port()) } - u.Host = fmt.Sprintf("%s:%d", host, port) + u.Host = fmt.Sprintf("%s:%d", u.Hostname(), port) return u.String(), nil } diff --git a/ipn/serve_test.go b/ipn/serve_test.go index a9fe4a462..e9d8e8f32 100644 --- a/ipn/serve_test.go +++ b/ipn/serve_test.go @@ -137,14 +137,13 @@ func TestExpandProxyTargetDev(t *testing.T) { wantErr bool }{ {name: "port-only", input: "8080", expected: "http://127.0.0.1:8080"}, - {name: "hostname+port", input: "localhost:8080", expected: "http://127.0.0.1:8080"}, - {name: "convert-localhost", input: "http://localhost:8080", expected: "http://127.0.0.1:8080"}, + {name: "hostname+port", input: "localhost:8080", expected: "http://localhost:8080"}, {name: "no-change", input: "http://127.0.0.1:8080", expected: "http://127.0.0.1:8080"}, {name: "include-path", input: "http://127.0.0.1:8080/foo", expected: "http://127.0.0.1:8080/foo"}, - {name: "https-scheme", input: "https://localhost:8080", expected: "https://127.0.0.1:8080"}, - {name: "https+insecure-scheme", input: "https+insecure://localhost:8080", expected: "https+insecure://127.0.0.1:8080"}, - {name: "change-default-scheme", input: "localhost:8080", defaultScheme: "https", expected: "https://127.0.0.1:8080"}, - {name: "change-supported-schemes", input: "localhost:8080", defaultScheme: "tcp", supportedSchemes: []string{"tcp"}, expected: "tcp://127.0.0.1:8080"}, + {name: "https-scheme", input: "https://localhost:8080", expected: "https://localhost:8080"}, + {name: "https+insecure-scheme", input: "https+insecure://localhost:8080", expected: "https+insecure://localhost:8080"}, + {name: "change-default-scheme", input: "localhost:8080", defaultScheme: "https", expected: "https://localhost:8080"}, + {name: "change-supported-schemes", input: "localhost:8080", defaultScheme: "tcp", supportedSchemes: []string{"tcp"}, expected: "tcp://localhost:8080"}, // errors {name: "invalid-port", input: "localhost:9999999", wantErr: true},