-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Error page does not utilize forwarded prefix #30828
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
Thanks for the sample, @bpfoster. The |
It's only the behavior on the error-handling side that is the same. The behaviour of the links endpoint changes because the native forwarded header handling in Tomcat (and Jetty and Undertow) does not support When the That leaves us with doing something in Boot or the application. One possibility is through a custom @Bean
DefaultErrorAttributes errorAttributes() {
return new DefaultErrorAttributes() {
@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, options);
addPath(errorAttributes, webRequest);
return errorAttributes;
}
private void addPath(Map<String, Object> errorAttributes, WebRequest webRequest) {
String path = getAttribute(webRequest, RequestDispatcher.ERROR_REQUEST_URI);
if (path == null) {
return;
}
HttpServletRequest servletRequest = ((ServletWebRequest)webRequest).getRequest();
while (servletRequest instanceof HttpServletRequestWrapper wrapper) {
servletRequest = (HttpServletRequest) wrapper.getRequest();
}
String pathPrefix = servletRequest.getHeader("X-Forwarded-Prefix");
errorAttributes.put("path", (pathPrefix != null) ? pathPrefix + path: path);
}
@SuppressWarnings("unchecked")
private <T> T getAttribute(RequestAttributes requestAttributes, String name) {
return (T) requestAttributes.getAttribute(name, RequestAttributes.SCOPE_REQUEST);
}
};
} This code assumes that you're using Framework's I'll label the issue for discussion in a team meeting so that we can consider our options. |
Thanks for the response @wilkinsona! Tomcat not using I do notice in I would think, if possible, it'd be better to have boot/framework automatically make this decoration in In the end, the path in the error response is probably not a big deal, but I did expect to see a consistent representation between these paths and that the error representation generated by Spring would have the same path handling as other points. |
We talked about this today and realised that this could be addressed in Framework. When |
We could set the I'm wondering if Boot could rely on |
Won't |
Indeed, I'll give it a try. |
Thanks for the sample @bpfoster. There is now a fix, which I have confirmed with the sample, but if you'd like to give it a try in your application, please use |
Hi @rstoyanchev, sorry for the delayed response. We've upgraded to framework 6.1.3 and I can confirm that I now see the path prefix in the error path. Thank you! |
Not sure if this belongs in Boot or Framework or somewhere else..
Spring Boot version: 3.0.7
If my Spring Boot application is behind a proxy, and I've configured the X-Forwarded-* headers to be sent, and the Boot application is configured with
server.forward-headers-strategy=FRAMEWORK
, I would expect thepath
attribute in the default error response to reflect the forwarded path prefix, but it does not.I have an extremely simple reproduction application at https://github.com/bpfoster/spring-boot-error-path-forwarded-prefix
Actuator includes the path prefix as expected:
The error response does not:
Note the
href
s in actuator include the X-Forwarded-Prefix value vs thepath
in the error do not.The text was updated successfully, but these errors were encountered: