Sessions plus Basic auth parsing
- Status: SHIPPED in C++ port
- Spec: SEC-07, FR-04, FR-05, FR-09
- Sources:
tosv.cppsess plus b64d plus handle,archive/tosv.pylegacy Flask sessions, SPEC.md 6.2
What it is
Humans get cookie sessions (tosv=s_<16 hex>, HttpOnly, Path=/),
machines get Basic auth per request. Both gates deny on anything
unexpected: missing cookie 302s to login, bad Basic gets denied,
unknown base64 chars are skipped into a mismatch, never an error
oracle.
How TOSV does it
Login mints s_ plus 16 hex chars into a mutex-guarded map;
handle parses the Cookie header by substring search. Basic paths
find Authorization: Basic, slice to end of line, run a table
decoder that ignores unknown chars, and compare the full
user:pass string. Store, fetch, and WebDAV each re-derive auth
from headers per request: no shared login state for machines.
What it protects against
Session theft via XSS (HttpOnly keeps JS out), auth-parser differential bugs (one strict compare shape everywhere), and machine-credential replay across endpoints (each endpoint checks its own cred class: store creds never fetch, grant creds never store... except WebDAV store-user access, which is explicit).
Attack realism
High for the boring wins: HttpOnly plus single-operator scope ends the classic session-steal stories. Realism limit is transport: Basic is base64, not encryption, so it leans fully on loopback plus stunnel. That pairing is pinned, not assumed.
Pros
Two mechanisms, each minimal. No token library, no JWT parsing, no expiry math for machines. Legacy Flask secret replaced by map-held randoms with no serialize step.
Cons and how the vault resolves them
- Basic is cleartext credentials per request. Resolved by the transport pin: loopback only in binary, TLS only via stunnel. A Basic header on loopback faces the same attackers as the process memory itself.
- Sessions never expire server-side. Closed in M5: 24h idle expiry with sliding refresh on every use, plus the 1000-cap oldest-drop.
- Cookie has no Secure or SameSite flags. SameSite=Lax landed in M5 with Gate 2 asserting it; Secure stays deferred to any non-loopback future, tracked, not forgotten.
- Substring cookie parse is loose. Accepted and bounded: it can only match exact session ids from the map; garbage matches nothing and 302s.
Residual risk
None beyond transport trust, which is the documented deployment contract, not a gap.
M6: logout now erases the server-side session entry, proven by dead-cookie plus live-sibling test.