Browse Source

Skip Content-Disposition header if status != 2xx

Issue: SPR-13588
pull/931/head
Rossen Stoyanchev 10 years ago
parent
commit
a879897063
  1. 21
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java

21
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java

@ -252,11 +252,12 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe @@ -252,11 +252,12 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
}
/**
* Check if the path has a file extension and whether the extension is either
* {@link #WHITELISTED_EXTENSIONS whitelisted} or
* {@link ContentNegotiationManager#getAllFileExtensions() explicitly
* registered}. If not add a 'Content-Disposition' header with a safe
* attachment file name ("f.txt") to prevent RFD exploits.
* Check if the path has a file extension and whether the extension is
* either {@link #WHITELISTED_EXTENSIONS whitelisted} or explicitly
* {@link ContentNegotiationManager#getAllFileExtensions() registered}.
* If not, and the status is in the 2xx range, a 'Content-Disposition'
* header with a safe attachment file name ("f.txt") is added to prevent
* RFD exploits.
*/
private void addContentDispositionHeader(ServletServerHttpRequest request,
ServletServerHttpResponse response) {
@ -266,6 +267,16 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe @@ -266,6 +267,16 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
return;
}
try {
int status = response.getServletResponse().getStatus();
if (status < 200 || status > 299) {
return;
}
}
catch (Throwable ex) {
// Ignore
}
HttpServletRequest servletRequest = request.getServletRequest();
String requestUri = RAW_URL_PATH_HELPER.getOriginatingRequestUri(servletRequest);

Loading…
Cancel
Save