From 3370a487d6e1100623ebfd982967f1223d251607 Mon Sep 17 00:00:00 2001 From: aur-build Date: Wed, 18 Nov 2026 14:41:45 +0000 Subject: http: the session id is the credential, not a cookie a client can type The gate asked whether the request carried `Cookie: auth=1`, and login did nothing but set that literal value, so the password protected the login form and nothing else: anyone could read the reviews, the audit log, the settings and the build logs by typing the cookie themselves, and the CSRF step then happily minted them a session to POST with. The random sid machinery was already there and already unguessable; it was just never bound to the flag that said "someone authenticated". A session now carries that flag. `auth.rs` holds a map of live sids to whether they passed the password gate; `authenticate` can only flip a sid this process minted, so a login attempt cannot mint a session as a side effect. `gate` asks `is_authenticated(sid)` and nothing else, and the `auth` cookie is gone from both the login response and the logout one. Login rotates the sid rather than promoting the anonymous one, so the session that existed before the password was typed is never the one that carries the privilege after it; logout drops the sid, which invalidates its derived CSRF token with it. Two tests, both over a bare socket because a client that follows redirects turns "you are not signed in" into the login page's 200 and hides the whole point: `a_forged_auth_cookie_is_not_a_session` (the exact forgery, on every sensitive surface, GET and POST) and `login_rotates_the_session_and_logout_ends_it` (rotation, dead pre-login sid, dead logged-out sid). The audit actor is honest now too: with a password set, only an authenticated session is "web". --- src/http/mod.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/http/mod.rs') diff --git a/src/http/mod.rs b/src/http/mod.rs index 16ff6b1..07024d8 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -5,9 +5,11 @@ //! mutations are handed to the writer actor as a transaction request. That is //! what keeps a slow browser from ever holding the database lock. //! -//! Two guards on every POST: a session cookie, and a CSRF token that must match -//! it. Forms are plain `
`, so the whole approval flow works -//! with JavaScript switched off (§12). +//! Two guards on every POST: a session id, and a CSRF token that must match +//! it. The session id is the only credential the browser holds, and it counts +//! as authentication only if someone typed the password into a form on that +//! exact session (§12). Forms are plain ``, so the whole +//! approval flow works with JavaScript switched off. mod auth; mod forms; @@ -232,12 +234,13 @@ fn dispatch(state: &State, req: &Req) -> Res { } // Session gate: mint a session for anonymous visitors so the CSRF token - // exists even before anyone logs in. + // exists even before anyone logs in. It is not a login — `gate` only lets + // through a sid that a successful login marked authenticated. let (sid, new_session) = match req.cookie("sid") { Some(s) if auth::is_valid_session(&s) => (s, false), _ => (auth::new_session(), true), }; - let gated = routes::gate(state, req); + let gated = routes::gate(state, req, &sid); if let Some(mut res) = gated { if new_session { res.header("X-New-Session", &sid); -- cgit v1.2.3