fix: use independent state and verifier for PKCE (RFC 7636) - #24
Open
Steffen025 wants to merge 1 commit into
Open
fix: use independent state and verifier for PKCE (RFC 7636)#24Steffen025 wants to merge 1 commit into
Steffen025 wants to merge 1 commit into
Conversation
Generate a separate random value for the OAuth state parameter instead
of reusing the PKCE code_verifier. Per RFC 7636 and RFC 6749, these
serve different purposes:
- state: CSRF protection, visible in the redirect URL
- code_verifier: proof of possession, never exposed until token exchange
Reusing the same value means observing the state (browser history,
proxy logs) reveals the verifier, weakening the PKCE guarantee.
Changes:
- createAuthorizationRequest now returns { url, verifier, state }
- exchangeCodeForTokens accepts state as a separate parameter
- index.ts passes state through from request to exchange
- Three new tests verify independence and URL inclusion
Fixes cemalturkcan#16.
Owner
|
One security issue still remains here: This PR generates a separate If you want the |
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.
Fixes #16.
Problem
createAuthorizationRequestreuses the PKCEcode_verifieras the OAuthstateparameter. Per RFC 7636 and RFC 6749 these serve different purposes:statecode_verifierReusing the same value means observing the
state(browser history, proxy logs, shoulder surfing) also reveals thecode_verifier, weakening the PKCE guarantee.Fix
Generate a separate
base64url(randomBytes(32))forstate:const verifier = base64url(randomBytes(32)); + const state = base64url(randomBytes(32));createAuthorizationRequestnow returns{ url, verifier, state }, andexchangeCodeForTokensacceptsstateas a separate parameter.Changes
src/pkce.tsstategeneration, addedstateparameter toexchangeCodeForTokenssrc/index.tsstatethrough the auth flowtests/pkce.test.tsTests
124 tests pass: