mirror of
https://github.com/versity/versitygw.git
synced 2026-08-21 14:46:19 +00:00
fix: reject invalid PostObject keys
Validate multipart PostObject key fields with the existing object name rules so path traversal and degenerate names return BadRequest. This prevents crafted object keys from escaping the gateway root.
This commit is contained in:
@@ -112,15 +112,7 @@ func (c S3ApiController) POSTObject(ctx *fiber.Ctx) (*Response, error) {
|
||||
cacheControl := parsed.Fields["cache-control"]
|
||||
expires := parsed.Fields["expires"]
|
||||
|
||||
key, ok := parsed.Fields["key"]
|
||||
if !ok || key == "" {
|
||||
debuglogger.Logf("missing object key")
|
||||
return &Response{
|
||||
MetaOpts: &MetaOptions{
|
||||
BucketOwner: parsedAcl.Owner,
|
||||
},
|
||||
}, s3err.PostAuth.MissingField("key")
|
||||
}
|
||||
key := parsed.Fields["key"]
|
||||
|
||||
err := auth.VerifyAccess(ctx.Context(), c.be,
|
||||
auth.AccessOptions{
|
||||
|
||||
@@ -254,28 +254,6 @@ func TestS3ApiController_POSTObject(t *testing.T) {
|
||||
input testInput
|
||||
output testOutput
|
||||
}{
|
||||
{
|
||||
name: "missing key",
|
||||
input: testInput{
|
||||
locals: postObjectLocalsForTest(middlewares.PostObjectResult{
|
||||
Fields: map[string]string{
|
||||
"policy": basePolicy,
|
||||
"file": "ignored",
|
||||
"x-amz-signature": "ignored",
|
||||
},
|
||||
FileRdr: newMockFileReader("payload"),
|
||||
ContentLength: int64(len("payload")),
|
||||
}),
|
||||
},
|
||||
output: testOutput{
|
||||
response: &Response{
|
||||
MetaOpts: &MetaOptions{
|
||||
BucketOwner: "root",
|
||||
},
|
||||
},
|
||||
err: s3err.PostAuth.MissingField("key"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "verify access fails",
|
||||
input: testInput{
|
||||
|
||||
@@ -86,6 +86,16 @@ func AuthorizePostObject(root RootUserConfig, iam auth.IAMService, region string
|
||||
|
||||
fields := result.Fields
|
||||
|
||||
if fields["key"] == "" {
|
||||
debuglogger.Logf("missing object key")
|
||||
return s3err.PostAuth.MissingField("key")
|
||||
}
|
||||
|
||||
if !utils.IsObjectNameValid(fields["key"]) {
|
||||
debuglogger.Logf("invalid POST object key: %q", fields["key"])
|
||||
return s3err.GetAPIError(s3err.ErrBadRequest)
|
||||
}
|
||||
|
||||
policyB64 := fields[formFieldPolicy]
|
||||
algorithm := fields[formFieldAlgorithm]
|
||||
credentialStr := fields[formFieldCredential]
|
||||
|
||||
Reference in New Issue
Block a user