s3: fix signature mismatch with non-standard ports and capitalized host (#8386)
* s3: fix signature mismatch with non-standard ports and capitalized host - ensure host header extraction is case-insensitive in SignedHeaders - prioritize non-standard ports in X-Forwarded-Host over default ports in X-Forwarded-Port - add regression tests for both scenarios fixes https://github.com/seaweedfs/seaweedfs/issues/8382 * simplify
This commit is contained in:
@@ -769,7 +769,7 @@ func extractSignedHeaders(signedHeaders []string, r *http.Request) (http.Header,
|
||||
extractedSignedHeaders := make(http.Header)
|
||||
for _, header := range signedHeaders {
|
||||
// `host` is not a case-sensitive header, unlike other headers such as `x-amz-date`.
|
||||
if header == "host" {
|
||||
if strings.ToLower(header) == "host" {
|
||||
// Get host value.
|
||||
hostHeaderValue := extractHostHeader(r)
|
||||
extractedSignedHeaders[header] = []string{hostHeaderValue}
|
||||
@@ -815,12 +815,12 @@ func extractHostHeader(r *http.Request) string {
|
||||
} else {
|
||||
host = strings.TrimSpace(forwardedHost)
|
||||
}
|
||||
port = forwardedPort
|
||||
if h, p, err := net.SplitHostPort(host); err == nil {
|
||||
host = h
|
||||
if port == "" {
|
||||
port = p
|
||||
}
|
||||
port = p
|
||||
}
|
||||
if forwardedPort != "" && isDefaultPort(scheme, port) {
|
||||
port = forwardedPort
|
||||
}
|
||||
} else {
|
||||
host = r.Host
|
||||
|
||||
Reference in New Issue
Block a user