diff --git a/cmd/bucket-handlers.go b/cmd/bucket-handlers.go index de596a112..b150f32bf 100644 --- a/cmd/bucket-handlers.go +++ b/cmd/bucket-handlers.go @@ -24,6 +24,7 @@ import ( "net/http" "net/url" "path" + "path/filepath" "reflect" "strings" "sync" @@ -438,6 +439,13 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h return } + // Make sure that the URL does not contain object name. + bucket := mux.Vars(r)["bucket"] + if bucket != filepath.Clean(r.URL.Path[1:]) { + writeErrorResponse(w, ErrMethodNotAllowed, r.URL) + return + } + // Require Content-Length to be set in the request size := r.ContentLength if size < 0 { @@ -482,7 +490,6 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h // Close multipart file defer fileBody.Close() - bucket := mux.Vars(r)["bucket"] formValues.Set("Bucket", bucket) if fileName != "" && strings.Contains(formValues.Get("Key"), "${filename}") { diff --git a/cmd/post-policy_test.go b/cmd/post-policy_test.go index 9b2509b4a..11e908b62 100644 --- a/cmd/post-policy_test.go +++ b/cmd/post-policy_test.go @@ -558,7 +558,7 @@ func newPostRequestV2(endPoint, bucketName, objectName string, accessKey, secret // Set the body equal to the created policy. reader := bytes.NewReader(buf.Bytes()) - req, err := http.NewRequest("POST", makeTestTargetURL(endPoint, bucketName, objectName, nil), reader) + req, err := http.NewRequest("POST", makeTestTargetURL(endPoint, bucketName, "", nil), reader) if err != nil { return nil, err } @@ -636,7 +636,7 @@ func newPostRequestV4Generic(endPoint, bucketName, objectName string, objData [] // Set the body equal to the created policy. reader := bytes.NewReader(buf.Bytes()) - req, err := http.NewRequest("POST", makeTestTargetURL(endPoint, bucketName, objectName, nil), reader) + req, err := http.NewRequest("POST", makeTestTargetURL(endPoint, bucketName, "", nil), reader) if err != nil { return nil, err }