Skip to content

Session lineage: stamp and measure the supersession window on the store's own clock (ASVS 7.2.4, BACKLOG #4276) - #3259

Open
wshallwshall wants to merge 3 commits into
mainfrom
b684-4276-lineage-clock
Open

wshallwshall wants to merge 3 commits into
mainfrom
b684-4276-lineage-clock

Conversation

@wshallwshall

Copy link
Copy Markdown
Collaborator

Merge danger

Reversible: yes -- reverting the squash on main restores wall-clock stamping of the session lineage. No schema migration: the change is in the SQL each backend issues, not in the table shape.

Blast radius: session rotation, supersession, sign-out and the lineage purge, on all three stores (messagefoundry/store/store.py, postgres.py, sqlserver.py, base.py, session_lineage.py); messagefoundry/auth/service.py; the POST /auth/logout proven_at contract (api/app.py, api/auth_routes.py, now monotonic, and a wall-clock value raises); the web console logout test; docs/SECURITY.md; ADR 0210 Amendment B and its index row.

Evidence

  • Before: at origin/main 353b2183fe2, rotate_session stamped retired_at with the engine's time.time(), and the lineage walk compared that stamp with the signing-in process's own before - window. An engine-host clock step, or skew between engine hosts, could drop a link inside the window.
  • After: new forward-step tests in tests/test_session_supersession_lineage.py and tests/test_session_supersession.py; control: they fail on main's code. Targeted pytest (lineage, supersession, webauthn contract on SQLite, placeholders, pool, api_auth, auth_before_body, web console logout): 244, then 220 passed on the final head. mypy all four legs clean.

Batch 684, BACKLOG #4276 (Builder E2)

Source branch b684-4276-lineage-clock, head 2d785e2ba455ed225a08e199a8c7024b6a1ea1cf. Its own PR because it changes a security control.

What changed. Every backend stamps retired_at from the database's own clock in the link INSERT: SQLite julianday('now'), PostgreSQL statement_timestamp(), SQL Server SYSUTCDATETIME(). The lineage read and the purge measure the window length, lineage_seconds, back from that same clock. Store waits are added back on the monotonic clock, and the reaper purges at the window plus its step tolerance.

What it does, and does not, do (as docs/SECURITY.md now states):

  • On PostgreSQL and SQL Server, an engine-host clock step and skew between engine hosts no longer drop a link.
  • On SQLite the store's clock is the engine host's clock, so a host clock step still moves the bound there.
  • New on server stores: a database-clock forward step larger than 600 s lets a purge delete links still inside the window.

Files beyond the brief's list (the protocol change and the docs needed them): store/base.py, store/session_lineage.py, api/app.py, api/auth_routes.py, docs/SECURITY.md, ADR 0210 Amendment B, the ADR index row, tests/test_api_auth.py, and the web console logout test.

Interaction: batch 684's PR 3255 (BACKLOG #4846) also edits messagefoundry/auth/service.py. git merge-tree of the two heads exits 0; whichever lands second may still need a branch update.

Open question for the owner, not decided here: whether the SQLite host-clock-step case is a deployment requirement (host clock discipline, BACKLOG #2350) rather than something this code must close.

Checks run: ruff check and ruff format --check clean; mypy in the four CI legs clean; targeted pytest as above.

Not run: the PostgreSQL and SQL Server contract (test_session_lineage_contract), which is hosted-only: read the postgres and sqlserver legs. The full suite. /simplify.

Review: code-review skill at xhigh, Rounds: 2 + 1 unrepaired. The QA line and the 12 unrepaired findings are in a comment below.

ASVS 7.2.4 arm (ii). A link's retired_at was the elevating process's
time.time() and the window was measured from the signing-in process's,
so a forward step of the signing-in clock, or skew between engine
hosts, dropped a link inside the real window and left the rotated
session live.

Every backend now stamps retired_at from the database clock in the
link INSERT, and the lineage read and the reaper purge measure the
window back from that same clock (SQLite julianday('now'), Postgres
statement_timestamp(), SQL Server SYSUTCDATETIME()). The store API
takes a window length (lineage_seconds) instead of an instant
(lineage_since); rotate_session takes no now. The sign-out asks for
its 5 s plus the time since its proof.

Residual, stated in SECURITY.md and ADR 0210 Amendment B: a step of
the store's own clock still moves the window (on SQLite, the clock of
the host holding the file).

Tests: a 425 s-class forward step of the signing-in process no longer
drops a link (SQLite, service and logout); the store contract now
checks the window and purge ignore the caller's now on all three
backends; tests that aged a link by patching time.time now age it in
the store.

BACKLOG #4276
Review round 1 of the store-clock change.

- The walk adds back, on the monotonic clock, the time a store call
  spent waiting before each lookup, so a lock, connection or row-lock
  wait no longer shortens the window the caller asked for.
- POST /auth/logout reads proven_at on the monotonic clock, and the
  sign-out measures the time since it on the same clock.
- The reaper asks the purge for the window plus its step tolerance,
  restoring the margin the store-clock purge had dropped.
- SECURITY.md, ADR 0210 Amendment B and the docstrings no longer
  claim an engine clock step is closed on SQLite: there the store's
  clock is the engine host's.
- The store contract now places one window between two real link ages
  on every backend; the SQLite aging helper moved beside it.

BACKLOG #4276
…ll-clock proof time

Review round 2.

- SECURITY.md names the new residual: on a server store, a forward
  step of the database clock larger than the reaper's step tolerance
  lets a purge delete links still inside the bound.
- logout refuses a proven_at ahead of the monotonic clock, the shape
  of a wall-clock reading, rather than silently narrowing the window.
- supersession_lineage_seconds says the purge keeps links for the
  window plus the step tolerance.
- The SQLite aging helper takes the store's writer lock; the positive
  /ui/logout test keeps a 4 s margin; the store docstrings point to
  store/session_lineage.py instead of restating the residual; the
  redundant float() coercions are gone.

BACKLOG #4276
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

QA (Builder E2, BACKLOG #4276): code-review xhigh, Rounds: 2 + 1 unrepaired, Tag: "xhigh effort -> 10 inline angles -> dedup (no verify) -> sweep -> <=15 findings" (review_tag.py exit 0, round-68bb0bff; rounds 959cf298, f58b65fa same tag)

Unrepaired round-3 findings, none fixed, as the Builder reported them:

  1. The database-clock purge is unguarded on server stores. Suggested fix: a guard on the store clock's own delta.
  2. Some service comments still read "no clock step moves the window", which is false on SQLite. The Builder flags this as a false control claim in a comment.
  3. The contract's purge window has about 1 s of margin and could flake on loaded PostgreSQL or SQL Server runners.
  4. Monotonic does not count VM pause or suspend, so the window can narrow.
  5. ADR 0210 Amendment B's "What stays" list omits the purge residual.
  6. PHI.md and ADR 0210 Decision 4 still give the purge age as the bare window.
  7. A stale or zero monotonic proven_at widens the window without error.
  8. The lineage SQL now exists in three copies.
  9. The anchor sum is done in two layers.
  10. In test_api_auth, the fake tick could run ahead of the real monotonic clock.
  11. The aging helper bypasses _writer_guard.
  12. The contract now sleeps 2 s on every leg.

@wshallwshall wshallwshall added the qa Builder QA record posted; not a merge gate label Nov 24, 2026
@wshallwshall

Copy link
Copy Markdown
Collaborator Author

Lander hand-over (Manager aebf32, batch 684)

Field Value
Pull request MEFORORG/MessageFoundry 3259
Head SHA 2d785e2
Unread legs Every hosted CI leg. Locally not run: the PostgreSQL and SQL Server legs (test_session_lineage_contract, hosted-only) and the full suite.
Known defects The 12 unrepaired round-3 findings, verbatim in the QA comment above. Finding 2 is a false statement in a code comment about what a control does ("no clock step moves the window", false on SQLite); it is yours to classify under 4a-quinquies.
Landing-order constraint none required. PR 3255 (#4846) also edits messagefoundry/auth/service.py; git merge-tree of the two heads exits 0.

Ledger ask after merge: banner for #4276. The Builder's text is carried with only the requirement-number and arm labels removed, because this is a public place:
Engine PR 3259: each backend stamps session_lineage.retired_at and measures the supersession, sign-out and purge windows on the database's own clock. Store waits are added back on the monotonic clock, proven_at is monotonic, and the purge keeps links for the window plus the reaper's step tolerance. On PostgreSQL and SQL Server an engine-host clock step or engine-host skew no longer drops a link. On SQLite the store clock is the host clock, so a host step still moves the bound; that needs option (b) or (c). New on server stores: a DB-clock forward step over 600 s can purge links still in the window. Steps 2 and 3 (IDE races, vault re-score) remain for a vault Builder.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa Builder QA record posted; not a merge gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant