Skip to content
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

RequestedUrlRedirectInvalidSessionStrategy can cause the HTTP method to change depending on the user agent #12797

Closed
mches opened this issue Feb 28, 2023 · 0 comments · Fixed by #12817
Assignees
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Milestone

Comments

@mches
Copy link
Contributor

mches commented Feb 28, 2023

Describe the bug
RequestedUrlRedirectInvalidSessionStrategy#onInvalidSessionDetected(…) uses DefaultRedirectStrategy#sendRedirect(…), which delegates to HttpServletResponse#sendRedirect(…) which always sets HTTP status 302 Found regardless of the HTTP method of the original request. I've observed this can cause the HTTP method to change from POST to GET depending on the user agent, as described in MDN documentation. The same documentation recommends to redirect with HTTP status 307 Temporary Redirect for HTTP methods other than GET and HEAD to prevent the user agent from changing the method.

Even if the specification requires the method (and the body) not to be altered when the redirection is performed, not all user-agents conform here - you can still find this type of bugged software out there. It is therefore recommended to set the 302 code only as a response for GET or HEAD methods and to use 307 Temporary Redirect instead, as the method change is explicitly prohibited in that case.

To Reproduce
Set an instance of RequestedUrlRedirectInvalidSessionStrategy as the invalid session strategy in the security filter chain. Make a POST request with an invalid session ID with Chrome browser. Observe a method not supported error due to Chrome using the GET method where only POST is allowed.

Expected behavior
The POST request with an invalid session ID should be redirected with HTTP status 307 Temporary Redirect. Chrome will be prohibited from changing the HTTP method.

Sample

5.7.x...mches:spring-security:gh-12797

@mches mches added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Feb 28, 2023
@mches mches changed the title DefaultRedirectStrategy#sendRedirect(…) can cause the HTTP method to change depending on the user agent RequestedUrlRedirectInvalidSessionStrategy can cause the HTTP method to change depending on the user agent Mar 2, 2023
jzheaux pushed a commit that referenced this issue Oct 16, 2023
@jzheaux jzheaux self-assigned this Oct 16, 2023
@jzheaux jzheaux added in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Oct 16, 2023
@jzheaux jzheaux added this to the 6.2.0-RC2 milestone Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants