From a63b5eb5528e5c7e53cff9d60d5816a68429fb8c Mon Sep 17 00:00:00 2001 From: chrislu Date: Wed, 29 Oct 2025 17:23:18 -0700 Subject: [PATCH] trim for ipv6 --- weed/s3api/auth_signature_v4.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/weed/s3api/auth_signature_v4.go b/weed/s3api/auth_signature_v4.go index cde42ebef..a196f7cda 100644 --- a/weed/s3api/auth_signature_v4.go +++ b/weed/s3api/auth_signature_v4.go @@ -637,10 +637,10 @@ func extractHostHeader(r *http.Request) string { // If we have a non-default port, join it with the host. // net.JoinHostPort will handle bracketing for IPv6. if port != "" && !isDefaultPort(scheme, port) { - // Before joining, strip brackets from host if they exist, as JoinHostPort adds them. - if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") { - host = host[1 : len(host)-1] - } + // Strip existing brackets before calling JoinHostPort, which automatically adds + // brackets for IPv6 addresses. This prevents double-bracketing like [[::1]]:8080. + // Using Trim handles both well-formed and malformed bracketed hosts. + host = strings.Trim(host, "[]") return net.JoinHostPort(host, port) }