Skip to content

Remove RFC 2047 encoding from Content-Disposition filename#36328

Open
tobifasc wants to merge 1 commit intospring-projects:mainfrom
tobifasc:main
Open

Remove RFC 2047 encoding from Content-Disposition filename#36328
tobifasc wants to merge 1 commit intospring-projects:mainfrom
tobifasc:main

Conversation

@tobifasc
Copy link

Appendix C.1 of RFC 2066 and Section 5 of RFC 2047 describe that an "encoded-word" (as described in RFC 2047) must not be used as parameter of a Content-Disposition header.

The current implementation in ContentDisposition does however encode the fallback filename parameter using the mechanism described in RFC 2047 (given that the charset is set to something other than US_ASCII).
Related discussion: #29861

This PR updates the Content-Disposition header creation logic to use only ISO-8859-1 characters for the fallback filename parameter instead. Non-compatible characters are replaced with ?. The "full" filename is still present in the filename* parameter.

This does not remove the ability to parse RFC 2047 encoded headers.

Updates the Content-Disposition header creation logic to use only
ISO-8859-1 characters for the fallback 'filename' parameter instead of
RFC 2047 encoded strings. Non-compatible characters are replaced with '?'.

This does not remove the ability to parse RFC 2047 encoded filenames.

Signed-off-by: Tobias Fasching <tobias.fasching@outlook.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 13, 2026
@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Mar 10, 2026
@bclozel bclozel self-assigned this Mar 10, 2026
@bclozel bclozel added this to the 7.0.x milestone Mar 10, 2026
@bclozel bclozel added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 10, 2026
}
return PRINTABLE.get(b);
private static String toIso88591(String input) {
return new String(input.getBytes(StandardCharsets.ISO_8859_1));
Copy link

@shardt68 shardt68 Mar 11, 2026

Choose a reason for hiding this comment

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

this would lead to Questionmarks "?" in the propose filename, which is not allowed in most filesystems,
I would rather propose an underline in place of non ascii characters
Suggetion:
// NFD decomposition splits characters like ä into base character 'a' + combining diacritic.
// Removing the combining diacritics (Unicode category Mn) gives a readable ASCII approximation
// (e.g. "Schöne Äpfel" → "Schone Apfel") without resorting to '?' which is a forbidden
// filename character on Windows.
String decomposed = java.text.Normalizer.normalize(input, java.text.Normalizer.Form.NFD);
return decomposed
.replaceAll("\p{InCombiningDiacriticalMarks}", "")
.replaceAll("[^\\x20-\\x7E]", "_");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants