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

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

Exact message you may see CSRF Warning! State not equal in request and responseState not equal in request and responseOAuth state mismatch session
Seen on: Python Flask

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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.