Skip to content

JSPWIKI-922 Encode non-ASCII attachment names in the Content-Disposition header - #571

Merged
arturobernalg merged 2 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-922-content-disposition-filename
Nov 2, 2026
Merged

arturobernalg merged 2 commits into
apache:masterfrom
arturobernalg:feature/JSPWIKI-922-content-disposition-filename

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

JSPWIKI-922

AttachmentServlet wrote the name of an attachment as it is inside the quoted filename parameter of Content-Disposition. On a running instance (Tomcat 10.1, current master) an attachment named Täst.txt was served with Content-Disposition: inline; filename="T\xE4st.txt";, that is one raw 0xE4 byte, which is not valid UTF-8. The header was the same over HTTP/1.1 and over HTTP/2. A name that contains a quote or a backslash also ended the quoted string.

A name with a character outside printable ASCII, a quote or a backslash now gets an ASCII fallback in filename and the UTF-8 name, percent encoded, in filename* (RFC 6266, RFC 8187): filename="T_st.txt"; filename*=UTF-8''T%C3%A4st.txt;. Names made of printable ASCII characters are written as before.

Tests: 8 new tests in AttachmentServletTest. They do not compile on master, because encodeFileName does not exist there. AttachmentServletTest (10 tests), AttachmentManagerTest (14) and BasicAttachmentProviderTest (13) pass. On a running instance with this change, an attachment with an umlaut, one with a Chinese name and one with a quote in the name were downloaded with status 200 over HTTP/1.1 and over HTTP/2 without TLS, with the new header.

Not tested: Firefox and HTTP/2 over TLS. A comment on JSPWIKI-922 reports a network error when a file with umlauts in its name is downloaded in Firefox; it is not known whether this change affects that error.

…ion header

The name of an attachment was written as it is inside the quoted filename parameter. A character
outside printable ASCII went out as a single raw byte (0xE4 for a-umlaut), which is not valid UTF-8,
and a name with a quote or a backslash ended the quoted string. Such names now get an ASCII
fallback in filename and the UTF-8 name, percent encoded, in filename* as in RFC 6266 and RFC 8187.
Names made of printable ASCII characters are written as before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can confirm that this patch allows me to upload and download attachments with names containing umlauts, and that, after download, they're stored with their names intact. So it looks good to me.

@arturobernalg
arturobernalg merged commit 827c58d into apache:master Nov 2, 2026
8 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.

2 participants