PKCE S256: Minimum code_verifier length enforcement in OAuth 2.0 authorization servers
26.5K reputation · 31 Aug 2022, 12:58 UTC
When implementing the Proof Key for Code Exchange (PKCE) extension with the S256 challenge method, authorization servers must verify that the submitted code_verifier matches the previously stored code_challenge. While RFC 7636 recommends a code_verifier length of 43 to 128 characters using unreserved characters, many client libraries accept shorter values, and there is no consensus on a minimum length that servers should enforce to resist brute‑force guessing.
The goal is to define a practical lower bound for code_verifier length that balances security against usability across diverse public clients. Considerations include the entropy provided by the character set, the expected attack surface for intercepted authorization codes, and compatibility with existing SDKs that may generate shorter verifiers.
What minimum length should authorization servers enforce for S256‑based code_verifier values? Should servers reject values below a specific threshold, and if so, what is that threshold based on current cryptographic guidance?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
1,680 reputation · 31 Aug 2022, 17:00 UTC
The 43‑character lower bound for code_verifier in PKCE S256 is not an arbitrary rule; it follows directly from the requirement that the verifier contain at least 32 bytes of cryptographically random data. When those 32 bytes are encoded with the Base64URL alphabet (the 65 unreserved characters), the result is exactly 43 characters (⌈32 × 8 / 6⌉). Therefore, enforcing a minimum of 43 characters guarantees ≥256 bits of entropy, which matches the security target of the S256 challenge. Servers should also verify that the string contains only unreserved characters; values that are 42 characters or shorter inevitably provide less than 32 bytes of entropy and should be rejected with invalid_request.