You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Request is saved in the Session. Note that queryString is originalParam=value
Authentication happens
A redirect to the saved request is performed. org.springframework.security.web.savedrequest.DefaultSavedRequest.getRedirectUrl() will append the matchingRequestParameterName to the query string. This is expected, as it is used to check if we need to access the session or not. This means the Redirect to the Browser looks something like this: https://myapp.com?originalParam=value&continue
In org.springframework.security.web.savedrequest.HttpSessionRequestCache.getMatchingRequest() the SavedRequest is compared to the Request from the Browser. This check involves comparing the queryString of the SavedRequest and the HttpServletRequest.
The SavedRequest has the queryString originalParam=value and HttpServletRequest.getQueryString() will return originalParam=value&continue
So the comparison fails, and the SavedRequest is not used.
To Reproduce
Perform a request to the application that has a query string
Authenticate
Now the SavedRequest should match, but it does not.
Expected behavior
The request should match, and the saved request should be picked up by the application.
It assumes, that the queryString of both requests is null. But in fact, when the success Parameter is available, also the queryString will be populated by the Servlet Engine.
Edit: Fixed a typo in the last code example. request.setQueryString("param=true&success") should have been requestToMatch.setQueryString("param=true&success");
The text was updated successfully, but these errors were encountered:
@jzheaux thanks for the confirmation. One last question. You assigned the ticket to the 5.8.2 milestone. Does this mean it will be also ported to the 6.0.2 Releae? Because this bug also affects the 6.0.1 Version.
furti
added a commit
to porscheinformatik/pnet-idp-client
that referenced
this issue
Feb 14, 2023
When the matchingRequestParameterName is set in the request cache.
A optimization is performed that prevents accessing the session on every
request.
Unfortunately this introduces a bug, where the saved request is not used
anymore, when we redirect to it.
When a fix for spring-projects/spring-security#12665
is available, we can remove the workaround.
Describe the bug
Some time ago, the following commit 28c0d14 introduced the matchingRequestParameterName parameter for the
HttpSessionRequestCache
.After upgrading my application to Spring Boot 3 and Spring Security 6, the saved request is not used anymore.
The problem is, that when the Parameter is set:
The SavedRequest has the queryString
originalParam=value
and HttpServletRequest.getQueryString() will returnoriginalParam=value&continue
So the comparison fails, and the SavedRequest is not used.
To Reproduce
Expected behavior
The request should match, and the saved request should be picked up by the application.
Sample
I have no sample yet. But maybe you can confirm the bug without a sample. What I found is, that the Unit Test introduced with the above mentioned commit might be a bit misleading. https://github.com/spring-projects/spring-security/blob/main/web/src/test/java/org/springframework/security/web/savedrequest/HttpSessionRequestCacheTests.java#L111
It assumes, that the queryString of both requests is null. But in fact, when the success Parameter is available, also the queryString will be populated by the Servlet Engine.
If I modify the test, and ensure that both Requests have a query string, the test fails.
Edit: Fixed a typo in the last code example.
request.setQueryString("param=true&success")
should have beenrequestToMatch.setQueryString("param=true&success");
The text was updated successfully, but these errors were encountered: