Skip to content

Compare session and user identifiers consistently when resetting a password - #72198

Merged
potiuk merged 1 commit into
apache:mainfrom
potiuk:fix-fab-reset-session-invalidation
Aug 28, 2026
Merged

Compare session and user identifiers consistently when resetting a password#72198
potiuk merged 1 commit into
apache:mainfrom
potiuk:fix-fab-reset-session-invalidation

Conversation

@potiuk

@potiuk potiuk commented Aug 28, 2026

Copy link
Copy Markdown
Member

reset_user_sessions() decodes each stored session and compares its _user_id against user.id:

if session_details.get("_user_id") == user.id:

Flask-Login stores whatever User.get_id() returns — a string (models/__init__.py:357) — while user.id is the integer column. The comparison is therefore "1" == 1, which is never true, so no session is ever deleted and the password update proceeds independently. With [fab] session_backend=database, provider.yaml documents that a password reset deletes all sessions for that user; it deletes none.

Both sides are now compared as strings, and a row carrying no _user_id is skipped rather than matched.

On the test. test_reset_user_sessions_delete passed throughout, because its fixture wrote an integer _user_id into the session row by hand — exercising a comparison that cannot occur in practice. It now stores what get_id() returns. Reverting the source change makes all three parametrisations fail (assert 2 == 1), which they did not before. Added coverage for sessions written before get_id() returned a string, and for a row with no _user_id.

Local: 28 passed in the touched file, 460 across the provider; ruff and mypy clean.

🤖 Generated with Claude Code

@potiuk
potiuk force-pushed the fix-fab-reset-session-invalidation branch from 6c81d1d to 7ffd0e3 Compare August 28, 2026 14:34
…ssword

reset_user_sessions() decoded each stored session and compared its _user_id
against user.id directly. Flask-Login stores whatever User.get_id() returns,
which is a string, while user.id is the integer column, so the comparison was
never true and no session was ever deleted. Both sides are now compared as
strings, and a session row without a _user_id is skipped rather than matched.

The existing test passed because its fixture wrote an integer _user_id into
the session row by hand, exercising a comparison that does not occur in
practice. It now stores what get_id() returns. Added coverage for sessions
written before get_id() returned a string, and for a row carrying no
_user_id at all.
@potiuk
potiuk force-pushed the fix-fab-reset-session-invalidation branch from 7ffd0e3 to e83ed55 Compare August 28, 2026 20:06
@potiuk
potiuk merged commit ff601cb into apache:main Aug 28, 2026
79 checks passed
@potiuk
potiuk deleted the fix-fab-reset-session-invalidation branch August 28, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants