# OAuth client: CSRF Warning! State not equal in request and response (mismatching_state)

**Code:** `CSRF Warning` · **Category:** Authentication · **Seen on:** Python, Flask

The state sent back by the provider is not the one the client stored, so the login is aborted as a possible CSRF attack.

## Meaning

Libraries such as Authlib, requests-oauthlib and Flask-Dance keep `state` in the user's session. If the session cookie is missing, expired, or belongs to another host or worker, the check fails.

## Common causes

- Session cookie not sent on the callback (SameSite, host mismatch)
- Multiple app instances without shared session storage
- User opened the login in two tabs
- Secret key changed between workers or restarts

## Quick fix

1. Use the same host name for start and callback
2. Share the session secret and storage between workers
3. Keep one login flow per tab

## Detailed fix by platform

### Flask

1. Set a fixed `SECRET_KEY` and `SESSION_COOKIE_SAMESITE="Lax"`; use one domain for the whole flow

## How to diagnose

1. **Cookie** — Sent on callback?
2. **Workers** — Same secret?
3. **Tabs** — Parallel logins?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/auth/oauth-csrf-warning-state-missing)
