Return MethodNotAllowed error in PostPolicyBucketHandler if URL contains object name (#5142)

S3 spec requires that MethodNotAllowed error be return if object name is part
of the URL.

Fix postpolicy related unit tests to not set object name as part of target URL.

Fixes #5141
master
kannappanr 7 years ago committed by Dee Koder
parent 8d59f35523
commit b63c37b28e
  1. 9
      cmd/bucket-handlers.go
  2. 4
      cmd/post-policy_test.go

@ -24,6 +24,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"path" "path"
"path/filepath"
"reflect" "reflect"
"strings" "strings"
"sync" "sync"
@ -438,6 +439,13 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
return 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 // Require Content-Length to be set in the request
size := r.ContentLength size := r.ContentLength
if size < 0 { if size < 0 {
@ -482,7 +490,6 @@ func (api objectAPIHandlers) PostPolicyBucketHandler(w http.ResponseWriter, r *h
// Close multipart file // Close multipart file
defer fileBody.Close() defer fileBody.Close()
bucket := mux.Vars(r)["bucket"]
formValues.Set("Bucket", bucket) formValues.Set("Bucket", bucket)
if fileName != "" && strings.Contains(formValues.Get("Key"), "${filename}") { if fileName != "" && strings.Contains(formValues.Get("Key"), "${filename}") {

@ -558,7 +558,7 @@ func newPostRequestV2(endPoint, bucketName, objectName string, accessKey, secret
// Set the body equal to the created policy. // Set the body equal to the created policy.
reader := bytes.NewReader(buf.Bytes()) 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 { if err != nil {
return nil, err return nil, err
} }
@ -636,7 +636,7 @@ func newPostRequestV4Generic(endPoint, bucketName, objectName string, objData []
// Set the body equal to the created policy. // Set the body equal to the created policy.
reader := bytes.NewReader(buf.Bytes()) 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 { if err != nil {
return nil, err return nil, err
} }

Loading…
Cancel
Save