From a6ac25876a9ef6bd9fce74ddee30a46760fb738e Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 10 Oct 2026 22:09:05 +1100 Subject: [PATCH] fix(webui): the wildcard listen address is not loopback IsLoopback(":8484") returned true: the empty host fell through the switch as loopback, so a wildcard bind skipped the non-loopback token requirement and served every interface unauthenticated. An empty host is the wildcard, not loopback. --- internal/webui/auth.go | 5 +++-- internal/webui/auth_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 internal/webui/auth_test.go diff --git a/internal/webui/auth.go b/internal/webui/auth.go index 43006030d..c87a45023 100644 --- a/internal/webui/auth.go +++ b/internal/webui/auth.go @@ -48,8 +48,9 @@ func IsLoopback(listen string) bool { if err != nil { host = strings.TrimSpace(listen) } - switch host { - case "", "localhost": + // An empty host is the wildcard, not loopback: ":8484" binds every + // interface, so it must not pass the loopback exemption. + if host == "localhost" { return true } ip := net.ParseIP(host) diff --git a/internal/webui/auth_test.go b/internal/webui/auth_test.go new file mode 100644 index 000000000..c6145a084 --- /dev/null +++ b/internal/webui/auth_test.go @@ -0,0 +1,29 @@ +package webui + +import "testing" + +// TestIsLoopback pins the loopback exemption that lets a bind skip the +// dashboard token: the wildcard host must not qualify, or `-listen :8484` +// would serve every interface unauthenticated. +func TestIsLoopback(t *testing.T) { + tests := []struct { + listen string + want bool + }{ + {":8484", false}, + {"0.0.0.0:8484", false}, + {"[::]:8484", false}, + {"192.168.1.5:8484", false}, + {"127.0.0.1:8484", true}, + {"127.0.0.2:8484", true}, + {"[::1]:8484", true}, + {"localhost:8484", true}, + } + for _, tt := range tests { + t.Run(tt.listen, func(t *testing.T) { + if got := IsLoopback(tt.listen); got != tt.want { + t.Fatalf("IsLoopback(%q) = %v, want %v", tt.listen, got, tt.want) + } + }) + } +}