IAM glossary
What is Nonce?
A random value the app sends in the OIDC request and finds again inside the ID token. If they do not match, the token was not issued for this login: it stops replay attacks.
How it works
A nonce is a random value used once. In OpenID Connect the app generates it, stores it in the user’s session and sends it in the login request. The provider copies it into the ID token.
When the ID token comes back, the app checks that the nonce inside matches the one it stored. If it does not, the token was not issued for this login: maybe it was stolen from another session and replayed. After the check the stored nonce is thrown away.
A simple example
The app sends nonce=k3J9xQ to the provider and saves it in Anna’s session. The ID token comes back with "nonce": "k3J9xQ": match, login continues. An attacker who injects an old ID token with "nonce": "aa71Bz" is rejected, because Anna’s session expects k3J9xQ.
Common mistakes
- Using a fixed or predictable nonce.
- Generating it but never checking it on the way back.
- Confusing it with
state: state protects the redirect, nonce protects the ID token.