# Login CSRF
> Forcing a victim's browser to authenticate into an **attacker-controlled** account (session swapping), so the victim's subsequent activity, data and linked identities land in the attacker's account; most often caused by OAuth/SAML callbacks that are not bound to the browser that started the flow.
## How it works
Inverse of classic CSRF: no victim session is ridden; instead a session is *established*. Sinks:
- **Password login form** without a pre-session token or Origin check.
- **OAuth 2.0 callback** — `code` (or token) accepted without a per-request `state` bound to the initiating browser; no PKCE; callback establishes a session for any valid code.
- **SAML ACS** — response correlated via unsigned `RelayState` instead of the receiving browser's pending AuthnRequest; signature and `InResponseTo` validate the assertion, not browser ownership.
- **Signed-request / magic-link sign-in** endpoints that accept an attacker-supplied credential blob without a CSRF header.
- **Account-linking / connect flows** (inverse case): the victim's account gets linked to the *attacker's* third-party identity → attacker logs in as the victim (that is ATO, not just login CSRF).
## Impact ladder
| Variant | Impact |
|---|---|
| Logout CSRF alone | annoyance / DoS; step in chains (force re-login on a phishing form, LostPass-style) |
| Login CSRF alone | victim enters data, uploads files, saves cards, submits reports into attacker account |
| + self-XSS in attacker account | stored payload executes in victim's browser on the real origin → credential phishing on a valid TLS origin, autofill theft |
| OAuth connect CSRF (victim linked to attacker IdP) | full [[Account Takeover]] |
| Product-specific | XE-0656: reading victim's sealed reports and payout address (CVSS 8.6) |
## Techniques / tests
- Login form: replay a login POST cross-site without token; check `Origin`/`Sec-Fetch-Site` enforcement before session exists.
- OAuth: inspect `state` — absent, static (`state={"origin_uri": "/"}`), not compared server-side, or not cleared after use. Mint a code in browser A, redeem the callback URL in fresh browser B; success = cross-session code acceptance.
- Check PKCE presence (`code_challenge`); check whether the callback refuses codes unrelated to the current browser context.
- State-cookie hygiene: cookie set under one `Path` and cleared under another survives, making `state` replayable (@fastify/oauth2).
- SAML: replay an IdP response with a tampered `RelayState` into an anonymous browser.
- Logout: GET logout that re-sets the session cookie also reopens the Chromium Lax+POST window ([[SameSite Cookies]]).
## Notable cases
- **dkrypt writeup** — static `state`, no PKCE, no session binding; code minted in browser A logs browser B into A's account; the `/authorize` CSRF token was also unenforced. [[raw/dkryptsecurity.com/login-csrf-via-a-replayable-oauth-code-static-state-no-pkce-15065|Login CSRF via a replayable OAuth code (static state, no PKCE)]]
- **Seamless Auth API < 0.19.2** — `state` was HMAC-signed, 10-minute, single-use, with PKCE on, but not bound to the initiating browser; the PKCE verifier was derived server-side from `state`, so holding `state`+`code` was enough (RFC 9700 §4.7). The React SDK only blunted it by accident (pending-sign-in check); native and direct API clients had no check. Fix: random `binding` returned by `/start`, its SHA-256 inside the signed state, constant-time compare at callback before burning the state. [[raw/seamlessauth.com/we-wrote-an-rfc-9700-matrix-and-it-found-a-bug-oauth-state-binding-15863|We wrote an RFC 9700 matrix and it found a bug (OAuth state binding)]]
- **XE-17987** — reporter OAuth callback not bound to initiating browser; victim authenticates as attacker's GitHub identity (identity grafting correctly blocked). Fix: nonce cookie bound to `state`. [[raw/bounty.xe.network/xe-17987-oauth-callback-not-bound-to-initiating-browser-login-csrf-15363|XE-17987: OAuth callback not bound to initiating browser (login CSRF)]]
- **XE-0656** — `xe_login` signed-request sign-in and GitHub/Discord callbacks skip the `X-Desk-CSRF` check enforced elsewhere; High. [[raw/bounty.xe.network/xe-0656-login-csrf-signs-a-victim-s-browser-into-an-attacker-chosen-re-13765|XE-0656: login CSRF signs a victim's browser into an attacker-chosen reporter identity]]
- **@fastify/oauth2** — state and PKCE verifier cookies set under `/login` path but cleared with `Path=/` → replayable state (from 7.2.0 / 7.6.0). Mitigations: patched release, `cookie: { path: '/' }`, `__Host-` names. [[raw/github.com/fastify-oauth2-login-csrf-via-uncleared-oauth-state-cookie-12793|@fastify/oauth2 login CSRF via uncleared OAuth state cookie]]
- **social-auth-core SAML (GHSA-4pv2-52v7-vrfx, 4.7.0–6.2.0)** — session selected from unsigned RelayState; fixed in 7.0.0 by correlating with the initiating browser's AuthnRequest. [[raw/github.com/social-core-login-csrf-in-saml-callbacks-via-relaystate-15352|social-core: login CSRF in SAML callbacks via RelayState]]
- **social-auth-core < 7.0.0 (CVE-2026-126775)** — crafted IdP responses + RelayState in the SAML backend. [[raw/github.com/social-auth-core-login-csrf-14377|social-auth-core login CSRF]]
- **NamelessMC** — OAuth `state` not validated server-side; crafted callback swaps the victim into the attacker's linked account. [[raw/github.com/namelessmc-oauth-callback-state-not-validated-login-csrf-15068|NamelessMC: OAuth callback state not validated, login CSRF]]
- **Keystatic ≤ 0.6.9 (GHSA-fv6w-2c5w-h387)** — `githubOauthCallback` omits state validation; victim's actions are committed under the attacker's GitHub identity. [[raw/github.com/keystatic-login-csrf-14930|Keystatic login CSRF]]
- **Vikunja < 2.8.0** — login CSRF. [[raw/github.com/vikunja-login-csrf-15674|Vikunja login CSRF]]
- **"Connect with Facebook" static state** — predictable `state` in a mature product's linking flow → ATO. [[raw/securepurple.com/oauth-based-csrf-exploiting-a-flawed-state-parameter-15066|OAuth-based CSRF: exploiting a flawed state parameter]]
- **OpenMage Magento LTS** — OAuth `confirm`/`confirmSimple` lack form-key validation on GET; victim visiting confirm URL grants attacker consumer a persistent REST token. [[raw/github.com/openmage-magento-lts-cross-site-request-forgery-critical-14534|OpenMage Magento LTS cross-site request forgery (critical)]]
- **ASP.NET Core CVE-2026-109481** — CSRF on `/_blazor/refresh` binds the victim's authenticated principal to an attacker-owned circuit (EoP, CVSS 7.5). [[raw/github.com/asp-net-core-elevation-of-privilege-via-csrf-cve-2026-109481-14078|ASP.NET Core elevation of privilege via CSRF (CVE-2026-109481)]]
## Defenses
- Pre-session CSRF tokens (or Origin/`Sec-Fetch-Site` enforcement) on login, logout and registration.
- OAuth: per-request unpredictable `state` stored server-side or in a `__Host-` cookie and cleared on use; PKCE for every client; refuse to establish a session from a code not tied to the current browser. Signing `state` does not bind it; carry a browser-held secret (hash inside `state`) and verify it before marking `state` used. See [[OAuth 2.0 Vulnerabilities]].
- SAML: correlate responses with the receiving browser's own pending AuthnRequest; never select session from `RelayState`. See [[SAML Attacks]].
- Rotate session on login ([[Session Management]]); show the logged-in identity prominently.
## Related
- [[Cross-Site Request Forgery]]
- [[OAuth 2.0 Vulnerabilities]]
- [[SAML Attacks]]
- [[Session Management]]
- [[Account Takeover]]
- [[SameSite Cookies]]
- [[CSRF Token Bypasses]]
## Sources
- [[raw/dkryptsecurity.com/login-csrf-via-a-replayable-oauth-code-static-state-no-pkce-15065|Login CSRF via a replayable OAuth code (static state, no PKCE)]]
- [[raw/bounty.xe.network/xe-17987-oauth-callback-not-bound-to-initiating-browser-login-csrf-15363|XE-17987: OAuth callback not bound to initiating browser (login CSRF)]]
- [[raw/bounty.xe.network/xe-0656-login-csrf-signs-a-victim-s-browser-into-an-attacker-chosen-re-13765|XE-0656: login CSRF signs a victim's browser into an attacker-chosen reporter identity]]
- [[raw/github.com/fastify-oauth2-login-csrf-via-uncleared-oauth-state-cookie-12793|@fastify/oauth2 login CSRF via uncleared OAuth state cookie]]
- [[raw/github.com/social-core-login-csrf-in-saml-callbacks-via-relaystate-15352|social-core: login CSRF in SAML callbacks via RelayState]]
- [[raw/github.com/social-auth-core-login-csrf-14377|social-auth-core login CSRF]]
- [[raw/github.com/namelessmc-oauth-callback-state-not-validated-login-csrf-15068|NamelessMC: OAuth callback state not validated, login CSRF]]
- [[raw/github.com/keystatic-login-csrf-14930|Keystatic login CSRF]]
- [[raw/github.com/vikunja-login-csrf-15674|Vikunja login CSRF]]
- [[raw/securepurple.com/oauth-based-csrf-exploiting-a-flawed-state-parameter-15066|OAuth-based CSRF: exploiting a flawed state parameter]]
- [[raw/github.com/openmage-magento-lts-cross-site-request-forgery-critical-14534|OpenMage Magento LTS cross-site request forgery (critical)]]
- [[raw/github.com/asp-net-core-elevation-of-privilege-via-csrf-cve-2026-109481-14078|ASP.NET Core elevation of privilege via CSRF (CVE-2026-109481)]]
- [[raw/security.stackexchange.com/web-application-should-login-and-logout-action-have-csrf-protection-in-931|web application - Should login and logout action have CSRF protection? - In]]
- [[raw/stackoverflow.com/oauth-2-0-how-does-csrf-work-without-state-parameter-in-oauth2-0-stack-934|oauth 2.0 - How does CSRF work without state parameter in OAuth2.0? - Stack]]
- [[raw/book.hacktricks.xyz/csrf-cross-site-request-forgery-hacktricks-2874|CSRF (Cross Site Request Forgery) - HackTricks]]
- [[raw/medium.com/csrf-the-bug-everyone-declared-dead-and-nobody-actually-fixed-13022|CSRF: The Bug Everyone Declared Dead and Nobody Actually Fixed]]
- [[raw/portswigger.net/lab-samesite-lax-bypass-via-cookie-refresh-portswigger-2870|Lab: SameSite Lax Bypass via Cookie Refresh - PortSwigger]]
- [[raw/owasp.org/csrf-owasp-foundation-3429|CSRF - OWASP Foundation]]
- [[raw/seamlessauth.com/we-wrote-an-rfc-9700-matrix-and-it-found-a-bug-oauth-state-binding-15863|We wrote an RFC 9700 matrix and it found a bug (OAuth state binding)]]