Skip to content

Do not quote the filename* parameter in multipart Content-Disposition - #3337

Merged
arturobernalg merged 1 commit into
apache:masterfrom
shinseongsu:multipart-filename-star-unquoted
Dec 4, 2026
Merged

arturobernalg merged 1 commit into
apache:masterfrom
shinseongsu:multipart-filename-star-unquoted

Conversation

@shinseongsu

Copy link
Copy Markdown
Contributor

I'm Korean, and most of the files we upload have Korean names. Since 5.5, uploading a file like 월간 보고서.pdf with MultipartEntityBuilder breaks on some very common servers: the request returns 200, but the file is either gone or saved under a garbage name.

The cause is the quotes around the filename* value added in #618:

Content-Disposition: form-data; name="file"; filename="?? ???.pdf"; filename*="UTF-8''%EC%9B%94%EA%B0%84%20%EB%B3%B4%EA%B3%A0%EC%84%9C.pdf"

In RFC 8187 (section 3.2.1) ext-value is a token, not a quoted-string, and the RFC 6266 examples are unquoted too. Tomcat tolerates the quotes, but busboy (multer) and Werkzeug do not.

Client code (default mode):

MultipartEntityBuilder.create()
        .addBinaryBody("file", bytes, ContentType.APPLICATION_OCTET_STREAM, "월간 보고서.pdf")
        .build();

What the server receives (all responses are 200):

server 5.4.2 5.6.5 / master this PR
Spring Boot 3.5 (Tomcat 10.1) ?? ???.pdf 월간 보고서.pdf 월간 보고서.pdf
Express + multer 2.0 ?? ???.pdf no file at all 월간 보고서.pdf
Flask 3.1 (Werkzeug) ?? ???.pdf "UTF-8''%EC%9B%94...pdf" 월간 보고서.pdf

The multer case is the one that hurt: the upload looks successful and the file is silently dropped.

Change

filename* is now written without quotes in MimeField#getBody (used by the default STRICT mode, and also by LEGACY and non form-data EXTENDED) and in HttpRFC7578Multipart (EXTENDED form-data). In MimeField the quotes are dropped only when the value already has the UTF-8'' prefix (that is always the case for values produced by FormBodyPartBuilder). Anything else keeps the old quoted output.

When filename* is emitted, and the encoding itself, are unchanged from #618. Only the two quote characters go away, so Content-Length shrinks by 2 bytes for each part that has filename*. ASCII and Latin-1 file names produce exactly the same bytes as before.

Tests

  • Updated the 3 assertions in TestMultipartEntityBuilder that expected the quoted form.
  • Added testDefaultModeNonLatinFilenameWritesUnquotedFilenameStar for the default mode, which had no filename* test.
  • The new and updated tests fail on master and pass with this change. httpclient5 verify passes.

Question

A value passed in by the user as filename* through addField is passed through as is if it starts with UTF-8''. Before this change it was at least wrapped in quotes. Would you like me to also validate it against the RFC 8187 ext-value grammar here (and percent-encode it otherwise)? Or is that better left for a separate change?

RFC 8187 ext-value is a token, not a quoted-string. Express/multer
(busboy) drops the file part and Flask (Werkzeug) returns the literal
quoted string as the file name when filename* is quoted.
@ok2c

ok2c commented Dec 4, 2026

Copy link
Copy Markdown
Member

The cause is the quotes around the filename* value added in #618:

@arturobernalg Would you have time to take a look?

@arturobernalg arturobernalg left a comment

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.

LGTM. Thank you @shinseongsu

@arturobernalg
arturobernalg merged commit 5e4c419 into apache:master Dec 4, 2026
12 checks passed
@ok2c ok2c added this to the 5.7-beta2 milestone Dec 4, 2026
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