OAuth2 State Fixation
OAuth2 state fixation occurs when an application accepts a state value without adequately binding it to the user’s authorization session.
How It Differs From Missing-State CSRF
The OAuth2 State Parameter page covers the plain case: the client generates no state, or never compares it, so the attacker's callback is simply accepted. State fixation is the case where the client _does_ generate and compare state, but stores the expected value somewhere the attacker can write, typically a cookie that is not bound to the authenticated session. The check runs and passes, because the attacker chose both sides of the comparison.
Why It Works
- The expected state lives in a client-writable cookie, not in the server-side session, so the attacker can set it.
- The comparison is state-to-cookie only; nothing ties the value to the specific authenticated user.
- A missing
__Host-prefix or an over-broadDomainlets a subdomain overwrite the cookie.
Prevention
- Store the expected state in the server-side session keyed to the authenticated user, not in a cookie the browser (or attacker) can write.
- If state must be carried in a cookie, HMAC it to the session ID and reject any state whose binding does not match the current session.
- Use the
__Host-cookie prefix withSecureandSameSiteso a sibling subdomain cannot fix the value. - Generate a fresh state per authorization request and invalidate it once consumed, so a fixed value cannot be reused.
- On account linking, require the linking user to re-confirm rather than linking silently on callback.