Repository navigation
Tie sign-in sessions to an account generation - #2
Open
JacobStephens2 wants to merge 3 commits into
Open
JacobStephens2 wants to merge 3 commits into
JacobStephens2 wants to merge 3 commits into
Conversation
A sign-in session stays signed in only while it carries the account's session generation. Log out, a password saved from a reset or invite link, and an account password change advance that generation. The browser that changes its password stores the new generation; API tokens and account deletion stay as they are.
A session that no longer carries the account's generation stays signed out when the account record is deleted or the account file cannot be read. The generation reached on log out or a password save is remembered beside the account, and creating an account returns that memory to the start.
A top-level cross-site GET still sends the SameSite=Lax session cookie, and the CSRF check covers only POST. Logout was advancing the account generation on GET, which signed out every other browser. The nav control now posts the CSRF token, and a GET clears only the cookie that followed the link.
Owner
Author
|
Delivery completed on agent-authored or reviewed head 8f4d007. |
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.
Summary
Creating an account returns its remembered generation to the start, so a reused email does not keep a previous one.
Seams under test:
POST /login,GET /account)POST /logoutwith the CSRF token; a GET does not advance the generation)POST /reset/<token>)POST /account)POST /api/v1/token,GET /api/v1/me), unchangedPOST /admin/delete): a session that still carries the generation stays signed in, and a session that already failed that check is not signed in againCloses #1
Evidence
Execution evidence
.venv/bin/python -m unittest tests.test_session_generation.SessionGenerationTests.test_sign_in_is_accepted_only_while_the_session_carries_the_account_generation -vAfter: same command
.venv/bin/python -m unittest tests.test_session_generation.SessionGenerationTests.test_deleting_an_account_must_not_revive_a_session_logout_already_rejected tests.test_session_generation.SessionGenerationTests.test_unreadable_users_file_must_not_accept_a_mismatched_generation -vAfter: same command
The full module,
.venv/bin/python -m unittest tests.test_session_generation -q, finishedRan 15 tests in 13.163sandOK.Visual evidence
The nav log out control is a POST form instead of a link. There are no before/after captures. The test client checked the signed-in page: it includes the logout form and its CSRF token, and posting that token signs out the other sessions.
Merge Danger
Door: two-way
Reverting the deploy restores the previous session check. Account records may keep a
session_generationfield, andsession_generations.jsonmay keep the remembered generations; the previous code ignores both. On deploy, a browser whose cookie does not yet carry a generation is signed out until the next sign-in.Blast Radius: sessions
Log out, a reset or invite password save, and an account password change sign out every other browser for that account. The browser that changes its password stays signed in. API tokens stay valid. Deleting an account still leaves a matching browser session and its API token in place.
Unaddressed findings
Standards
None.
Spec
None. The one Spec finding was fixed and its tests kept. A session that log out had already rejected was signed in again after the account was deleted (
AssertionError: 200 == 200), and a mismatched generation was signed in again whenusers.jsoncould not be read (same failure). Both tests now pass, as in the second execution pair above.Security
None. A cross-site GET
/logoutadvanced the account generation and signed out every other session (AssertionError: 302 != 200fromtests.test_session_generation.SessionGenerationTests.test_a_cross_site_get_logout_does_not_sign_out_other_sessions). The session cookie isSameSite=Lax, so a top-level cross-site navigation still sends it, and the CSRF check applies only to POST. Logout now advances the generation only for a POST that carries the CSRF token, which is what the nav control sends. That test passes.Security review outcome
Review coverage
No changed file was left unread. Standards and Spec both read
app.pyandtests/test_session_generation.py.Built with grok grok 1.0.70 (f50904eaee6c) [stable] · default model · default effort