Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is PKCE?

PKCE stops a stolen OAuth authorisation code being redeemed by anyone else: the client proves it started the flow by revealing a secret it generated at the beginning.

Illustration for the cybersecurity term PKCE
Home / Blog / Cybersecurity Terms / What Is PKCE?
17 November 2026

What Is PKCE?

What Is PKCE?

PKCE—pronounced “pixy”, and standing for Proof Key for Code Exchange—was written in 2015 to fix a specific hole in OAuth on mobile devices. It has since become the recommended practice for every client type, confidential ones included. RFC 7636 is the specification.

The Problem It Was Written For

In the authorisation code flow, the authorisation server redirects the browser back to the application with a code in the URL, and the application then exchanges that code for tokens. A web application running on a server also sends its client secret during the exchange, which proves it is the application the code was issued to.

A mobile application cannot do that. Anything shipped inside an app binary can be extracted, so a mobile client has no secret. On older mobile platforms the redirect happened through a custom URI scheme—something like myapp://callback—and any other application on the device could register the same scheme. A malicious app that did so would receive the authorisation code and, with no client secret required, exchange it for tokens itself.

The Fix

PKCE makes the client prove it is the one that started the flow, using a secret created per-request rather than embedded in the application.

  1. Before redirecting, the client generates a code verifier: a cryptographically random string of 43 to 128 characters.
  2. It computes the code challenge as the base64url encoding of the SHA-256 hash of the verifier, and sends that with code_challenge_method=S256 in the authorisation request.
  3. The authorisation server stores the challenge alongside the code it issues.
  4. When the client exchanges the code, it sends the original verifier.
  5. The server hashes the verifier and compares. No match, no tokens.
GET /authorize?response_type=code
  &client_id=mobile-banking-uk
  &redirect_uri=https%3A%2F%2Fapp.example.co.uk%2Fcb
  &scope=openid accounts.read
  &state=9f2c41ab7d
  &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
  &code_challenge_method=S256

An attacker who intercepts the code has only a hash. Reversing SHA-256 is not an option, so the code is useless to them. The secret that matters never travels in the first message, which is what makes the scheme work without any pre-registered credential.

Do Not Use the Plain Method

The specification permits code_challenge_method=plain, where the challenge is the verifier itself. It exists only for devices that genuinely cannot compute SHA-256, which in practice means nothing you are likely to build. With plain, an attacker who can see the authorisation request sees the verifier and can redeem the code normally.

Servers should reject plain outright. Clients should always send S256. If a library offers a choice, that is a configuration decision worth checking rather than leaving at a default.

Why Confidential Clients Need It Too

The original scope was public clients. The OAuth 2.0 Security Best Current Practice document, and OAuth 2.1 which consolidates current guidance, now recommend PKCE for all clients.

The reason is authorisation code injection. Consider an attacker who obtains a code issued for their own account—trivially, since they can start a flow themselves—and injects it into a victim’s session with the application. Without PKCE, the application exchanges it and binds the attacker’s account to the victim’s session, or in some designs the reverse: the victim’s data becomes accessible under the attacker’s account. The state parameter does not prevent this because it protects against cross-site request forgery rather than code substitution.

With PKCE the injected code fails at exchange, because the verifier in the client’s session does not correspond to the challenge the code was issued against. For OpenID Connect clients the nonce claim provides a similar binding for identity tokens, and using both is the correct answer rather than choosing between them.

Getting It Right in Practice

Most modern libraries implement this correctly if you let them. The failures found in assessments are usually hand-rolled implementations, or a server that accepts a token exchange with no verifier at all when the challenge is absent—which lets an attacker simply omit PKCE from the authorisation request and bypass the whole mechanism. For the surrounding context, see OAuth 2.0, OpenID Connect, and DPoP for binding the tokens that follow.

At Privia Security, we test authorisation flows for code interception and injection in our mobile application security services.

FAQ – Frequently Asked Questions

Does PKCE Replace the Client Secret?

For public clients it provides the protection a client secret cannot, since those clients have no way to keep a secret. For confidential clients it does not replace the secret; both are used together. The secret authenticates the application to the token endpoint, while PKCE binds the authorisation code to the particular request that produced it.

Is PKCE Needed for Server-Side Web Applications?

Yes, current guidance recommends it for every client type. A confidential client is still exposed to authorisation code injection, where an attacker feeds a code from their own flow into a victim’s session. PKCE prevents that because the verifier held in the legitimate client’s session will not match the challenge the injected code was issued against.

What Is the Difference Between S256 and Plain?

With S256 the challenge is the SHA-256 hash of the verifier, so an attacker who sees the authorisation request learns nothing useful. With plain the challenge is the verifier itself, so anyone observing the request can redeem an intercepted code. Plain exists only for devices that cannot hash; servers should reject it and clients should never send it.

Does PKCE Protect the Access Token After Issue?

No. It protects the authorisation code during the exchange and stops there. Once tokens are issued they are ordinary bearer credentials, usable by anyone who obtains them. Short lifetimes, refresh token rotation, working revocation, and sender-constrained tokens through DPoP or mutual TLS are what protect the tokens themselves.

Related Terms

You May Be Interested In These

What Is a Keylogger?

Cybersecurity Terms

17 November 2026

What Is a Keylogger?

Read More
What Is Sandboxing?

Cybersecurity Terms

17 November 2026

What Is Sandboxing?

Read More
What Is VLAN Security?

Cybersecurity Terms

17 November 2026

What Is VLAN Security?

Read More