From 24b03d4caf2998b424038435bf6d0d4e241469b5 Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 6 Oct 2026 16:12:32 +0200 Subject: [PATCH] fix: reject invalid authentication origin authorities --- tools/tht/internal/authconfig/commands.go | 2 +- tools/tht/internal/authconfig/loopback_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/tht/internal/authconfig/commands.go b/tools/tht/internal/authconfig/commands.go index f3b3cc12..0fdb5a04 100644 --- a/tools/tht/internal/authconfig/commands.go +++ b/tools/tht/internal/authconfig/commands.go @@ -1177,7 +1177,7 @@ func rolesToStrings(roles []Role) []string { // ValidPublicURL follows the backend policy: HTTP requires canonical literal loopback. func ValidPublicURL(value string) bool { parsed, err := url.Parse(value) - if err != nil || parsed.Host == "" || parsed.User != nil || (parsed.Path != "" && parsed.Path != "/") || parsed.RawQuery != "" || parsed.Fragment != "" { + if err != nil || parsed.Hostname() == "" || strings.Contains(parsed.Hostname(), "%") || parsed.User != nil || (parsed.Path != "" && parsed.Path != "/") || parsed.RawQuery != "" || parsed.Fragment != "" { return false } if port := parsed.Port(); port != "" { diff --git a/tools/tht/internal/authconfig/loopback_test.go b/tools/tht/internal/authconfig/loopback_test.go index 78431f09..fc55d343 100644 --- a/tools/tht/internal/authconfig/loopback_test.go +++ b/tools/tht/internal/authconfig/loopback_test.go @@ -21,7 +21,7 @@ func TestPublicOriginMatchesBackendURLContract(t *testing.T) { t.Errorf("runtime-valid origin refused: %s", origin) } } - for _, origin := range []string{"https://example.com:99999", "http://localhost:8080", "HTTP://127.0.0.1:8080", "https://example.com/path", "http://example.com", "https://user:password@example.com"} { + for _, origin := range []string{"https://:443", "https://[fe80::1%25eth0]", "https://example.com:99999", "http://localhost:8080", "HTTP://127.0.0.1:8080", "https://example.com/path", "http://example.com", "https://user:password@example.com"} { if ValidPublicURL(origin) { t.Errorf("runtime-invalid origin accepted: %s", origin) }