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.
This commit is contained in:
2 files changed
+32
-2
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user