Keep the PKCE code verifier in the cookie rather than the state URL - #78
Keep the PKCE code verifier in the cookie rather than the state URL#78devin-ai-integration[bot] wants to merge 1 commit into
Conversation
The PKCE code verifier was sealed into the OAuth `state` parameter and round-tripped through the authorization response URL, while the callback's double-submit cookie check compared the URL `state` against a cookie whose value was that same sealed `state`. Both comparands came from the same inbound request, so possession of a leaked callback URL (`?code=...&state=...`) was enough to recover the verifier and complete the code exchange as the victim, with no access to the initiating browser's cookie.
Store the code verifier only in the HttpOnly cookie (sealed as `{ nonce, codeVerifier }`) and seal the URL `state` as `{ nonce, customState, returnPathname }` with no secret. The callback recovers the verifier from the cookie and binds it to the URL state by matching the shared nonce, so a leaked callback URL alone can no longer complete the exchange.
Original prompt from Linear User
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThis PR keeps the PKCE verifier out of the OAuth state URL. The main changes are:
Confidence Score: 4/5Mixed-version callbacks can fail during a rolling deployment.
src/get-authorization-url.ts and src/authkit-callback-route.ts Important Files Changed
|
|
Re: Greptile's P1 "Mixed Versions Reject Valid Callbacks" (src/get-authorization-url.ts:50-55) — acknowledged, but I don't think it should change this PR. This is a transient rolling-deploy artifact, not a correctness bug in the new code, and it's inherent to any change of the
So I'm intentionally leaving this as-is. If zero login disruption during rollout is a hard requirement, the right lever is deploy-level (drain / blue-green, or a temporary dual-read window that is explicitly not the vulnerable equality check), which is out of scope for this security fix. Flagging for the human reviewer to decide. |
Summary
The PKCE code verifier was serialized into the OAuth
stateparameter, so it round-tripped through the authorization response URL. This change keeps the verifier in the cookie only and reconstructs it on callback, so it no longer travels in the URL.Please review before merging.