Skip to content

[Bug] S3 requests for unimplemented operations run as plain PUT/DELETE and overwrite or delete objects #156

Closed

Description

@saworbit

Summary

The object route ignores the query string and S3's operation headers. As a result, PutObjectTagging and PutObjectAcl replace the object's bytes with the request's XML body, and DeleteObjectTagging deletes the object. CopyObject answers 200 but writes an empty object. Standard clients make these calls routinely. aws s3 mv is CopyObject followed by DeleteObject, so a move leaves an empty destination and deletes the source.

Classification

  • Type: Bug
  • Severity: High
  • Verification: Verified (Runtime)
  • Location: crates/protocol-s3/src/server.rs:45-64 (router), crates/protocol-s3/src/handlers.rs:63-85 (put_object), :139-149 (delete_object), :185-234 (list_objects)

Reproduction / Context

Start the server with spacectl serve-s3 --port 8080, then:

Request Response Effect
PUT /b1/hello.txt?tagging with a <Tagging> body 200 hello.txt now contains the <Tagging> XML
PUT /b1/hello.txt?acl with <AccessControlPolicy/> 200, new ETag object replaced by <AccessControlPolicy/>
DELETE /b1/hello.txt?tagging 204 object deleted; the next GET is NoSuchKey
PUT /b1/dst.txt with x-amz-copy-source: /b1/src.txt 200 dst.txt is 0 bytes
GET /b1/hello.txt?tagging 200 returns the object body
GET /b1?location 200 returns a ListBucketResult

boto3 1.43.94 (path-style) shows the same results:

  • put_object_tagging() succeeds, and get_object() then returns b'<Tagging xmlns="http://s3.amazonaws.com/doc/2006-03-01/">...'.
  • copy_object() succeeds, and the copy reads back as b''.

Methods with no route get an empty-bodied response instead of an S3 <Error>, so SDKs report a bare ClientError (405) Method Not Allowed with no code:

  • 405 for POST /b1?delete and POST /b1/k?uploads.
  • 404 for GET / and PUT /b1/.

Proposed Fix / Recommendation

  • Add a guard (middleware or extractor) on both the bucket and object routes. It should reject any request whose query names an S3 subresource the server doesn't implement with 501, <Code>NotImplemented</Code>. Examples: acl, tagging, uploads, uploadId, partNumber, versionId, location, versioning, policy, cors, lifecycle, delete, restore, select, attributes. Build it as an allow-list of the parameters each handler understands, so subresources added later fail closed.
  • Reject x-amz-copy-source on PUT with NotImplemented until CopyObject exists. A server-side read-and-rewrite would implement it cheaply, since the copy dedups to the same segments.
  • Add a fallback handler that returns S3 XML (MethodNotAllowed / NotImplemented) for unmatched routes and methods.
  • Add a regression test for each row of the table above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugprotocol-s3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions