Describe the bug
In the user login stage inside the authentication flow, a user may randomly be unable to log in, receiving an error message, “Flow does not apply to current user,” or encountering other similar issues. We discovered a race condition between frontend requests arriving at the backend that may cause this issue.
To Reproduce
Steps to reproduce the behavior:
- Create an authentication source (e.g., Social Login via OIDC) and enable it, which corresponds to the
default-source-authentication flow while authenticating.
- Try to log in via this source multiple times or use tools to slow down requests to
/api/v3/flows/executor/default-source-authentication/.
- You will be declined by the flow, showing an error message indicating permission denied.
Expected behavior
Users should be able to log in normally.
Screenshots
-
Branding request responds with a delete cookie header:

-
API request after it will have NO session cookie, causing authentication invalidation:

Version and Deployment (please complete the following information):
- authentik version: 2024.8.3
- Deployment: docker-compose
Additional context
After debugging, we found the following condition may trigger this issue:
- Django cycles
session_key once the user logs in, which purges the old session_key in cache storage.
- Requests sent earlier arrive at the server later with an old session token with a cycled
sid, causing the cache storage to not find the corresponding sid.
- The server finds the session cookie exists but is not valid since the corresponding key is purged; it returns a
delete_cookie header which removes the session cookie.
- Once the request above arrives, the user session will be logged out immediately, even if they have completed the user login stage, which fails the subsequent request to
/api/v3/flows/executor/default-source-authentication/.
References:
Currently, the workaround for this issue is under exploration.
Describe the bug
In the user login stage inside the authentication flow, a user may randomly be unable to log in, receiving an error message, “Flow does not apply to current user,” or encountering other similar issues. We discovered a race condition between frontend requests arriving at the backend that may cause this issue.
To Reproduce
Steps to reproduce the behavior:
default-source-authenticationflow while authenticating./api/v3/flows/executor/default-source-authentication/.Expected behavior
Users should be able to log in normally.
Screenshots
Branding request responds with a delete cookie header:
API request after it will have NO session cookie, causing authentication invalidation:
Version and Deployment (please complete the following information):
Additional context
After debugging, we found the following condition may trigger this issue:
session_keyonce the user logs in, which purges the oldsession_keyin cache storage.sid, causing the cache storage to not find the correspondingsid.delete_cookieheader which removes the session cookie./api/v3/flows/executor/default-source-authentication/.References:
authentik/authentik/root/middleware.py
Lines 84 to 91 in 0804179
authentik/authentik/stages/user_login/stage.py
Lines 97 to 102 in 0804179
Currently, the workaround for this issue is under exploration.