diff options
| author | aur-build <aur-build@localhost> | 2026-11-18 14:41:45 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-18 14:41:45 +0000 |
| commit | 3370a487d6e1100623ebfd982967f1223d251607 (patch) | |
| tree | 124db2f1fe41c3835b4aa4f39a980200804202ea /src/http/mod.rs | |
| parent | 157c078e52fee6c37ff20093189ae7ad7cd223cb (diff) | |
| download | aur-build-3370a487d6e1100623ebfd982967f1223d251607.tar.gz aur-build-3370a487d6e1100623ebfd982967f1223d251607.zip | |
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".
Diffstat (limited to 'src/http/mod.rs')
| -rw-r--r-- | src/http/mod.rs | 13 |
1 files changed, 8 insertions, 5 deletions
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 `<form method=post>`, 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 `<form method=post>`, 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); |
