Skip to content

Tie sign-in sessions to an account generation - #2

Open
JacobStephens2 wants to merge 3 commits into
mainfrom
issue-1
Open

JacobStephens2 wants to merge 3 commits into
mainfrom
issue-1

Conversation

@JacobStephens2

@JacobStephens2 JacobStephens2 commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

on each request
  if the session names no account
    signed out
  if the account file cannot be read
    signed out
  generation = the account's generation
               or, when that record was deleted, the generation remembered for it
               (an account with none yet is at the start, 0)
  signed in only when the session carries that generation

on log out
on a password saved from a reset or invite link
on an account password change
  advance the account's generation and remember it
on an account password change
  store the new generation in this browser's session too

Creating an account returns its remembered generation to the start, so a reused email does not keep a previous one.

Seams under test:

  • Sign-in and the signed-in check (POST /login, GET /account)
  • Log out (POST /logout with the CSRF token; a GET does not advance the generation)
  • Password saved from a reset or invite link (POST /reset/<token>)
  • Account password change (POST /account)
  • API tokens (POST /api/v1/token, GET /api/v1/me), unchanged
  • Account deletion (POST /admin/delete): a session that still carries the generation stays signed in, and a session that already failed that check is not signed in again

Closes #1

Evidence

Execution evidence

  • Before: .venv/bin/python -m unittest tests.test_session_generation.SessionGenerationTests.test_sign_in_is_accepted_only_while_the_session_carries_the_account_generation -v
AssertionError: None != 2
Ran 1 test in 0.392s
FAILED (failures=1)

After: same command

ok
Ran 1 test in 0.421s
OK
  • Before: .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 -v
AssertionError: 200 == 200
AssertionError: 200 == 200
Ran 2 tests in 1.072s
FAILED (failures=2)

After: same command

ok
ok
Ran 2 tests in 1.134s
OK

The full module, .venv/bin/python -m unittest tests.test_session_generation -q, finished Ran 15 tests in 13.163s and OK.

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_generation field, and session_generations.json may 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 when users.json could not be read (same failure). Both tests now pass, as in the second execution pair above.

Security

None. A cross-site GET /logout advanced the account generation and signed out every other session (AssertionError: 302 != 200 from tests.test_session_generation.SessionGenerationTests.test_a_cross_site_get_logout_does_not_sign_out_other_sessions). The session cookie is SameSite=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

  • Security review incomplete: session failed, ended early or omitted a valid final line; see Session trace

Review coverage

No changed file was left unread. Standards and Spec both read app.py and tests/test_session_generation.py.

Built with grok grok 1.0.70 (f50904eaee6c) [stable] · default model · default effort

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.
@JacobStephens2

Copy link
Copy Markdown
Owner Author

Delivery completed on agent-authored or reviewed head 8f4d007.

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.

Tie sign-in sessions to an account generation

1 participant