A code verifier is a unique, unpredictable value generated by a client before authentication in a PKCE flow. It protects against an attacker intercepting the authorization code and exchanging it for an access token. section 13.1
PKCE uses the verifier in a short sequence:
- The client generates random data, typically a byte array, and Base64-encodes it as the code verifier. section 13.1
- The client hashes the verifier, commonly with SHA-256, to create the code challenge and sends only the challenge during login. section 13.1
- After authentication, the client sends the authorization code and original verifier; the authorization server issues a token only when the verifier matches. section 13.1
Intercepted authorization code
If an attacker steals the authorization code between authentication and token exchange, the exchange still fails because the attacker does not possess the client’s code verifier. section 13.1
Figure 13.3 Relationship between code verifier and code challenge. The code verifier is a securely generated random value. The code challenge is derived by applying a cryptographic hash function (often, SHA-256) to the code verifier. This one-way transformation strengthens the security of the authorization process by ensuring that the verifier can’t be reverse-engineered from the challenge.
Trace how the random code verifier becomes a one-way hashed code challenge. section 13.1
