Skip to content

Harden Content-Disposition header for downloads (non-ASCII / quoted filenames) - #193

Open
sxpnet64 wants to merge 1 commit into
tscircuit:mainfrom
sxpnet64:fix/content-disposition-rfc5987
Open

sxpnet64 wants to merge 1 commit into
tscircuit:mainfrom
sxpnet64:fix/content-disposition-rfc5987

Conversation

@sxpnet64

Copy link
Copy Markdown

Fixes downloads failing for non-ASCII filenames and malformed headers for quoted filenames.

All four download paths interpolated the raw filename into the Content-Disposition header, which throws TypeError: Header 'Content-Disposition' has invalid value from new Response() for any non-ASCII name (the download fails entirely) and produces a malformed header for names containing ".

  • Adds getAttachmentContentDisposition() in lib/utils/content-disposition.ts: plain ASCII names keep the exact historical header; unsafe names get a sanitized ASCII fallback plus an RFC 5987 filename*=UTF-8''... parameter carrying the exact UTF-8 name
  • Wires it into all 6 header sites across both download routes and the file proxy
  • Adds 6 tests (4 unit + 2 integration); full suite 35 pass, 0 fail. The 2 integration tests fail on unfixed code (verified via stash).

/claim #5

Downloading a file whose name contains non-ASCII characters threw
`TypeError: Header 'Content-Disposition' has invalid value` from
`new Response()`, so the download failed entirely. A name containing
a double quote produced a malformed header instead.

Add a shared `getAttachmentContentDisposition()` helper (RFC 6266 /
RFC 5987): plain ASCII names keep the exact historical header, while
unsafe names get a sanitized ASCII fallback plus a `filename*`
parameter carrying the exact UTF-8 name. Wire it through both
download routes and both file-proxy paths, and add regression tests
covering the helper and both download forms.

Related: tscircuit#5
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