fix: delete the PKCE request session only after a successful verification#883
Open
shilps1583 wants to merge 1 commit into
Open
fix: delete the PKCE request session only after a successful verification#883shilps1583 wants to merge 1 commit into
shilps1583 wants to merge 1 commit into
Conversation
|
|
📝 WalkthroughWalkthroughChangesPKCE session lifecycle
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…rification HandleTokenEndpointRequest deletes the stored PKCE request session immediately after fetching it, before the verifier has been checked against the bound challenge. A failed verification (wrong verifier, disallowed method, PKCE not enforced but a challenge existed, etc.) still leaves the session deleted. That session is what binds an authorization code to its code_challenge. Once it's gone, the same code can be replayed at the token endpoint with no code_verifier at all: GetPKCERequestSession returns ErrNotFound, nv == 0, and validateNoPKCE lets the exchange through as a non-PKCE request (unless EnforcePKCE is on). A failed PKCE attempt against a code should not make a second, verifier-less attempt against that same code succeed -- that's a downgrade from a PKCE-protected exchange to an unprotected one. Move the delete to the two points where the session's job is actually done: a confirmed challenge/verifier match, and the non-PKCE path where no challenge was ever bound and none is required. A verifier presented against a session with no bound challenge is also consumed, since there is no challenge there for a downgrade to strip. Every other error path (validate() failures, verifier format failures, a challenge/verifier mismatch) now leaves the session in place. TestHandleTokenEndpointRequest_SessionLifecycle covers both outcomes; two of its five cases fail against the prior behavior.
shilps1583
force-pushed
the
fix/pkce-delete-session-after-verify
branch
from
July 15, 2026 10:17
70de8eb to
be6b58a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HandleTokenEndpointRequest deletes the stored PKCE request session
immediately after fetching it, before the verifier has been checked
against the bound challenge. A failed verification (wrong verifier,
disallowed method, PKCE not enforced but a challenge existed, etc.)
still leaves the session deleted.
That session is what binds an authorization code to its
code_challenge. Once it's gone, the same code can be replayed at the
token endpoint with no code_verifier at all: GetPKCERequestSession
returns ErrNotFound, nv == 0, and validateNoPKCE lets the exchange
through as a non-PKCE request (unless EnforcePKCE is on). A failed
PKCE attempt against a code should not make a second, verifier-less
attempt against that same code succeed -- that's a downgrade from a
PKCE-protected exchange to an unprotected one.
Move the delete to the two points where the session's job is actually
done: a confirmed challenge/verifier match, and the non-PKCE path
where no challenge was ever bound and none is required. A verifier
presented against a session with no bound challenge is also consumed,
since there is no challenge there for a downgrade to strip. Every other
error path (validate() failures, verifier format failures, a
challenge/verifier mismatch) now leaves the session in place.
TestHandleTokenEndpointRequest_SessionLifecycle covers both outcomes;
two of its five cases fail against the prior behavior.
Summary by CodeRabbit
Bug Fixes
Tests