Skip to content

feat(download): let the browser download Bunny files under their real name - #160

Merged
yusufipk merged 1 commit into
masterfrom
feat/bunny-named-downloads
Dec 4, 2026
Merged

yusufipk merged 1 commit into
masterfrom
feat/bunny-named-downloads

Conversation

@yusufipk

@yusufipk yusufipk commented Dec 4, 2026

Copy link
Copy Markdown
Owner

Bunny downloads under 10 GB are pulled into a Blob inside the tab so the app can choose the file name. For a multi-GB file that means:

  • the tab has to stay open;
  • the whole file is copied again at the end;
  • there is no resume;
  • a drop near the end falls back to a plain navigation that starts again from zero.

Change. This is behind OPENFRAME_ENABLE_BUNNY_NAMED_DOWNLOADS. It is off by default and has no effect without BUNNY_CDN_TOKEN_KEY.

  • GET /api/versions/[versionId]/download redirects to a Bunny URL that carries the file name in fn. The name is signed inside the HMAC token: signBunnyNamedDownloadUrl, valid 6h, with no token_ignore_params.
  • An edge rule on the pull zone turns fn into Content-Disposition: attachment; filename*=UTF-8''.... The rule's exact triggers are documented in .env.example.
  • The server builds the name as "title label" or "title vN". A caller may pass a stem, but never the extension: that comes from the CDN's Content-Type. So name=invoice.exe saves as invoice.exe.mov.
  • The video page and project downloads start the file as a download (download attribute on the same-origin route). The browser's own download manager then takes it: straight to disk, resumable, and it survives the tab. Project downloads pace requests at 1.1 s to stay under the route's 60 per minute limit, and hold no unload guard when every file goes to the browser.
  • sanitizeDownloadFileName and the MIME map moved to lib/download-file-name.ts so the server can use them. The client re-exports them.

Tested live against a Bunny test pull zone with token auth on, using headless Chromium:

  • Chromium saved the file as Magi 2 İlk Video - 1.1 v3.mov with all bytes, including with the live zone's existing Force Download rule mirrored on the test zone. Our header replaces its bare attachment; and only one Content-Disposition is sent.
  • Bunny URL-decodes fn once before substituting it, so the URL carries it encoded twice.
  • An edited signed fn gets 403. %0D%0A stays literal in the header. The header is set per request and never sticks in the cache (the zone ignores query strings for caching).
  • The security review found that a first version of the rule also named files on playback URLs, whose tokens ignore extra parameters. Anyone could then serve Invoice.pdf.exe from the zone. The final triggers allow only query-string HS256 tokens without token_ignore_params. Live checks: a playback URL with its own fn gets no name, and adding a fake or copied query token gets 403.
  • Headless Playwright could not show Chrome resuming an interrupted download, because it marks the download canceled. Bunny answers Range requests (206) and sends Last-Modified, which Chrome's resume needs, but resume itself is not verified.

Not changed. Attachment (asset) downloads still use the buffered path. The 150-character stem cap can cut the version suffix off a very long project file name; the browser then adds " (1)" instead of overwriting.

Rollout.

  1. Add the edge rule to the live pull zone. It is inert until the flag is set.
  2. Set OPENFRAME_ENABLE_BUNNY_NAMED_DOWNLOADS=true in the app environment.

Validation. bun run check passes, and so do 3330 unit and component tests and the download API tests. New tests: tests/api/bunny-named-download.test.ts, tests/unit/lib/download-file-name.test.ts, tests/component/project-download-manifest.test.ts, plus additions to the token, manifest and hook tests.

… name

Bunny downloads were pulled into a Blob inside the tab so the app could pick
the file name. A multi-GB file held the tab open, was copied again at the end,
could not resume, and a drop near the end silently restarted it from zero as
a plain navigation.

Behind OPENFRAME_ENABLE_BUNNY_NAMED_DOWNLOADS (off by default, and only with a
CDN token key), the download route now redirects to a Bunny URL carrying the
file name in `fn`, signed inside the token, and a pull-zone edge rule turns it
into Content-Disposition. The browser's own download manager then saves the
file straight to disk under that name. The server builds the name; a caller
may pass a stem, never the extension, which comes from the file's type.

Project downloads use the same route, start each file as a download rather
than a navigation, and pace requests under the route's rate limit.
@yusufipk
yusufipk merged commit d34e6f3 into master Dec 4, 2026
13 checks passed
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.

1 participant