Skip to content

Read the session key from the SESSION_KEY environment variable - #480

Merged
Mariatta merged 4 commits into
mainfrom
session-key-from-env
Oct 26, 2026
Merged

Mariatta merged 4 commits into
mainfrom
session-key-from-env

Conversation

@Mariatta

Copy link
Copy Markdown
Member

The Fernet key that encrypts the session cookie was generated fresh on every start, so each deploy or restart signed everyone out. On Heroku with rare deploys that was tolerable; on cabotage, where deploys are more frequent, it is not.

The key now comes from the SESSION_KEY environment variable, set in the cabotage UI alongside the other secrets. When it is missing, the app still generates a random key so local development keeps working with no setup, and it logs a warning.

EncryptedCookieStorage accepts the key as a str and passes it straight to Fernet, so the base64 round-trip in the old startup block is gone. The loading logic lives in get_session_key() so it can be tested; the two new tests cover both branches, including that the random fallback is a valid Fernet key.

Also documents SESSION_KEY in the readme, with the one-liner that generates it.

The production SESSION_KEY is already set on cabotage, so the first deploy after this merges signs everyone out one last time and every deploy after that keeps sessions.

The Fernet key that encrypts the session cookie was generated fresh on
every start, so each deploy or restart signed everyone out. The key now
comes from SESSION_KEY, set in the cabotage UI like the other secrets.
When it is missing, the app still generates a random key, which keeps
local development working, and logs a warning.
A malformed value used to fail inside EncryptedCookieStorage with a
message that did not say which variable was wrong. Also tightens the
readme wording and drops an import the tests no longer need.
The generate command now lives in its own readme section under Deploy.
The startup error and the missing-key warning just say what is wrong
and refer to that section.
Without this the tests stayed green when the pointer was removed.
@Mariatta
Mariatta merged commit ca62751 into main Oct 26, 2026
11 checks passed
@Mariatta
Mariatta deleted the session-key-from-env branch October 26, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant