Skip to content

ContentDisposition cannot parse encoded filename with leading space #24112

@aaronols

Description

@aaronols

Affects:

  • Tested with spring-web 5.2.1.RELEASE
  • Affects probably all 5.0+ releases.

The Content-Disposition parser supports filename encoding.
However, if there is a space in front of the encoding, it fails with an IllegalCharsetNameException:

Exception in thread "main" java.nio.charset.IllegalCharsetNameException:  UTF-8
	at java.nio.charset.Charset.checkName(Charset.java:315)
	at java.nio.charset.Charset.lookup2(Charset.java:484)
	at java.nio.charset.Charset.lookup(Charset.java:464)
	at java.nio.charset.Charset.forName(Charset.java:528)
	at org.springframework.http.ContentDisposition.parse(ContentDisposition.java:285)

Note the two spaces in front of the 'UTF-8'. One is from the exception string template, the other is from the parsed value from the response header.

We have an application running on the Undertow webserver. The exact header from an example response looks like this:
Content-Disposition: attachment; filename*= UTF-8''some-file.zip

This is a valid header format as per RFC 6266 Section 5 (Examples) where the following example is listed:

     Content-Disposition: attachment;
                          filename*= UTF-8''%e2%82%ac%20rates

My suggested fix is to trim() the charset before passing it to Java.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions