-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Server info leak after corrupted request #7936
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
Comments
Could you please provide a small sample that illustrates the problem you have described? I want to be sure that we're investigating exactly what you're describing. |
I've created a project https://github.com/dreambrother/spring-boot-server-info-leak-example illustrating issue described above. I've added public/error/500.html page to handle 500 errors, and it works as expected for exceptions thrown in controller @RequestMapping("/exception")
public String error() {
throw new RuntimeException("Error test");
} but not for corrupted request. Example of corrupted request was given in the issue description. |
@dreambrother Thanks. Your sample doesn't exactly reproduce the behaviour you've described, but I've been able to modify it to do so. The problem with your sample is that your custom configuration of the The underlying problem with the corrupted request is due in part to @Bean
public FilterRegistrationBean hiddenHttpMethodFilterRegistration(OrderedHiddenHttpMethodFilter filter) {
FilterRegistrationBean registration = new FilterRegistrationBean(filter);
registration.setEnabled(false);
return registration;
} An alternative would be to provide a custom @Bean
public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() {
return new OrderedHiddenHttpMethodFilter() {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) != null) {
filterChain.doFilter(request, response);
}
else {
super.doFilterInternal(request, response, filterChain);
}
}
};
} It feels to me like Either approach doesn't fully resolve the problem as the dispatch to
The logging in
However, this doesn't work as the request attribute is a @Bean
public DispatcherServlet dispatcherServlet() {
return new DispatcherServlet() {
protected HttpServletRequest checkMultipart(HttpServletRequest request) throws MultipartException {
if (getMultipartResolver() != null && getMultipartResolver().isMultipart(request)) {
if (WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class) != null) {
logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, " +
"this typically results from an additional MultipartFilter in web.xml");
} else {
Throwable error = (Throwable)request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE);
while (error != null) {
if (error instanceof MultipartException) {
logger.debug("Multipart resolution failed for current request before - " +
"skipping re-resolution for undisturbed error rendering");
return request;
}
error = error.getCause();
}
return getMultipartResolver().resolveMultipart(request);
}
}
// If not returned before: return original request.
return request;
}
};
} I've opened https://jira.spring.io/browse/SPR-15178 |
@dreambrother Can you please let us know how you get on with the workarounds described above? If both SPR issues are accepted, there may be nothing to do in Boot. |
The two SPR issues have been fixed. The workarounds described above are no longer required when using Spring Framework 4.3.6 snapshots. We'll upgrade to 4.3.6.RELEASE in #7774. |
I want to prevent any server info leak in error responses. I disabled whitelabel and stacktrace printing
server.error.include-stacktrace=never
server.error.whitelabel.enabled=false
I also tried to add my own error controller and custom error pages, but when I send corrupted request, embedded Tomcat responses with server info and stacktrace.
Example of corrupted request:
I tried to turn off report and server info printing manually, but exception message still presents in responses (it contains tomcat's and spring's classes names).
I think it's possible to overwrite
TomcatEmbeddedServletContainerFactory#getEmbeddedServletContainer
to returnTomcat
instance with differenthost
property,StandardHost#errorReportValveClass
should be changed for another class in that case. I didn't try this solution, because it creates too much coupling to underlying implementations. Looks like spring-boot should be able to do this.The text was updated successfully, but these errors were encountered: