mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
s3api: validate the SSE-C key and KMS context on CreateMultipartUpload
Initiate accepted an SSE-C key whose MD5 did not match, an incomplete SSE-C header set, and a KMS encryption context that was not base64 JSON, then created the upload. Reject them before creating the upload with the same codes PutObject returns, so the headers the response echoes are ones the parts can use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2d3905f752
commit
5a779f5440
2 files changed
+58
No files matched your search
@@ -153,3 +153,53 @@ func TestNewMultipartUploadSSEHeadersMatchUploadEntry(t *testing.T) {
|
||||
require.Equal(t, string(uploadEntry.Extended[s3_constants.SeaweedFSSSEKMSKeyID]), rr.Header().Get(s3_constants.AmzServerSideEncryptionAwsKmsKeyId))
|
||||
require.Empty(t, rr.Header().Get(s3_constants.AmzServerSideEncryptionBucketKeyEnabled))
|
||||
}
|
||||
|
||||
func TestNewMultipartUploadRejectsInvalidSSEHeaders(t *testing.T) {
|
||||
customerKey := make([]byte, 32)
|
||||
otherSum := md5.Sum([]byte("a different key"))
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
request map[string]string
|
||||
code string
|
||||
}{
|
||||
{
|
||||
name: "SSE-C key MD5 mismatch",
|
||||
request: map[string]string{
|
||||
s3_constants.AmzServerSideEncryptionCustomerAlgorithm: "AES256",
|
||||
s3_constants.AmzServerSideEncryptionCustomerKey: base64.StdEncoding.EncodeToString(customerKey),
|
||||
s3_constants.AmzServerSideEncryptionCustomerKeyMD5: base64.StdEncoding.EncodeToString(otherSum[:]),
|
||||
},
|
||||
code: "InvalidArgument",
|
||||
},
|
||||
{
|
||||
name: "SSE-C key missing",
|
||||
request: map[string]string{
|
||||
s3_constants.AmzServerSideEncryptionCustomerAlgorithm: "AES256",
|
||||
},
|
||||
code: "InvalidRequest",
|
||||
},
|
||||
{
|
||||
name: "KMS context not base64 JSON",
|
||||
request: map[string]string{
|
||||
s3_constants.AmzServerSideEncryption: "aws:kms",
|
||||
s3_constants.AmzServerSideEncryptionContext: "not-json",
|
||||
},
|
||||
code: "InvalidRequest",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
s3a, f := newMultipartInitiateSSETestServer(t, nil)
|
||||
rr := initiateMultipartWithHeaders(s3a, tc.request)
|
||||
require.Equal(t, http.StatusBadRequest, rr.Code, rr.Body.String())
|
||||
require.Contains(t, rr.Body.String(), "<Code>"+tc.code+"</Code>")
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
for path := range f.entries {
|
||||
require.False(t, strings.HasPrefix(path, "/buckets/b/"+s3_constants.MultipartUploadsFolder+"/"), path)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,14 @@ func (s3a *S3ApiServer) NewMultipartUploadHandler(w http.ResponseWriter, r *http
|
||||
s3err.WriteErrorResponse(w, r, errCode)
|
||||
return
|
||||
}
|
||||
if _, err := ParseSSECHeaders(r); err != nil {
|
||||
s3err.WriteErrorResponse(w, r, MapSSECErrorToS3Error(err))
|
||||
return
|
||||
}
|
||||
if _, err := parseEncryptionContext(r.Header.Get(s3_constants.AmzServerSideEncryptionContext)); err != nil {
|
||||
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// Check if bucket exists, and create it if it doesn't (auto-create bucket)
|
||||
if err := s3a.checkBucket(r, bucket); err == s3err.ErrNoSuchBucket {
|
||||
|
||||
Reference in new issue
Block a user