oliver-zehentleitner / maity
hub: auth: one reader of a presented session cookie (the ASCII guard and the live-row lookup in one place)
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) androutes/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_sessionandemail_sign_in._anonymousalso repeat the same lookup: select the row byid_hash, thenended_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; andlive_session_row(conn, value)for the two that need the live row (_anonymousthen only compares the CSRF token).
Effort / risk: S. Low; test_auth_human.py covers the non-ASCII cases on each path.