Skip to content

Add filename to Content-Disposition header for DAM downloads - #6338

Open
VPS-Obi wants to merge 1 commit into
mainfrom
claude/file-name-content-disposition-x8ra8y
Open

Add filename to Content-Disposition header for DAM downloads#6338
VPS-Obi wants to merge 1 commit into
mainfrom
claude/file-name-content-disposition-x8ra8y

Conversation

@VPS-Obi

@VPS-Obi VPS-Obi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The header was previously set to attachment without a file name, so browsers derived the name of the downloaded file from the URL, which contains the file name without its extension.

Uses Express' res.attachment instead of building the header by hand, which does proper escaping and RFC 5987 encoding. Note: this also sets the Content-Type-header based on the file extension, but this is overridden in streamFile.

https://claude.ai/code/session_01CxUhjh9AAnB6AHvGopkdCu

The download endpoints sent a bare `attachment`, so browsers fell back to
the URL for the name of the saved file. That URL only contains the file
name without its extension, leaving downloads without one.

Use `res.attachment()` instead of building the header by hand: file names
are not slugified when a file is renamed, so they can contain quotes or
non-latin1 characters, which need escaping and RFC 5987 encoding.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CxUhjh9AAnB6AHvGopkdCu
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: 7c9acf7f-539e-4578-8d8a-ef77ccce04d8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@VPS-Obi VPS-Obi self-assigned this Sep 9, 2026
@VPS-Obi
VPS-Obi marked this pull request as ready for review September 9, 2026 06:40
@VPS-Obi
VPS-Obi requested a review from nsams September 9, 2026 06:40
@VPS-Obi

VPS-Obi commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@nsams do we need the Content-Disposition-header for non-download-endpoints as well?

}

res.setHeader("Content-Disposition", "attachment");
res.attachment(file.name);

@nsams nsams Sep 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does also set mime type (see https://github.com/expressjs/express/blob/bed501c695a61886399ee622875f3be933c716d8/lib/response.js#L609), based on the file name. (which you noted in the description)

I'm not sure we should do that; doesn't it set the header twice? (two values)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this locally, it doesnt:

image

Alternatively, we could use the content-disposition package directly. I'd prefer to not roll our own encoding/escaping.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you verify using curl, so we can see the raw output?

Alternatively, we could use the content-disposition package directly.

yes, maybe better. is that what express uses internally?

@nsams

nsams commented Sep 9, 2026

Copy link
Copy Markdown
Member

do we need the Content-Disposition-header for non-download-endpoints as well?

yes, together with inline that might work. Needs proper testing in all browser we support...

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.

3 participants