-
Notifications
You must be signed in to change notification settings - Fork 6k
Throw exception if URL does not include context path when context relative #8399
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
Throw exception if URL does not include context path when context relative #8399
Conversation
Thanks for the report @yoshikawaa. Could you explain how you arrived at this behaviour? It would be very helpful if you produce a minimal sample that demonstrates the issue. |
Dear. @eleftherias
Please check sample application.
When a URL that does not contains the context path is specified, I expected to redirect always to the context root. ... However, if it is determined that |
Thank you for the sample @yoshikawaa. While this sample demonstrates the issue, I am not able to see the cause of it, due to the multitude of dependencies that seem to hide the configuration. Please modify the sample to confirm to these minimal sample guidelines. Here are a few key things that are troubling about the sample in its current state:
|
@eleftherias |
Thank you for the updated sample @yoshikawaa. This scenario occurs when there is a disconnect between what the application is expecting to receive (context relative URL) and what it is actually given (not context relative URL). When looking at gh-4142, I was hesitant to throw an exception in this case, but now I think that may be the best response. This situation happens what a developer does something unexpected, not a user, so it may be best to warn the developer that they are doing something that the application is not expecting. What do you think about throwing an exception in this case, rather than redirecting to the root context path? |
@eleftherias Based on this, I will fix this pull request. |
76ac2d4
to
adf1901
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @yoshikawaa!
All of the code looks good.
My one note is to format your commit message to follow our conventions https://github.com/spring-projects/spring-security/blob/master/CONTRIBUTING.adoc#format-commit-messages.
Here is a suggestion, but feel free to update it as you see fit
Throw exception if context path not in redirect
Issue: gh-8399
adf1901
to
94d36ee
Compare
@eleftherias |
Thanks for the PR @yoshikawaa! I am curious if we have the same issue one the reactive side. |
Sorry for the late response, @eleftherias . When using Lines 56 to 66 in 28d2cfa
The DefaultServerRedirectStrategy#createLocation method does not perform the process of calculating the redirect destination URL by removing the scheme and context path from the URL.As a result, It will be response.getHeaders().setLocation("") only when the developer intentionally sets the empty redirect URL (eg URI.create("") ).
Since behavior when intentionally specifying an empty URL is as requested by the developer and it is not a trouble of Spring Security, I think that it is no need to fix this. Regards. |
Thank you for looking into that @yoshikawaa. |
Versions
Problem
#4142
DefaultRedirectStrategy
send redirect to""
if redirect argumenturl
not contains application context path.But on Tomcat, it may not redirect to the context root as intended.
When
HttpServletResponse#sendRedirect("")
, Tomcat response with empty Location header.If the request url is
/context-root/login
and response empty Location header:/context-root/login
/context-root/login
/context-root
https://javaee.github.io/javaee-spec/javadocs/javax/servlet/http/HttpServletResponse.html#sendRedirect-java.lang.String-
It seems to be the case in the latter case.
Note:
On Weblogic,
""
is converted to the context path and set in the Location header.Solution
Change to send redirect to explicitly specifying the context path.
HttpServletResponse#sendRedirect("")
->
HttpServletResponse#sendRedirect(contextPath)