fix: use persistent runtime ID for session cookie name#1771
Open
gdeyoung wants to merge 1 commit into
Open
Conversation
Use get_persistent_id() instead of get_runtime_id() for SESSION_COOKIE_NAME to prevent session cookie invalidation on process/container restarts. get_runtime_id() generates a new random secrets.token_hex(8) on every process start, changing the cookie name and orphaning browser sessions. get_persistent_id() reads A0_PERSISTENT_RUNTIME_ID from .env, which survives restarts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: Session cookies invalidated on every process/container restart
Problem
SESSION_COOKIE_NAMEinhelpers/ui_server.pyusesruntime.get_runtime_id(), which generates a new random value (secrets.token_hex(8)) on every process start. This means the cookie name changes on every restart, orphaning the browser's existing session cookie and forcing re-login.This is separate from the
FLASK_SECRET_KEYpersistence (which was already addressed) — even with a stable secret key, the cookie name rotation breaks sessions.Impact
Affects every Docker deployment. Users are forced to re-login after any container restart, supervisor process restart, or self-update.
Fix
Use
runtime.get_persistent_id()instead, which readsA0_PERSISTENT_RUNTIME_IDfrom.env(generating and persisting it on first use). This function already exists inhelpers/runtime.pyand is designed exactly for this purpose — it's already used for CSRF token cookie names and other stable identifiers.Change
One line in
helpers/ui_server.py:Testing
Verified across a 4-container deployment. After applying the fix:
supervisorctl restart run_ui)A0_PERSISTENT_RUNTIME_ID