Skip to content

fix(#1349): name every published S3 sub-resource, so an unrouted one is refused rather than reinterpreted - #1351

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1349-s3-subresource-routing
Oct 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1349-s3-subresource-routing

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Fixes #1349

The bug: data loss from a routing default

parseS3Operation names every S3 request's operation, for the plugin's switch and for the
pipeline's authorization, metering and event log. Each method arm tested a fixed list of sub-resource
keys and otherwise returned its default, so any published sub-resource missing from the list became
a different, routed operation
:

Request Became Effect
DeleteBucketCors, DeleteBucketEncryption, DeleteBucketWebsite, DeleteBucketOwnershipControls, DeleteBucketReplication DeleteBucket the bucket was deleted (204, then HeadBucket 404)
PutObjectRetention, PutObjectLegalHold PutObject the object was overwritten with the XML body
GetBucketLocation ListObjects answered a ListBucketResult
PutBucketCors and others CreateBucket answered 200 and recorded nothing

The resolved name was also the authorized name. DeleteBucketEncryption needed
s3:DeleteBucket; ListObjects maps to s3:ListBucket at authz.go:840.

#446 (?publicAccessBlock) and #656 (?policy, ?acl) each fixed one sub-resource by adding it
to the list. The defaults were reached by absence, so the next unlisted name failed the same way.
#1350's S3 wire test found it: its GetBucketLocation presence anchor read a listing.

The fix: name each unrouted sub-resource for what it is

The new emulator/s3_subresources.go holds two tables, bucket-level and object-level, mapping
(method, sub-resource key) to the real operation name for every published sub-resource substrate
does not route
:

  • Bucket level: accelerate; the four id-keyed configuration families (analytics, inventory,
    metrics, intelligent-tiering), where an id param selects Get and its absence selects List; cors;
    encryption; location; logging; object-lock; ownershipControls; policyStatus; replication;
    requestPayment; website; the V1 metadataTable and V2 metadataConfiguration families, including
    their two PUT update operations; and session (CreateSession).
  • Object level: retention, legal-hold, attributes, torrent and restore.

I checked the URI forms of the less common ones (CreateSession, the metadata tables,
intelligent-tiering, GetObjectAttributes) against the S3 API reference today.

parseS3Operation consults the tables immediately before each default, after every routed test,
so no routed operation changes name. HandleRequest's switch does not route the new names, and
its existing default answers NotImplemented/501, which is S3's own published code. The operation
catalog is generated from that switch, so operation-catalog-check and operation-docs-check see no
change. Keys are tested for presence only, per the file's #656 convention, since SDKs send ?cors=.
Keys are visited in sorted order, so a malformed two-key request always resolves the same way, which
matters for replay.

Tests: emulator/s3_subresource_routing_test.go, 46 subtests through the real server

  • The data-loss regression. Every unrouted bucket DELETE (eleven) is refused with 501 and the
    bucket still answers HeadBucket 200
    .
  • The object overwrite. PUT ?retention and ?legal-hold are refused, and the object's bytes are
    unchanged.
  • No silent success. Thirteen more unrouted GET/PUT/POST requests at both levels answer 501.
  • The authorized name. Through ParseAWSRequest, DELETE /b?encryption resolves to
    DeleteBucketEncryption, the id-keyed families split Get/List correctly, and twenty routed
    forms
    (DeleteBucket, ListObjects with prefix/delimiter, ListObjectsV2 with
    start-after, PutObject, the tagging operations and others) resolve exactly as before.

Negative control (run, then restored)

Removing encryption from the DELETE table brings the bug straight back:

  • UnroutedDelete…/DeleteBucketEncryption fails, because the request is reinterpreted.
  • Resolves…/DELETE /b?encryption fails, because it resolves to DeleteBucket again.

All existing S3 tests pass unchanged.

Not in this PR

Implementing any of the newly named operations stays with its own issue: CORS is #1278 and encryption
is #493. Both get a comment that they are now refused rather than reinterpreted. #508's sub-resource
cleanup on DeleteBucket is separate.

Verification

All of these pass:

  • make lint: 0 issues.
  • make test: race, -count=1.
  • docs-reference-check docs-versions version-check discarded-unmarshal-check wire-bookkeeping-check operation-catalog-check operation-docs-check.

…is refused rather than reinterpreted

parseS3Operation reached each method's default by absence: any published
sub-resource missing from its lists became DeleteBucket, CreateBucket,
ListObjects, PutObject or GetObject. DeleteBucketCors, DeleteBucketEncryption,
DeleteBucketWebsite, DeleteBucketOwnershipControls and DeleteBucketReplication
each deleted the bucket; PutObjectRetention and PutObjectLegalHold overwrote the
object with their XML body; GetBucketLocation answered a listing. The name was
also what the request was authorized under, so each needed s3:DeleteBucket or
s3:PutObject rather than its own action. #446 and #656 fixed one sub-resource at
a time.

emulator/s3_subresources.go names every published bucket- and object-level
sub-resource substrate does not route, and parseS3Operation consults it just
before each default, after every routed test, so no routed operation changes
name. Each resolves to its real operation and HandleRequest's existing default
refuses it as NotImplemented/501, the code S3 publishes.

emulator/s3_subresource_routing_test.go drives every unrouted bucket DELETE and
requires the bucket to survive, requires the object to survive both object PUTs,
and pins the resolved names through ParseAWSRequest beside twenty routed ones.

Fixes #1349
@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s3: an unrouted bucket sub-resource falls through to DeleteBucket, so DeleteBucketEncryption (and four others) delete the bucket

1 participant