From 1cd6713e2488620222a347aa90870a0711b4b8d9 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Fri, 15 Jul 2022 15:04:48 -0700 Subject: [PATCH] copy query values before update to preserve the expected keys (#15310) in success_action_redirect we were missing required query params as per S3 spec - updated tests. --- cmd/bucket-handlers.go | 8 +++++--- cmd/post-policy_test.go | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index bc8e6fcba..9dac30d37 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -1117,9 +1117,11 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h }) if redirectURL != nil { // success_action_redirect is valid and set. - redirectURL.Query().Add("bucket", objInfo.Bucket) - redirectURL.Query().Add("key", objInfo.Name) - redirectURL.Query().Add("etag", "\""+objInfo.ETag+"\"") + v := redirectURL.Query() + v.Add("bucket", objInfo.Bucket) + v.Add("key", objInfo.Name) + v.Add("etag", "\""+objInfo.ETag+"\"") + redirectURL.RawQuery = v.Encode() writeRedirectSeeOther(w, redirectURL.String()) return } diff --git a/cmd/post-policy_test.go b/cmd/post-policy_test.go index 4e9e250fa..979db968a 100644 --- a/cmd/post-policy_test.go +++ b/cmd/post-policy_test.go @@ -499,9 +499,11 @@ func testPostPolicyBucketHandlerRedirect(obj ObjectLayer, instanceType string, t t.Error("Unexpected error: ", err) } - redirectURL.Query().Add("bucket", info.Bucket) - redirectURL.Query().Add("key", info.Name) - redirectURL.Query().Add("etag", "\""+info.ETag+"\"") + v := redirectURL.Query() + v.Add("bucket", info.Bucket) + v.Add("key", info.Name) + v.Add("etag", "\""+info.ETag+"\"") + redirectURL.RawQuery = v.Encode() expectedLocation := redirectURL.String() // Check the new location url