mirror of
https://github.com/versity/versitygw.git
synced 2026-01-07 12:15:18 +00:00
fix: prevent directory type object uploads containing data
Since objects with trailing "/" are mapped to directories in the posix filesystem, they must not contain data since there is no place to store that data. This checks both PutObject and CreateMultipartUpload for invalid directory object types containing data.
This commit is contained in:
@@ -223,6 +223,12 @@ func (p *Posix) CreateMultipartUpload(_ context.Context, mpu *s3.CreateMultipart
|
|||||||
return nil, fmt.Errorf("stat bucket: %w", err)
|
return nil, fmt.Errorf("stat bucket: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(*mpu.Key, "/") {
|
||||||
|
// directory objects can't be uploaded with mutlipart uploads
|
||||||
|
// because posix directories can't contain data
|
||||||
|
return nil, s3err.GetAPIError(s3err.ErrDirectoryObjectContainsData)
|
||||||
|
}
|
||||||
|
|
||||||
// generate random uuid for upload id
|
// generate random uuid for upload id
|
||||||
uploadID := uuid.New().String()
|
uploadID := uuid.New().String()
|
||||||
// hash object name for multipart container
|
// hash object name for multipart container
|
||||||
@@ -960,6 +966,13 @@ func (p *Posix) PutObject(ctx context.Context, po *s3.PutObjectInput) (string, e
|
|||||||
|
|
||||||
if strings.HasSuffix(*po.Key, "/") {
|
if strings.HasSuffix(*po.Key, "/") {
|
||||||
// object is directory
|
// object is directory
|
||||||
|
if po.ContentLength != 0 {
|
||||||
|
// posix directories can't contain data, send error
|
||||||
|
// if reuests has a data payload associated with a
|
||||||
|
// directory object
|
||||||
|
return "", s3err.GetAPIError(s3err.ErrDirectoryObjectContainsData)
|
||||||
|
}
|
||||||
|
|
||||||
err = mkdirAll(name, os.FileMode(0755), *po.Bucket, *po.Key)
|
err = mkdirAll(name, os.FileMode(0755), *po.Bucket, *po.Key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ const (
|
|||||||
// Non-AWS errors
|
// Non-AWS errors
|
||||||
ErrExistingObjectIsDirectory
|
ErrExistingObjectIsDirectory
|
||||||
ErrObjectParentIsFile
|
ErrObjectParentIsFile
|
||||||
|
ErrDirectoryObjectContainsData
|
||||||
)
|
)
|
||||||
|
|
||||||
var errorCodeResponse = map[ErrorCode]APIError{
|
var errorCodeResponse = map[ErrorCode]APIError{
|
||||||
@@ -408,6 +409,11 @@ var errorCodeResponse = map[ErrorCode]APIError{
|
|||||||
Description: "Object parent already exists as a file.",
|
Description: "Object parent already exists as a file.",
|
||||||
HTTPStatusCode: http.StatusConflict,
|
HTTPStatusCode: http.StatusConflict,
|
||||||
},
|
},
|
||||||
|
ErrDirectoryObjectContainsData: {
|
||||||
|
Code: "DirectoryObjectContainsData",
|
||||||
|
Description: "Directory object contains data payload.",
|
||||||
|
HTTPStatusCode: http.StatusBadRequest,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAPIError provides API Error for input API error code.
|
// GetAPIError provides API Error for input API error code.
|
||||||
|
|||||||
Reference in New Issue
Block a user