fix: validate s3 ownership controls rule (#9684)

This commit is contained in:
7y-9
2026-05-28 05:41:10 +08:00
committed by GitHub
parent 69c84801e4
commit bbbc3925ec
2 changed files with 33 additions and 1 deletions

View File

@@ -1059,7 +1059,7 @@ func (s3a *S3ApiServer) PutBucketOwnershipControls(w http.ResponseWriter, r *htt
return
}
if len(v.Rules) != 1 {
if len(v.Rules) != 1 || v.Rules[0] == nil || v.Rules[0].ObjectOwnership == nil {
s3err.WriteErrorResponse(w, r, s3err.ErrInvalidRequest)
return
}

View File

@@ -9,9 +9,11 @@ import (
"testing"
"time"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/gorilla/mux"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/s3api/policy_engine"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
)
func newMiscTestServer(t *testing.T, bucket string) *S3ApiServer {
@@ -102,6 +104,36 @@ func TestPutBucketRequestPaymentRequesterRejected(t *testing.T) {
}
}
func TestPutBucketOwnershipControlsRejectsRuleWithoutObjectOwnership(t *testing.T) {
ownerID := AccountAdmin.Id
s3a := &S3ApiServer{
bucketRegistry: &BucketRegistry{
metadataCache: map[string]*BucketMetaData{
"b": {
Name: "b",
Owner: &s3.Owner{
ID: &ownerID,
},
},
},
notFound: map[string]struct{}{},
},
}
body := `<OwnershipControls><Rule></Rule></OwnershipControls>`
req := newBucketRequest(http.MethodPut, "b", "ownershipControls=", body)
req.Header.Set(s3_constants.AmzAccountId, AccountAdmin.Id)
rec := httptest.NewRecorder()
s3a.PutBucketOwnershipControls(rec, req)
if rec.Code != http.StatusBadRequest {
t.Fatalf("status = %d, want %d, body=%s", rec.Code, http.StatusBadRequest, rec.Body.String())
}
if !strings.Contains(rec.Body.String(), "InvalidRequest") {
t.Fatalf("body missing InvalidRequest: %s", rec.Body.String())
}
}
func TestGetBucketAccelerateConfiguration(t *testing.T) {
s3a := newMiscTestServer(t, "b")
req := newBucketRequest(http.MethodGet, "b", "accelerate=", "")