fix(bb-file-bucket): harden dev file server against stored XSS and token forgery - #292
Merged
Conversation
…ken forgery The local dev file server served attacker-controlled bodies inline under an attacker-controlled Content-Type (stored-XSS primitive), and signed presigned-URL tokens with a hardcoded, source-visible secret (forgeable offline). - GET responses now send X-Content-Type-Options: nosniff and Content-Disposition: attachment so an uploaded text/html/SVG payload can't execute in the app origin. - LOCAL_FILE_SECRET is now a per-process random value instead of a fixed literal. The token-minting mock and the validating dev server share one in-process module instance, so local presigned-URL round-trips still work. Adds regression tests (both verified red on the old code): nosniff+attachment on GET, and rejection of a token forged with the former hardcoded secret.
🦋 Changeset detectedLatest commit: f7c59c8 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 |
soberm
approved these changes
Aug 4, 2026
Simone319
approved these changes
Aug 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Harden the local dev file server (
packages/bb-file-bucket/src/file-server.ts) against two issues in the same code path:Content-Type. Any client with a presigned PUT can upload atext/html/SVG payload; served inline it executes in the local app's origin. Now every download sends:X-Content-Type-Options: nosniffContent-Disposition: attachment'__blocks_file_bucket_dev_secret__'), so anyone could mint a valid token offline for anyfullId/path/method without ever callinggetUrl()/putUrl().LOCAL_FILE_SECRETis now a per-process random value (randomBytes(32)). The token-minting mock (index.mock.ts) and the validating dev server (file-server.ts) import the same in-process module instance, so local round-trips are unaffected; only offline forgery is closed.LOCAL_FILE_SECRETandtokens.tsare internal (not in the packageexportsmap, not inAPI.md), so this is not a public API change.Why
Board bug-bash card (P0 / Security): bb-file-bucket: dev mock signs uploads with hardcoded secret + serves text/html — https://github.com/orgs/aws-amplify/projects/141/views/15?pane=issue&itemId=195528277
Keeps local dev no weaker than an S3 object served behind CloudFront.
Testing
Two regression tests added to
file-server.test.ts, both verified red on the old code, green with the fix:GET sends
nosniff+Content-Disposition: attachmentafter uploading an HTML payload.A token forged with the former hardcoded secret is rejected (403).
npm run build(full monorepo) — passesnpm testinpackages/bb-file-bucket— 92 tests, 0 failuresbiome lint --changed --since=origin/main— cleanDESIGN.mdupdated (token-secret + download-hardening notes)Changeset
Included (
@aws-blocks/bb-file-bucketpatch).Scope note
The card mentions the mock also "serves whatever was uploaded as text/html". This PR addresses that via response hardening (nosniff + attachment) rather than rewriting content-type handling, and closes the hardcoded-secret half. Both halves of the card are covered.