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:.*}")
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
0 votes, 7 watchers
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 16
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:
This would produce an HTTP response that looks like:
This leads us right back to where we started.
A few important things to highlight:
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.