OAuth Authorisation Code Flow Without PKCE

The OAuth authorisation code flow is used without Proof Key for Code Exchange, so an intercepted or leaked authorisation code can be redeemed or injected by someone else.

SeverityLow
CVSS 3.13.1 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:N/A:N Open in the calculator
CVSS 4.02.3 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-294: Authentication Bypass by Capture-replay
OWASP Top 10A07:2025 Authentication Failures
MITRE ATT&CKT1528 Steal Application Access Token, T1550.001 Application Access Token
CategoryInsecure Design

Description

Proof Key for Code Exchange (PKCE, RFC 7636) binds an authorisation code to the client instance that requested it. The client creates a random secret, the code verifier, and sends a hash of it, the code challenge, with the authorisation request; when it redeems the code, it must present the verifier, which only it knows. The client application uses the authorisation code flow without PKCE, or the authorisation server accepts code redemptions without checking a verifier, or accepts the weaker plain method, in which the challenge is the verifier itself.

Without PKCE, the code alone is enough to obtain tokens, or to complete the sign-in in a browser. An attacker who obtains an authorisation code, for example from logs or Referer headers, or through an open redirect combined with weak redirect URI checks, can exchange it for the victim's tokens or use it to sign in to the client as the victim. This matters most for public clients, which cannot keep a client secret: single-page applications, and mobile and desktop applications, where a malicious application on the same device, registered for the same custom URL scheme, can receive the redirect. For confidential clients that authenticate to the token endpoint, a stolen code cannot be redeemed directly, but it can be injected into the attacker's own session with the client to sign in as the victim.

Exploitation depends on such a way of intercepting codes and on the victim signing in, so the risk is typically low for confidential web applications and higher for mobile, desktop and single-page applications, and any resulting access is limited to the user's account, the granted scopes and the token lifetime. The OAuth 2.0 Security Best Current Practice requires PKCE for public clients and recommends it for confidential ones.

The weakness is identified by checking authorisation requests for the code_challenge and code_challenge_method parameters, and by redeeming a code without a verifier, or with a wrong one, to see whether the authorisation server enforces PKCE.

Remediation

Use PKCE in every authorisation code flow and enforce it at the authorisation server:

  • For each authorisation request, have the client generate a new code verifier (a high-entropy random string of 43 to 128 characters), send its SHA-256 hash as code_challenge with code_challenge_method=S256, and send the verifier as code_verifier when redeeming the code. Current OAuth and OpenID Connect client libraries do this when PKCE is enabled.
  • Configure the authorisation server to require PKCE for every client, or at least every public client, to reject the plain method, and to reject a token request that carries a verifier when no challenge was sent with the authorisation request.
  • For mobile applications, prefer claimed HTTPS redirects (Android App Links or iOS Universal Links) to custom URL schemes, and use the system browser rather than an embedded web view.
  • Keep authorisation codes single-use and short-lived, and revoke tokens already issued from a code that is presented a second time.

Confirm the fix by checking that authorisation requests carry an S256 code challenge and that a code cannot be redeemed without the correct verifier.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Authentication and Sessions Findings

Every Authentication and Sessions finding