From 005b17a15b839384540a60dccb2de49fab914a03 Mon Sep 17 00:00:00 2001 From: chrislu Date: Tue, 28 Oct 2025 13:51:56 -0700 Subject: [PATCH] ipv6 --- weed/s3api/auth_signature_v4.go | 2 +- weed/s3api/auth_signature_v4_test.go | 8 ++++++++ weed/s3api/auto_signature_v4_test.go | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/weed/s3api/auth_signature_v4.go b/weed/s3api/auth_signature_v4.go index 93bffdd34..d0297d623 100644 --- a/weed/s3api/auth_signature_v4.go +++ b/weed/s3api/auth_signature_v4.go @@ -602,7 +602,7 @@ func extractHostHeader(r *http.Request) string { } // An IPv6 address literal must be enclosed in square brackets. - if ip := net.ParseIP(forwardedHost); ip != nil && ip.To4() == nil { + if ip := net.ParseIP(forwardedHost); ip != nil && strings.Contains(forwardedHost, ":") { forwardedHost = "[" + forwardedHost + "]" } diff --git a/weed/s3api/auth_signature_v4_test.go b/weed/s3api/auth_signature_v4_test.go index 3215ba9ba..16f3840c0 100644 --- a/weed/s3api/auth_signature_v4_test.go +++ b/weed/s3api/auth_signature_v4_test.go @@ -223,6 +223,14 @@ func TestExtractHostHeader(t *testing.T) { forwardedProto: "https", expected: "[2001:db8:85a3::8a2e:370:7334]:443", }, + { + name: "IPv4-mapped IPv6 address without brackets, should add brackets with port", + hostHeader: "backend:8333", + forwardedHost: "::ffff:127.0.0.1", + forwardedPort: "8080", + forwardedProto: "http", + expected: "[::ffff:127.0.0.1]:8080", + }, } for _, tt := range tests { diff --git a/weed/s3api/auto_signature_v4_test.go b/weed/s3api/auto_signature_v4_test.go index 288ec95d7..d31294c99 100644 --- a/weed/s3api/auto_signature_v4_test.go +++ b/weed/s3api/auto_signature_v4_test.go @@ -491,6 +491,14 @@ func TestSignatureV4WithForwardedPort(t *testing.T) { forwardedProto: "http", expectedHost: "[2001:db8::1]:8080", }, + { + name: "IPv4-mapped IPv6 without port - should add port with brackets", + host: "backend:8333", + forwardedHost: "::ffff:127.0.0.1", + forwardedPort: "8080", + forwardedProto: "http", + expectedHost: "[::ffff:127.0.0.1]:8080", + }, } for _, tt := range tests {