-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
RelativeRedirectResponseWrapper does not commit response in sendRedirect #29050
Conversation
Could we take a step back here? Even if we were to flush the buffer where it's suggested, it would not prevent some code to further write to the response, still leading to an incorrect HTTP message (a redirect+location response with invalid HTML content?). |
b5482c0
to
78d3236
Compare
I will try to provide minimal reproducible code. |
@bclozel Here is the demo repo: https://github.com/yuezk/RelativeRedirectFilter-bug. It uses |
We also need to call
|
e4f3ccc
to
4de3c2c
Compare
4de3c2c
to
2898235
Compare
sendRedirect()
methodsendRedirect()
method
sendRedirect()
method
Thanks @yuezk , this will be shipped in the next maintenance release. |
According to the Servlet spec 5.5 Convenience Methods,
sendRedirect()
should commit the response.Currently, it could cause a problem where the server couldn't redirect the user to the URL passed in. Though it might be rare.
We encountered the problem aforementioned. We configured the
ForwardedHeaderFilter
withrelativeRedirect
set totrue
, inside theForwardedHeaderFilter
, it will useRelativeRedirectResponseWrapper
to wrap the response. I our application, we calledsendRedirect()
to redirect to the home page when the user logged in. But we found that the server responds with a 404 status code and theLocation
response header.We found that the authentication filter didn't stop the filter chain when logged in, it continues, and the endpoint for handling the login process doesn't actually exist as we are using the filter to intercept the matched login request and perform the login process. So, in the later process, it couldn't find the handler and set the status code to 404. Thus this problem.
We called
sendRedirect()
insuccessHandler.onAuthenticationSuccess(request, response, authentication)
, and the filter continues after it.The filter we are using is
SpnegoAuthenticationProcessingFilter
from https://github.com/spring-projects/spring-security-kerberos/blob/0c9be90a7480edd48276a3703258258beeef59ff/spring-security-kerberos-web/src/main/java/org/springframework/security/kerberos/web/authentication/SpnegoAuthenticationProcessingFilter.java#L169-L175