fix(security): separate OAuth PKCE state from code_verifier#10699
fix(security): separate OAuth PKCE state from code_verifier#10699shaun0927 wants to merge 2 commits into
Conversation
The PKCE flow reused the code_verifier as the OAuth state parameter. Per RFC 6749 §10.12 and RFC 7636, these serve different purposes: state is an anti-CSRF token visible in the authorization URL; the code_verifier must remain secret for the token exchange. Generate an independent secrets.token_urlsafe(32) for state and validate it on callback to provide actual CSRF protection. Closes NousResearch#10693
Group the secrets import with time and webbrowser at the top of run_hermes_oauth_login_pure(), matching the existing pattern. Drop the _secrets alias — no name conflict in this scope.
|
Re-checked this against current
So the concern in #10693 isn't stale — the same code path #1775 originally fixed has come back via This branch rebases cleanly onto
Net diff is still scoped to
Happy to force-push the rebase if maintainers prefer a clean linear history before review. |
|
Salvaged in #26861 (merged). Your two commits were cherry-picked onto current main with your authorship preserved in git log — thanks for the catch and the clean RFC-grounded fix. Added two regression tests on top so this doesn't drift back. For context: this was a regression of #1775 — the old |
Summary
The Anthropic OAuth PKCE flow reused the
code_verifieras thestateparameter. This PR generates an independent cryptographic random value forstateand validates it on callback.Changes
agent/anthropic_adapter.py:On callback:
Why this matters
Per RFC 6749 §10.12 and RFC 7636,
stateandcode_verifierserve fundamentally different purposes:stateis an anti-CSRF token, visible in the authorization URL (browser history, referrer headers, server logs)code_verifiermust remain secret — known only to the client, used in the token exchangeReusing the verifier as state leaked it via the authorization URL. Additionally, the state was never validated on callback, so CSRF protection was absent.
Files changed (1 file, +10/-3)
agent/anthropic_adapter.pyTest plan
hermes login --anthropicOAuth flow completes successfullycode_verifier(unchanged)Closes #10693