Skip to content

fix(s3): a subresource marker routes on presence, not on a sentinel value (#656) - #657

Merged
scttfrdmn merged 1 commit into
mainfrom
s3-subresource-routing-656
Aug 15, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
s3-subresource-routing-656

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #656

The defect

S3 routes bucket-policy and ACL operations on a query-string marker — ?policy, ?acl — and emulator/s3_plugin.go compared that marker against the "1" sentinel parser.go assigns to bare query keys. aws-sdk-go-v2 does not send a bare key. It sends ?policy= — a key with an empty value — which the sentinel is never applied to.

Captured from aws-sdk-go-v2 service/s3 v1.107.0 against an httptest server:

PUT    /b   RawQuery="policy="     <- PutBucketPolicy
GET    /b   RawQuery="policy="     <- GetBucketPolicy
DELETE /b   RawQuery="policy="     <- DeleteBucketPolicy
PUT    /b   RawQuery="acl="        <- PutBucketAcl
GET    /b   RawQuery="acl="        <- GetBucketAcl

So the comparison failed on every request a real client made, and seven operations fell through to their arm's default:

Called Actually handled as
PutBucketPolicy CreateBucket → 409 BucketAlreadyExists
GetBucketPolicy ListObjectsV2
DeleteBucketPolicy DeleteBucket
PutBucketAcl CreateBucket → 409
GetBucketAcl ListObjectsV2
PutObjectAcl PutObject — overwrites the object with the ACL request's empty body
GetObjectAcl GetObject

DeleteBucketPolicy is data loss. A consumer clearing a bucket policy destroyed the bucket. On a bucket holding objects the misroute at least surfaced as BucketNotEmpty; on an empty bucket it answered 204 — byte for byte what a correct DeleteBucketPolicy returns — so nothing in the response distinguished the two and only a later call revealed the bucket was gone.

Why no test caught it

Every S3 unit test passed throughout. Each one hand-built Params{"policy": "1"}, so the suite asserted the routing worked for the one request shape no client sends. This is the #446 class and the #561/#610/#636 class at once: a path only a real client exercises cannot be pinned by a test that builds the request itself.

The fix

All seven comparisons become presence tests, under a block comment stating the invariant: a subresource marker is tested for presence, never for a value. A marker carries no information beyond being there, and its wire shape is the client's choice, not substrate's. list-type is the sole exception and stays a value test, because 2 genuinely selects ListObjectsV2.

Coverage, at the levels that can see the difference

emulator/s3_subresource_routing_test.go — through Server.ServeHTTP, so the parser produces the params:

  • the policy lifecycle in both marker shapes, ending with a HeadBucket that asserts the bucket survived (a misrouted delete answers 204 either way, so only a later call distinguishes the data-loss path)
  • the bucket-ACL and object-ACL pairs, the latter also asserting the object's bytes survive PutObjectAcl
  • nine markers × five values, asserting a marker's value never changes routing — the guard against the class rather than the instance
  • the list-type counter-case, asserting "", "1" and "3" are not ListObjectsV2
  • the in-process path, where a caller (the CFN deployer, or any plugin reading another service) sets params by hand

test/e2e/journey_s3_bucket_policy_test.go — through the real SDK, the tier that found this. TestS3_DeleteBucketPolicyLeavesAnEmptyBucketStanding is separate on purpose: in the full lifecycle the misroute is stopped by BucketNotEmpty before the survival assertion is reached, so the silent case needs its own path to it.

Verification

Full gate green: gofmt/build/vet/golangci-lint (0 issues), make test (race), make coverage (emulator 82.7%), docs targets, npm --prefix docs run build, test/e2e.

Each new test was confirmed to fail against the pre-fix code, including the silent path with only the DELETE-arm sentinel restored.

Live-server check with the real AWS CLI (AWS_MAX_ATTEMPTS=1): policy put/get/delete round trip, the public-read grant reflected in GetBucketAcl, the bucket standing after DeleteBucketPolicy, and NoSuchBucketPolicy on the follow-up read.

Mutation testing: 5 mutants, 5 CAUGHT, 0 survivors — four sentinel restorations plus one flattening list-type to a presence test. The last survived the first version of TestS3_ListTypeIsStillValueSensitive, which only covered =2 and absence; extending it to other values caught it.

…alue (#656)

S3 routes bucket-policy and ACL operations on a query-string marker, and substrate
compared that marker against the "1" sentinel parser.go assigns to *bare* query keys.
aws-sdk-go-v2 does not send a bare key: it sends "?policy=", a key with an empty value,
which the sentinel is never applied to. Seven comparisons therefore failed on every
request a real client made, and each fell through to its arm's default:

  PutBucketPolicy    -> CreateBucket  (409 BucketAlreadyExists)
  GetBucketPolicy    -> ListObjectsV2
  DeleteBucketPolicy -> DeleteBucket
  PutBucketAcl       -> CreateBucket
  GetBucketAcl       -> ListObjectsV2
  PutObjectAcl       -> PutObject     (overwrites the object)
  GetObjectAcl       -> GetObject

DeleteBucketPolicy is data loss: clearing a policy destroyed the bucket. On a bucket
holding objects the misroute surfaced as BucketNotEmpty; on an empty one it answered 204,
byte for byte what a correct DeleteBucketPolicy returns, so only a later call revealed
the bucket was gone.

Every S3 unit test passed throughout, because each hand-built Params{"policy": "1"} --
the one shape no client sends. The rule adopted here is that a subresource marker is
tested for presence and never for a value: it carries no information beyond being there,
and its wire shape is the client's choice. list-type stays a value test, being the one
query key whose value genuinely selects the operation.

Coverage goes to the levels that can see the difference: through Server.ServeHTTP in
both marker shapes, a value-insensitivity assertion over nine markers and five values,
and e2e journeys through the real SDK -- one of which exists solely to reach the silent
case and assert an emptied bucket is still standing after its policy is cleared.

Verified against a live server with the AWS CLI. Mutation-tested 5/5 caught.
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 6122c75 into main Aug 15, 2026
13 checks passed
@scttfrdmn
scttfrdmn deleted the s3-subresource-routing-656 branch August 15, 2026 08:26
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 subresource routing misses every SDK bucket-policy and bucket-ACL call; DeleteBucketPolicy destroys the bucket

1 participant