oliver-zehentleitner / maity

hub: auth: one reader of a presented session cookie (the ASCII guard and the live-row lookup in one place)

Sign in to report

tsk-ftmhm1b15nek Proposed

Audit round 4 (tsk-hgnbapyw7hnh), read at 0a1b832e. Kind: duplication.

What is wrong

  • #2040 made a non-ASCII cookie name no session. The guard is now written at each caller of session_id_hash (auth/caller.py:174, which encodes ASCII only) instead of once: caller._cookie (auth/caller.py:239-242), caller.has_live_session (auth/caller.py:346-349), routes/auth.end_presented (routes/auth.py:215-217) and routes/email_sign_in._anonymous (routes/email_sign_in.py:63-67). A fifth reader of a presented value would have to remember it.
  • has_live_session and email_sign_in._anonymous also repeat the same lookup: select the row by id_hash, then ended_at is None and session_alive(row, now) (auth/caller.py:348-352, routes/email_sign_in.py:65-70).

Proposal

  • One helper in auth/caller.py, e.g. presented_hash(value) -> str | None (None for empty or non-ASCII), used by all four callers; and live_session_row(conn, value) for the two that need the live row (_anonymous then only compares the CSRF token).

Effort / risk: S. Low; test_auth_human.py covers the non-ASCII cases on each path.