Skip to content

fix: validate OAuth state before token exchange - #381

Draft
ryanduguid wants to merge 3 commits into
XeroAPI:masterfrom
ryanduguid:codex/validate-oauth-state-before-exchange
Draft

fix: validate OAuth state before token exchange#381
ryanduguid wants to merge 3 commits into
XeroAPI:masterfrom
ryanduguid:codex/validate-oauth-state-before-exchange

Conversation

@ryanduguid

@ryanduguid ryanduguid commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • validate a supplied OAuth callback state before the authorisation-code exchange
  • prevent a mismatched callback from making a token request or overwriting the current token set
  • return a static mismatch error that exposes neither the expected nonce nor attacker-supplied state
  • add regression coverage for mismatched, matching and legacy no-state callback paths

This preserves the SDK's existing optional-state compatibility: callers that do not configure state continue to work. It makes the existing configured-state protection effective before the mutating token exchange occurs.

Validation

  • Ruby 3.2 syntax checks for the implementation and focused spec
  • git diff --check

The full RSpec suite could not run locally because this Windows environment lacks MSYS2/native gem build support. The focused spec retains explicit no-token-request and no-token-mutation assertions, and now also proves that neither synthetic state value appears in the error.

@ryanduguid
ryanduguid marked this pull request as draft August 12, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants