spring-framework: Content-Disposition with fixed file name "f.txt" causes confusion [SPR-13643]

Dave Syer opened SPR-13643 and commented

$ curl -v localhost:8888/foo/bar/master/application.yml
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8888 (#0)
> GET /foo/bar/master/application.yml HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8888
> Accept: */*
> 
< HTTP/1.1 200 OK
* Server Apache-Coyote/1.1 is not blacklisted
< Server: Apache-Coyote/1.1
< X-Application-Context: configserver:8888
< Content-Disposition: attachment;filename=f.txt
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 120
< Date: Wed, 04 Nov 2015 14:48:09 GMT
< 
...

Users expect the filename would be “application.yml”. It looks weird in the browser when you get a download of a file that has the wrong name.

Here’s the endpoint:

@RequestMapping("/{name}/{profile}/{label}/{path:.*}")

From https://github.com/spring-cloud/spring-cloud-config/blob/c0ddcd8/spring-cloud-config-server/src/main/java/org/springframework/cloud/config/server/resource/ResourceController.java#L63


Affects: 4.1.8, 4.2.2

Issue Links:

  • #18124 Protect against RFD exploits
  • #18164 Content-Disposition header causes download in browser for Spring Boot Actuator endpoints

Referenced from: commits https://github.com/spring-projects/spring-framework/commit/a3168fde18f34489bcbb497f3accc4c930fdb098, https://github.com/spring-projects/spring-framework/commit/92ca537d6147eceedb39ee389ae9eac9c3d5a955, https://github.com/spring-projects/spring-framework/commit/1489e29d0c0d91da194721eb47f415118b00b532, https://github.com/spring-projects/spring-framework/commit/3a919a48d6941622ae1b08034630b0f565d0554b, https://github.com/spring-projects/spring-framework/commit/f0464e81761d2631902d512d67016967b9cd316a, https://github.com/spring-projects/spring-framework/commit/f5f57e95441166b82241f755b09a58743fe429f8, https://github.com/spring-projects/spring-framework/commit/71a9eb7102f3a9fbdbcfa0b449c9ddc149652e6d

Backported to: 4.1.9, 3.2.16

0 votes, 7 watchers

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 16

Most upvoted comments

Rob Winch commented

A note that is good for historical records…

I spoke to John Melton, a respected security expert, offline. He favored using a constant as well.

He also pointed out that a constant filename will make searching for a solution easier. Specifically, searching for “spring f.txt” will result in a quick answer. However, if the filename was dynamic the search might be more challenging.

Rob Winch commented

As demonstrated in #18124 reflecting user input is quite risky. This is especially true for HTTP headers. As previously mentioned, allowing user defined input to control the filename increases the attack surface which tends to lead to vulnerabilities.

In this instance, allowing the user to specify the file name can lead to attacks like HTTP Response Splitting. There is an excellent white paper on Content-Disposition and HTTP Response splitting.

More concretely a malicious user could craft a URL that looks like:

https://example.com/run.bat%22%0D%0A%0D%0Anotepad%0D%0A%0D%0A

This would produce an HTTP response that looks like:

HTTP/1.1 200 OK
..
Content-Disposition: attachment; filename="run.bat"

notepad

.txt" # this is the suffix we tried to append to the file name we computed
1. remainder of HTTP headers and the body

This leads us right back to where we started.

A few important things to highlight:

  • We could whitelist the possible characters that the filename could have
  • Many modern application servers protect against HTTP Response splitting. For example, tomcat replaces new line characters with a space.

While the example I provided does not produce a valid exploit (if done properly), it does lead to quite a bit more code and increases the attack surface of the application. For these reasons, I think we are better off leaving the file name a constant.