-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Include FilterChain on SessionInformationExpiredEvent to allow continuing the request #14077
Comments
Hi, @arvyy, thanks for the report.
Can you elaborate more on your use case? How does the session expire? What are those requests that you always want to go through? |
I have a /currentUser endpoint that I want to work regardless if user is logged in or not (in latter case it'd return null). On frontend I create a timer until the end of the session (which I know from an auxiliary cookie). At the end of the timer, I call /currentUser, and if it weren't null (because user was browsing in different tab), I restart the timer. If it was null, I know user has been idle too long and change frontend view to the login screen. This is currently broken, because frontend instead of receiving a json response of an expected form, it instead receives a plain text message "This session has been expired ...". I understand that permitAll still invokes security filters, and that's desired, because I still want to be able to fetch (just potentially empty) security context's user authentication value. My problem isn't with design as a whole, but with inflexibility of ConcurrentSessionFilter specifically. |
It seems to me that your But, if you do not want to do that and instead return |
Doesn't seem like a robust solution. SessionInformationExpiredStrategy shouldn't be tight coupled to specific endpoint's concerns, especially since there can be more than one permitAll endpoint in an application (albeit the one I shared is the one most likely to trigger this issue). As a current workaround I'll probably reimplement the concurrent session filter altogether. |
As I mentioned before, a "robust" solution would be to return 401 since the user has provided some credentials (session id) but that session is not valid anymore, the filter is not aware of specific endpoint's concerns as well. |
I see, I thought you were commenting about my specific example solution.
As a default general case, a 401 isn't consistent with broader spring security behaviour. Usually calling into spring with a bad sessionid cookie will simply make spring treat you as an anonymous user: if a given endpoint is allowed to be accessed by anonymous users, the request will succeed with a 200, not killed with a 401 just because sessionid was bad. |
I have been thinking about this and it seems reasonable to include the static class ContinueRequestSessionInformationExpiredStrategy implements SessionInformationExpiredStrategy {
@Override
public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws ServletException, IOException {
event.getFilterChain().doFilter(event.getRequest(), event.getResponse());
}
} This way the That being said, this would be an enhancement in the behavior, therefore I'll schedule this for 6.3.0-M1. Would you be interested in submitting a PR? Ideally, the |
I wonder if, instead of saving the session with the status expired in the Lines 105 to 117 in 67d3e4c
|
Hello @marcusdacoregio may i handle this issue? please assign to me. i will make pr soon :) |
- continues to execute subsequent filters even after session expiration. - Issue spring-projects#14077
@marcusdacoregio
public ConcurrentSessionFilter(SessionRegistry sessionRegistry) {
Assert.notNull(sessionRegistry, "SessionRegistry required");
this.sessionRegistry = sessionRegistry;
this.sessionInformationExpiredStrategyArray = new SessionInformationExpiredStrategy[]{
new ResponseBodySessionInformationExpiredStrategy(),
new ContinueRequestSessionInformationExpiredStrategy()};
}
|
Sorry for dropping the ball; I was busy at the time, and managed to forget about it later on when I was free. Let me know if you need me |
- continues to execute subsequent filters even after session expiration. - Issue spring-projects#14077
- continues to execute subsequent filters even after session expiration. - Issue spring-projects#14077
- continues to execute subsequent filters even after session expiration. - Issue spring-projects#14077
I expect to always be able to invoke endpoints marked with permitAll. However, ConcurrentSessionFilter early aborts such requests at the edge of expiration.
spring-security/web/src/main/java/org/springframework/security/web/session/ConcurrentSessionFilter.java
Line 145 in ed6ff67
The text was updated successfully, but these errors were encountered: