Repository navigation
Description
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:
curl 'http://localhost:8080/foo' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundaryHBic2VjAi3E215bk' --data-binary $'------WebKitFormBoundaryHBic2VjAi3E215bk\r\nContent-Disposition: form-data; name="file"; filename="doc-xlsx.xlsx"\r\nContent-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\r\n\r\n\r\n------WebKitFormBoundaryHBic2VjAi3E215bk\r\nContent-Disposition: '
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).
@Bean
public EmbeddedServletContainerFactory servletContainer() {
// Disable tomcat version and exception logging by ErrorReportValve
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
ErrorReportValve errorReportValve = new ErrorReportValve();
errorReportValve.setShowReport(false);
errorReportValve.setShowServerInfo(false);
tomcat.addContextValves(errorReportValve);
return tomcat;
}I think it's possible to overwrite TomcatEmbeddedServletContainerFactory#getEmbeddedServletContainer to return Tomcat instance with different host 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.
Activity
wilkinsona commentedon Jan 13, 2017
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.
dreambrother commentedon Jan 16, 2017
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
but not for corrupted request. Example of corrupted request was given in the issue description.
wilkinsona commentedon Jan 23, 2017
@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
ErrorReportValveplaces it in the wrong place so the logic in Tomcat that would route to/errorand then one of your custom error pages doesn't get called.The underlying problem with the corrupted request is due in part to
HiddenHttpMethodFilter. It's in the filter chain for the dispatch to/errorand its call torequest.getParameter("_method")fails due to the corrupted request. This failure while trying to dispatch to an error page causes Tomcat's default error page to be rendered. You can disableHiddenHttpMethodFilterby adding aFilterRegistrationBeanthat it not enabled:An alternative would be to provide a custom
HiddenHttpMethodFilterthat doesn't do anything when an error is being dispatched:It feels to me like
HiddenHttpMethodFiltershould do something like this by default. I've opened SPR-15179.Either approach doesn't fully resolve the problem as the dispatch to
/errorstill fails. The request now makes it toDispatcherServletbut its attempt to check the multipart request fails:The logging in
checkMultipartsuggests that this problem should be avoided by checking thejavax.servlet.error.exceptionrequest attribute:However, this doesn't work as the request attribute is a
NestedServletExceptionwith aMultipartExceptioncause. You can work around this by declaring a customDispatcherServletbean that overridescheckMultipart():I've opened https://jira.spring.io/browse/SPR-15178
wilkinsona commentedon Jan 23, 2017
@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.
wilkinsona commentedon Jan 24, 2017
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.