How to fix: OAuth authorization code request missing PKCE
A request made to an OAuth/OIDC authorize endpoint during the scan uses response_type=code with a client_id but no code_challenge parameter, meaning the authorization code flow is running without Proof Key for Code Exchange (PKCE).
Why it matters
Without PKCE, an authorization code intercepted in transit, via a malicious app registered on the same custom redirect URI scheme, a compromised network, or referrer leakage from the redirect target, can be exchanged for tokens by whoever captures it. PKCE binds the code to the client that originated the request, so an intercepted code alone is no longer enough to redeem it.
This inspects the actual request URL fetched during the scan for the OAuth authorize endpoint shape (response_type=code, a client_id, and the presence or absence of code_challenge); it is not a text match against page content. It cannot tell whether this OAuth client is confidential (a server-side app exchanging the code with a client_secret) or public (an SPA or native app); PKCE matters most for public clients but is now recommended for all client types.
How to fix it
- 1Generate a random code_verifier and derive code_challenge from it with S256 before redirecting to the authorize endpoint
- 2Send code_challenge and code_challenge_method=S256 as parameters on the authorize request
- 3Send the original code_verifier when exchanging the authorization code at the token endpoint
Code examples
Build a PKCE-enabled authorize redirect
async function buildAuthorizeUrl() {
const verifier = base64url(crypto.getRandomValues(new Uint8Array(32)));
sessionStorage.setItem('pkce_verifier', verifier);
const challengeBytes = await crypto.subtle.digest(
'SHA-256',
new TextEncoder().encode(verifier),
);
const challenge = base64url(new Uint8Array(challengeBytes));
const url = new URL('https://idp.example.com/oauth2/v1/authorize');
url.searchParams.set('response_type', 'code');
url.searchParams.set('client_id', CLIENT_ID);
url.searchParams.set('redirect_uri', REDIRECT_URI);
url.searchParams.set('code_challenge', challenge);
url.searchParams.set('code_challenge_method', 'S256');
url.searchParams.set('state', crypto.randomUUID());
return url.toString();
}References
Detected automatically by VulnRadar. The check id is api-oauth-authorize-missing-pkce, stable across every scan so you can filter or diff on it.
More api checks
- LowTRACE method referenced in API response body
- InfoREST endpoint allows DELETE
- LowGraphQL introspection field suggestions
- MediumGraphQL endpoint has no rate-limit headers
- LowOpenAPI server URL leaks internal host
- LowCORS preflight result not cached
- HighBearer token in URL query string
- MediumJSONP callback parameter accepted
Questions
- How severe is OAuth authorization code request missing PKCE?
- VulnRadar rates this medium severity in the api category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id api-oauth-authorize-missing-pkce, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does OAuth authorization code request missing PKCE map to?
- It maps to CWE-294. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.