Antonio Braccolino, Identity & Access, home
EN · Language: English
← All terms

IAM glossary

What is State?

A random value the app sends to the authorization endpoint and checks when the user comes back. It protects the callback from CSRF; without it, someone can log you into their account.

How it works

state is a random value the app generates before sending the user to the authorization server, and stores in the user’s browser session. The server returns it unchanged in the redirect, together with the code.

The app checks that the returned state matches the stored one. This proves that the response belongs to a login this browser started, and stops login CSRF: an attacker cannot make your browser complete a login with the attacker’s own code. Apps also use it to remember where to send the user after login.

A simple example

The app stores state=9fK2pQ and redirects you to the provider. You come back with ?code=...&state=9fK2pQ: match, continue. An attacker tricks you into opening .../callback?code=ATTACKER_CODE&state=zz11; your session expects 9fK2pQ, so the app refuses and you do not end up logged in to the attacker’s account.

Common mistakes

  • Omitting state or using a fixed value.
  • Checking it only if present, so an attacker simply leaves it out.
  • Putting sensitive data in it: it travels in the URL.

See it at work