OAuth2 State Fixation is an attack where the attacker forces a victim to use a pre-set state value that the attacker knows. This allows the attacker to link their OAuth account to the victim's session or bypass CSRF protections.
How It Works
- Attacker initiates OAuth flow on the vulnerable app
- Attacker captures the generated state value
- Attacker tricks victim into using this state
- Victim completes OAuth with attacker's account
- Victim's session now linked to attacker's OAuth account
Attack Scenario
// 1. Attacker visits vulnerable app, gets state
GET /login/oauth?provider=github
// App generates: state=ATTACKER_KNOWN_STATE
// 2. Attacker creates malicious link for victim
https://victim-app.com/oauth/callback?
code=ATTACKER_AUTH_CODE&
state=ATTACKER_KNOWN_STATE
// 3. If app doesn't properly bind state to session,
// victim's account gets linked to attacker's GitHub
Why This Works
- State not cryptographically bound to session
- State validated but session not checked
- State stored in predictable location (cookie without proper flags)
Prevention
- Bind state to session cryptographically (HMAC with session secret)
- Use HttpOnly, Secure, SameSite cookies for state storage
- Validate state AND session binding together
- Generate new state for each authorization request
PentesterLab Exercises
See Also