[4/15] Add PKCE and single-use state CSRF protection to the OAuth client flow - #157
Open
UnknownJoe796 wants to merge 2 commits into
Open
[4/15] Add PKCE and single-use state CSRF protection to the OAuth client flow#157UnknownJoe796 wants to merge 2 commits into
UnknownJoe796 wants to merge 2 commits into
Conversation
Contributor
Author
|
I'll feel more comfortable with this when it tests against an external, official (if possible) OAuth server. |
UnknownJoe796
force-pushed
the
v53/oauth-pkce
branch
from
July 29, 2026 22:54
84236a8 to
e55ee55
Compare
The OAuth client flow previously round-tripped a caller-supplied `state` through the provider without storing or validating it (TODO acknowledged in-code), and used no PKCE. - state/CSRF: the value sent to the provider is now an opaque 256-bit single-use nonce. At flow start a FlowRecord (caller state + PKCE verifier) is stored in the cache keyed by the nonce with a short TTL; the callback validates and consumes it via getAndRemove BEFORE any token exchange, so unknown/expired/replayed callbacks are rejected. The caller's app STATE is preserved server-side and still delivered to onAccess; it no longer leaks to the provider. - PKCE (RFC 7636): S256 code_challenge on the auth redirect and code_verifier on token exchange, gated by a per-provider supportsPkce flag (default true). Verified against the RFC Appendix B test vector. - Confirmed the redirect_uri (fixed callback URL) and final UI redirect (driven only by a server-signed Proof) are not attacker-controllable; documented rather than adding an unnecessary whitelist. Also fixes two latent bugs uncovered here: a NPE on code.state!! and an onError result that was computed then discarded (execution fell through). Requires a cache: OauthCallbackEndpoint/OauthProofEndpoints take a Runtime<Cache> and loginUrl is now suspend (source-breaking on the 5.x line). Docs note the shared-cache requirement for multi-instance deployments and the residual login-CSRF limitation of cookie-less state. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit d0bc38c) (cherry picked from commit 72e2eed)
UnknownJoe796
force-pushed
the
v53/security-headers
branch
from
July 30, 2026 02:19
d0355f1 to
ee913c8
Compare
UnknownJoe796
force-pushed
the
v53/oauth-pkce
branch
from
July 30, 2026 02:19
e55ee55 to
7e99887
Compare
Contributor
Author
|
More tests is good, but I want this tested against externally managed code. |
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.
Adds PKCE and single-use
stateCSRF protection to the OAuth client flow.Pkce.ktis new;OauthCallbackEndpointnow rejects reused or unknown statevalues.
OauthCallbackSecurityTestcovers the happy path and the replay andforgery cases.