Skip to content

fix: replace filesystem sessions with Flask signed-cookie sessions#70

Merged
fatherlinux merged 1 commit into
mainfrom
fix/remove-flask-session-filesystem
Apr 17, 2026
Merged

fix: replace filesystem sessions with Flask signed-cookie sessions#70
fatherlinux merged 1 commit into
mainfrom
fix/remove-flask-session-filesystem

Conversation

@fatherlinux
Copy link
Copy Markdown
Member

Summary

  • Removes flask-session and its filesystem-based session storage
  • Switches to Flask's built-in signed-cookie sessions
  • Fixes invalid_grant: Missing code verifier OAuth error caused by PKCE code_verifier being lost when /data/flask_session is unavailable

Why

SESSION_TYPE=filesystem required /data/flask_session to exist as a persistent volume. When missing (fresh deploy, local dev), the session silently failed — code_verifier came back None from the session on callback, and Google rejected the token exchange. Cookie sessions store auth state in the signed browser cookie, requiring zero filesystem access.

Test plan

  • Build succeeds (base image needs rebuild since requirements.txt changed)
  • OAuth login completes without invalid_grant error
  • Session persists across auth → callback redirect

🤖 Generated with Claude Code

Flask-Session with SESSION_TYPE=filesystem requires /data/flask_session
to exist and be persistent. When unavailable (fresh deploy, missing
volume mount, local dev), the code_verifier is silently lost between
/auth/google and /auth/callback, causing Google to reject the token
exchange with invalid_grant: Missing code verifier.

Signed-cookie sessions (Flask's built-in default) store auth state in
the browser cookie — no filesystem, no volume mounts, no PKCE failures.
Aligns with the constitution's no-persistent-volumes principle.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@fatherlinux fatherlinux merged commit e34e514 into main Apr 17, 2026
1 of 3 checks passed
@fatherlinux fatherlinux deleted the fix/remove-flask-session-filesystem branch April 17, 2026 00:42
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the flask-session dependency and transitions the application to Flask's built-in signed-cookie sessions, eliminating the need for filesystem-based session storage. The changes include removing the import, configuration keys, and initialization of flask-session in app.py, as well as updating requirements.txt. Feedback indicates that corresponding obsolete session configurations in tests/conftest.py should also be removed to maintain consistency and avoid dead configuration.

Comment thread app.py
app.config["SECRET_KEY"] = secret_key
app.config["SESSION_TYPE"] = "filesystem"
app.config["SESSION_FILE_DIR"] = "/data/flask_session"
# Only require HTTPS cookies in production (localhost uses HTTP)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The removal of SESSION_TYPE and SESSION_FILE_DIR is correct for the switch to cookie-based sessions. However, the test configuration in tests/conftest.py (lines 39-40) still contains these keys and attempts to set up a filesystem session directory. This will lead to dead configuration and potential confusion in the test suite. Please update the app fixture in tests/conftest.py to remove the obsolete session configuration.

References
  1. Maintainability: Adherence to language idioms and best practices, including removing dead configuration. (link)

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