diff --git a/lib/api/api.go b/lib/api/api.go index f22b28bfb..b3ca1c590 100644 --- a/lib/api/api.go +++ b/lib/api/api.go @@ -1772,8 +1772,13 @@ func addressIsLocalhost(addr string) bool { // There was no port, so we assume the address was just a hostname host = addr } - switch strings.ToLower(host) { - case "localhost", "localhost.": + host = strings.ToLower(host) + switch { + case host == "localhost": + return true + case host == "localhost.": + return true + case strings.HasSuffix(host, ".localhost"): return true default: ip := net.ParseIP(host) diff --git a/lib/api/api_test.go b/lib/api/api_test.go index 7bd18db54..0b60e4902 100644 --- a/lib/api/api_test.go +++ b/lib/api/api_test.go @@ -995,14 +995,14 @@ func TestAddressIsLocalhost(t *testing.T) { {"[::1]:8080", true}, {"127.0.0.1:8080", true}, {"127.23.45.56:8080", true}, + {"www.localhost", true}, + {"www.localhost:8080", true}, // These are all non-localhost addresses {"example.com", false}, {"example.com:8080", false}, {"localhost.com", false}, {"localhost.com:8080", false}, - {"www.localhost", false}, - {"www.localhost:8080", false}, {"192.0.2.10", false}, {"192.0.2.10:8080", false}, {"0.0.0.0", false},