Repository navigation
fix(bb-file-bucket): return 404 from local file server for delete-marked keys - #1167
Conversation
🦋 Changeset detectedLatest commit: fd55366 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
belaboe
left a comment
There was a problem hiding this comment.
Thanks, the delete-marker 404 is right, and the test is a real regression test.
One gap worth closing here: with any versionId the new check is skipped, and an unknown versionId falls back to content/{key} (L131-137). So after delete('doc.txt'), getUrl('doc.txt', { versionId: 'v999' }), or the old URL with &versionId=v999, still returns 200 with the deleted body, while get() returns null and S3 would 404 NoSuchVersion. I'd suggest returning 404 NoSuchVersion when the version file is missing (or delegating GET to bucket.get() as PUT does), plus tests for "old version still readable after delete" and "unknown version -> 404".
Smaller: S3 also sets x-amz-delete-marker: true on this 404. Either add it, or say "matching get()" in the changeset. A line in DESIGN.md would help too.
Brings in 14 commits from main, among them "fix(core): return Invalid Request for a null JSON-RPC body" (#1143), "fix(core): reject non-JSON-RPC response bodies with ApiError" (#1171), "feat(bb-logger,core): backend Lambda log lines carry the invocation's requestId" (#1325), #1131, #1132, #1142, #1167, #1173, #1178, #1214, #494 and CI changes (#946, #970, #971). packages/core/src/client/index.test.ts and lambda-handler.test.ts: keep both sides' tests (this branch's httpErrorStatus, namespace identity and per-call fetch suites; main's non-JSON-RPC body and request id suites). packages/core/src/api.ts: the httpErrorStatus docs now say what the client does since #1171 when a Hosting error page replaces a 403 / 404: it rejects with a bare ApiError carrying the HTTP status, instead of response.json() throwing. # Conflicts: # packages/core/src/client/index.test.ts # packages/core/src/lambda-handler.test.ts
Problem
On a versioned bucket,
delete(key)without aversionIdwrites a delete marker (versions/{key}/__deleted__) and keepscontent/{key}. The mockget()honors the marker and returnsnull(packages/bb-file-bucket/src/index.mock.ts), but the local file server (packages/bb-file-bucket/src/file-server.ts) only checks thatcontent/{key}exists, so a presigned GET fromgetUrl()keeps returning 200 with the deleted body. S3 returns 404NoSuchKeywhen the current version is a delete marker.Issue #, if available:
Changes
packages/bb-file-bucket/src/file-server.ts: on GET withoutversionId, respond with the existing 404NoSuchKeyerror when the key's delete marker exists. GETs with an explicitversionIdare unchanged.packages/bb-file-bucket/src/file-server.test.ts: regression test for a deleted key on a versioned bucket (404, while an undeleted key still returns 200), plus a control for delete on an unversioned bucket..changeset/bb-file-bucket-file-server-delete-marker.md: patch changeset for@aws-blocks/bb-file-bucket.Validation
GET without versionId returns 404 when the current version is a delete markerfailed before the fix (deleted key must not be served,200 !== 404) and passes after.npm run build,@aws-blocks/bb-file-bucketnpm test,npm run lint,npm run lint:deps: pass.npm test(all workspaces) andnpm run test:e2e:localfrom the repo root: pass.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.