Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentDisposition cannot parse encoded filename with leading space #24112

Closed
aaronols opened this issue Dec 2, 2019 · 0 comments
Closed

ContentDisposition cannot parse encoded filename with leading space #24112

aaronols opened this issue Dec 2, 2019 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@aaronols
Copy link

aaronols commented Dec 2, 2019

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.

@aaronols aaronols changed the title ContentDisposition parser cannot parse encodings ContentDisposition parser cannot parse encodings with space in front of them Dec 2, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 2, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 6, 2019
@rstoyanchev rstoyanchev added this to the 5.2.3 milestone Dec 6, 2019
@rstoyanchev rstoyanchev self-assigned this Dec 6, 2019
@rstoyanchev rstoyanchev added the for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x label Dec 6, 2019
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x labels Dec 6, 2019
@rstoyanchev rstoyanchev changed the title ContentDisposition parser cannot parse encodings with space in front of them ContentDisposition cannot parse encoded filename with leading space Dec 10, 2019
rstoyanchev added a commit that referenced this issue Dec 13, 2019
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) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants