SECURITY: OIDC sign-in is not bound to the browser that started it (login CSRF) #999

Closed
opened 2026-10-24 17:25:54 +00:00 by Cordy · 3 comments
Owner

Found in the #985 research (research-985-7 §3).

Code (VERIFIED, main 07602d02). BeginAuth (internal/auth/oidclib/oidclib.go:192-212) keeps state, PKCE verifier and nonce only in server memory, keyed by state (f.states[state], :204). No cookie is set. HandleCallback (:260-281) accepts any browser that presents a known state with a code.

Attack (INFERRED). The attacker starts a sign-in, signs in at the IdP with their own account, stops before the callback and sends the callback URL (/auth/callback?code=...&state=..., valid up to 10 minutes) to the victim. The victim's browser completes the exchange and is signed in to Cairn as the attacker. Whatever the victim then uploads lands in the attacker's files.

Standards (VERIFIED). RFC 9700 (OAuth 2.0 Security BCP) and the OAuth 2.1 draft require that PKCE / state / nonce be securely bound to the user agent. oauth2-proxy and Nextcloud user_oidc use a short-lived cookie for this.

Fix.

  • BeginAuth sets a short-lived cookie (__Host- prefix, HttpOnly, Secure, SameSite=Lax, Path /, 10 min) holding a random binding value, or a hash of it stored in the state entry.
  • HandleCallback refuses when the cookie is missing or does not match; clears it in every outcome.
  • Tests: callback from a browser without the cookie is refused; with a different cookie is refused; normal flow and reauth flow still work; concurrent sign-ins in two tabs (one cookie per state, or a small set).
  • Later, with #742: the same cookie could carry the whole (sealed) sign-in state, so any instance can finish a sign-in.

Live check (5 minutes, dogfood). Start a sign-in in browser A, copy the callback URL before it loads (or from the IdP redirect), open it in browser B. Today B is signed in as A's account; after the fix B gets the login page with "sign-in failed".

Also from the same research, low severity, untested: POST /auth/logout has no cross-origin protection, so a foreign page may be able to sign someone out of Cairn. Add Go's http.CrossOriginProtection to it.

Found in the #985 research (research-985-7 §3). **Code (VERIFIED, main 07602d02).** `BeginAuth` (`internal/auth/oidclib/oidclib.go:192-212`) keeps state, PKCE verifier and nonce only in server memory, keyed by `state` (`f.states[state]`, :204). No cookie is set. `HandleCallback` (:260-281) accepts any browser that presents a known `state` with a code. **Attack (INFERRED).** The attacker starts a sign-in, signs in at the IdP with their **own** account, stops before the callback and sends the callback URL (`/auth/callback?code=...&state=...`, valid up to 10 minutes) to the victim. The victim's browser completes the exchange and is signed in to Cairn **as the attacker**. Whatever the victim then uploads lands in the attacker's files. **Standards (VERIFIED).** RFC 9700 (OAuth 2.0 Security BCP) and the OAuth 2.1 draft require that PKCE / state / nonce be securely bound to the user agent. oauth2-proxy and Nextcloud user_oidc use a short-lived cookie for this. **Fix.** - `BeginAuth` sets a short-lived cookie (`__Host-` prefix, `HttpOnly`, `Secure`, `SameSite=Lax`, Path `/`, 10 min) holding a random binding value, or a hash of it stored in the state entry. - `HandleCallback` refuses when the cookie is missing or does not match; clears it in every outcome. - Tests: callback from a browser without the cookie is refused; with a different cookie is refused; normal flow and reauth flow still work; concurrent sign-ins in two tabs (one cookie per state, or a small set). - Later, with #742: the same cookie could carry the whole (sealed) sign-in state, so any instance can finish a sign-in. **Live check (5 minutes, dogfood).** Start a sign-in in browser A, copy the callback URL before it loads (or from the IdP redirect), open it in browser B. Today B is signed in as A's account; after the fix B gets the login page with "sign-in failed". Also from the same research, low severity, untested: `POST /auth/logout` has no cross-origin protection, so a foreign page may be able to sign someone out of Cairn. Add Go's `http.CrossOriginProtection` to it.
Author
Owner

Decision (Nikola, 2026-10-24): fixed first, as its own release v0.6.353, before the #985 UI work. Includes CrossOriginProtection on POST /auth/logout.

Decision (Nikola, 2026-10-24): fixed first, as its own release v0.6.353, before the #985 UI work. Includes `CrossOriginProtection` on `POST /auth/logout`.
Author
Owner

Scope found while writing the fix brief (verified in code):

  • Password sign-in has the same class of bug. POST /auth/password (login.go:63+) decodes JSON without checking Content-Type, and a cross-site HTML form with enctype="text/plain" can produce a valid JSON body. A foreign page could therefore sign the victim in as the attacker's local or LDAP account. The implementer confirms this with a red test first.
  • Session cookies are SameSite=Lax (session.go:434-444). Lax does not stop a same-site, cross-origin page (a sibling subdomain of the same domain) from sending POSTs with the cookie.

Fix for v0.6.353:

  1. A per-flow browser-binding cookie for every OIDC flow:
    • HttpOnly, SameSite=Lax, 10 minutes.
    • __Host- and Secure on HTTPS; the same name without them on plain HTTP.
  2. Go's http.CrossOriginProtection around the whole handler for unsafe methods.
    • Requests without Sec-Fetch-Site/Origin (WebDAV, rclone, WOPI, OCM, peering, back-channel logout) pass unchanged.
    • Cross-site and cross-origin browser requests get 403 cross-origin.
    • This also covers POST /auth/logout.
Scope found while writing the fix brief (verified in code): - **Password sign-in has the same class of bug.** `POST /auth/password` (`login.go:63+`) decodes JSON without checking Content-Type, and a cross-site HTML form with `enctype="text/plain"` can produce a valid JSON body. A foreign page could therefore sign the victim in as the attacker's local or LDAP account. The implementer confirms this with a red test first. - **Session cookies are `SameSite=Lax`** (`session.go:434-444`). Lax does not stop a same-site, cross-origin page (a sibling subdomain of the same domain) from sending POSTs with the cookie. **Fix for v0.6.353:** 1. A per-flow browser-binding cookie for every OIDC flow: - `HttpOnly`, `SameSite=Lax`, 10 minutes. - `__Host-` and `Secure` on HTTPS; the same name without them on plain HTTP. 2. Go's `http.CrossOriginProtection` around the whole handler for unsafe methods. - Requests without `Sec-Fetch-Site`/`Origin` (WebDAV, rclone, WOPI, OCM, peering, back-channel logout) pass unchanged. - Cross-site and cross-origin browser requests get 403 `cross-origin`. - This also covers `POST /auth/logout`.
Cordy closed this issue 2026-10-24 21:10:28 +00:00
Author
Owner

Released in v0.6.353 (PR #1000), live on both dogfoods (files, files-bao).

Live checks (2026-10-25)

  • Nikola signed in with single sign-on on both instances. The bound flow works end to end.
  • /auth/login on the public hosts sets __Host-cairn_oidc_<16 hex>: Path=/, Max-Age=600, HttpOnly, Secure, SameSite=Lax. Secure comes through the trusted VPS proxy.
  • /auth/login started on the LAN IP answers 302 to the configured callback host with moved=1.
  • /auth/callback?state=x&code=y without the binding cookie returns 401.
  • Cross-site POST /auth/password (Sec-Fetch-Site: cross-site, the text/plain form shape) and cross-site POST /auth/logout return 403 {"code":"cross-origin"}.
  • Same-origin requests from the signed-in browser are unaffected:
    • POST /auth/password reaches the handler (400 login-missing for an empty body).
    • Authenticated POST /api/v1/shares reaches validation (400).
    • WebDAV PROPFIND /dav/ answers 207.

Still to test by hand (optional): paste a captured callback URL into a second browser; it should get "login failed". The unit and live tests cover this; nobody has tried it manually yet.

Review: .superpowers/sdd/2026-10-25-999/review.md.

  • S1 (sign-in on a foreign host) and S2 (Host size bound) are fixed.
  • Nits N1, N4 and N6 are documented in deployment.md ("Keep the Host header, serve one scheme").
  • N3 is in the report.
  • N5 (a raw # in a hand-crafted request) is accepted.

Closing.

Released in **v0.6.353** (PR #1000), live on both dogfoods (files, files-bao). **Live checks (2026-10-25)** - Nikola signed in with single sign-on on both instances. The bound flow works end to end. - `/auth/login` on the public hosts sets `__Host-cairn_oidc_<16 hex>`: `Path=/`, `Max-Age=600`, `HttpOnly`, `Secure`, `SameSite=Lax`. Secure comes through the trusted VPS proxy. - `/auth/login` started on the LAN IP answers 302 to the configured callback host with `moved=1`. - `/auth/callback?state=x&code=y` without the binding cookie returns 401. - Cross-site `POST /auth/password` (`Sec-Fetch-Site: cross-site`, the text/plain form shape) and cross-site `POST /auth/logout` return 403 `{"code":"cross-origin"}`. - Same-origin requests from the signed-in browser are unaffected: - `POST /auth/password` reaches the handler (400 `login-missing` for an empty body). - Authenticated `POST /api/v1/shares` reaches validation (400). - WebDAV `PROPFIND /dav/` answers 207. **Still to test by hand (optional):** paste a captured callback URL into a second browser; it should get "login failed". The unit and live tests cover this; nobody has tried it manually yet. **Review:** `.superpowers/sdd/2026-10-25-999/review.md`. - S1 (sign-in on a foreign host) and S2 (Host size bound) are fixed. - Nits N1, N4 and N6 are documented in deployment.md ("Keep the Host header, serve one scheme"). - N3 is in the report. - N5 (a raw `#` in a hand-crafted request) is accepted. Closing.
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#999
No description provided.