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
When an application has a firewall that includes both routes with stateless: true and routes that use the session, the routes with stateless: true will remove the session data and session cookie. This means that the user has to reauthenticate if they visit a route that uses the session after visiting a route with stateless: true.
I think the stateless routes should simply ignore the session data and should not actively remove an existing session.
How to reproduce
Create two routes, one with stateless: true and one without.
Visit the route that uses the session and stores the user in the session.
Visit the route with stateless: true. This route will remove the user in the session and delete the session cookie.
Possible Solution
The problem is that the ContextListener removes the session data in the kernel.response event:
if (!$this->trustResolver->isAuthenticated($token)) {
if ($request->hasPreviousSession()) {
$session->remove($this->sessionKey);
}
} else {
The first if statement will always be true, as the token is always null and therefore the user is not authenticated. $request->hasPreviousSession() will also be true if the user has a session cookie from the previous request.
ContextListener::onKernelResponse should probably also check if the request is stateless and return early when this is the case. This event listener either stores the token in the session or removes the session data, neither of which should be actions for stateless requests.
Symfony version(s) affected
6.4.9
Description
When an application has a firewall that includes both routes with
stateless: true
and routes that use the session, the routes withstateless: true
will remove the session data and session cookie. This means that the user has to reauthenticate if they visit a route that uses the session after visiting a route withstateless: true
.I think the stateless routes should simply ignore the session data and should not actively remove an existing session.
How to reproduce
stateless: true
and one without.stateless: true
. This route will remove the user in the session and delete the session cookie.Possible Solution
The problem is that the
ContextListener
removes the session data in thekernel.response
event:symfony/src/Symfony/Component/Security/Http/Firewall/ContextListener.php
Lines 169 to 173 in 3804b46
The first if statement will always be true, as the token is always null and therefore the user is not authenticated.
$request->hasPreviousSession()
will also be true if the user has a session cookie from the previous request.ContextListener::onKernelResponse
should probably also check if the request is stateless and return early when this is the case. This event listener either stores the token in the session or removes the session data, neither of which should be actions for stateless requests.Additional Context
This bug was introduced in #57372
The text was updated successfully, but these errors were encountered: