s3api: reject malformed copy-source and multipart PUT parameters

A malformed X-Amz-Copy-Source or a non-numeric partNumber fell through
to the plain PutObject route and stored the body as a regular object.
Answer them with InvalidArgument-class errors instead of writing data.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Chris LuandDevin committed 2026-10-06 09:16:29 -07:00
1 parent 564fdf26e1
commit 06fde6e2f6
2 files changed
+20

No files matched your search

@@ -328,6 +328,12 @@ func (s3a *S3ApiServer) ListObjectPartsHandler(w http.ResponseWriter, r *http.Re
// PutObjectPartHandler - Put an object part in a multipart upload.
func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Request) {
bucket, object := s3_constants.GetBucketAndObject(r)
if src := r.Header.Get("X-Amz-Copy-Source"); src != "" {
// Well-formed copy sources are claimed by the CopyObjectPart route; what
// is left here has no "bucket/key" form and is not a plain PutObjectPart.
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidArgument)
return
}
_, err := validateContentMd5(r.Header)
if err != nil {
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)
+14
View File
@@ -86,6 +86,20 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
// http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadingObjects.html
bucket, object := s3_constants.GetBucketAndObject(r)
// A copy-source header that did not satisfy the CopyObject route is
// malformed (it needs a '/' separating source bucket from key), and a
// partNumber/uploadId pair that did not satisfy the UploadPart route is
// malformed too; neither should be silently written as a plain object.
if r.Header.Get("X-Amz-Copy-Source") != "" {
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidCopySource)
return
}
if r.URL.Query().Has("partNumber") || r.URL.Query().Has("uploadId") {
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidArgument)
return
}
_, err := validateContentMd5(r.Header)
if err != nil {
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidDigest)