oliver-zehentleitner / maity

hub: one live-session SQL clause (caller, sessions, notifications/presence); a non-ASCII session cookie answers 401, not 500

Sign in to report

tsk-76rpp9qt2xvc Done Maity Coder Claude 003

Audit round 3b (tsk-hgnbapyw7hnh), read at 80fef076. Kind: duplication / robustness.

What is wrong

  • "not ended, expires_at > now, last_seen_at > now - SESSION_IDLE - SEEN_EVERY" is hand-written three times: hub/src/maity_hub/auth/caller.py:257-260, auth/sessions.py:229-232 (negated), notifications/presence.py:53-56; all must move with the Python session_alive (caller.py:357-362).
  • _cookie hashes facts.cookies[SESSION_COOKIE] (caller.py:239) with session_id_hash, which encodes ASCII (:175). Starlette decodes the cookie header as latin-1, so a non-ASCII maity_session raises UnicodeEncodeError and the call answers 500 instead of 401. has_live_session (:346) guards with isascii(), but precheck runs only for large-body routes (middleware.py:268-280); ordinary routes reach _cookie unguarded. Commit d2131073 noted this and left it out.

Proposal

  • caller.live_session_clause(now) used in all three places.
  • _cookie refuses a non-ASCII value with unauthenticated, like has_live_session; add a test.

Effort / risk: S. Low.

Notes

  1. Maity Test Team · Nov 20, 2026, 20:04 UTC

    Tester result (mmza): pass. Build: local hub from main at 19dc7ecbfa836f45b5332b842c35f75b2d39cef0 (contains d75b07ee / #2040), SQLite, freshly migrated (head 20261120090000_fresh_session), on 127.0.0.1. Prod reports 0.1.0a10, so the change is not deployed there. No prod contact.

    The probes use curl with a raw latin-1 byte in the cookie (Cookie: maity_session=\xe4); with ASCII abc as the control:

    • GET /api/v1/me: 401 unauthenticated "the session has ended or expired" (same for \xe4\xf6abc and for UTF-8 \xc3\xa4; the ASCII control gives the same)
    • POST /api/v1/auth/logout: 401 unauthenticated "the session has ended or expired"
    • POST /api/v1/auth/login with wrong credentials (end_presented path): 401 "address or password is wrong", identical to the ASCII control
    • POST /api/v1/auth/email-link (_anonymous path): 202 {"expires_in":900}, identical to the ASCII control

    No 500 status and no traceback or UnicodeEncodeError in the server log.
    Not exercised: email-code (my request body did not validate), device code, the registration page, and the large-body precheck routes.