Skip to content

Commit 67f4ba1

Browse files
authored
fix: post policy request security bypass (#16849)
1 parent 440ad20 commit 67f4ba1

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

cmd/api-router.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,9 @@ func registerAPIRouter(router *mux.Router) {
434434
router.Methods(http.MethodHead).HandlerFunc(
435435
collectAPIStats("headbucket", maxClients(gz(httpTraceAll(api.HeadBucketHandler)))))
436436
// PostPolicy
437-
router.Methods(http.MethodPost).HeadersRegexp(xhttp.ContentType, "multipart/form-data*").HandlerFunc(
438-
collectAPIStats("postpolicybucket", maxClients(gz(httpTraceHdrs(api.PostPolicyBucketHandler)))))
437+
router.Methods(http.MethodPost).MatcherFunc(func(r *http.Request, _ *mux.RouteMatch) bool {
438+
return isRequestPostPolicySignatureV4(r)
439+
}).HandlerFunc(collectAPIStats("postpolicybucket", maxClients(gz(httpTraceHdrs(api.PostPolicyBucketHandler)))))
439440
// DeleteMultipleObjects
440441
router.Methods(http.MethodPost).HandlerFunc(
441442
collectAPIStats("deletemultipleobjects", maxClients(gz(httpTraceAll(api.DeleteMultipleObjectsHandler))))).Queries("delete", "")

cmd/auth-handler.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"encoding/hex"
2626
"errors"
2727
"io"
28+
"mime"
2829
"net/http"
2930
"net/url"
3031
"strconv"
@@ -74,8 +75,11 @@ func isRequestPresignedSignatureV2(r *http.Request) bool {
7475

7576
// Verify if request has AWS Post policy Signature Version '4'.
7677
func isRequestPostPolicySignatureV4(r *http.Request) bool {
77-
return strings.Contains(r.Header.Get(xhttp.ContentType), "multipart/form-data") &&
78-
r.Method == http.MethodPost
78+
mediaType, _, err := mime.ParseMediaType(r.Header.Get(xhttp.ContentType))
79+
if err != nil {
80+
return false
81+
}
82+
return mediaType == "multipart/form-data" && r.Method == http.MethodPost
7983
}
8084

8185
// Verify if the request has AWS Streaming Signature Version '4'. This is only valid for 'PUT' operation.

0 commit comments

Comments
 (0)