Fix malformed API token auth handling - #393
Merged
Merged
Conversation
mattzcarey
force-pushed
the
fix/api-token-error-handling
branch
from
June 8, 2026 17:38
ee9fa2e to
d24d050
Compare
mattzcarey
force-pushed
the
fix/api-token-error-handling
branch
2 times, most recently
from
July 29, 2026 12:47
d029b8a to
f868b2d
Compare
Return structured OAuth resource errors for expected direct-token validation failures so malformed bearer values do not escape as Worker exceptions. Use documented credential ownership prefixes to avoid unnecessary identity probes while retaining Wrangler OAuth and legacy token compatibility. Preserve Retry-After for rate-limited identity probes.
mattzcarey
force-pushed
the
fix/api-token-error-handling
branch
from
July 29, 2026 13:08
f868b2d to
d1d3d66
Compare
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.
Summary
cfat_: only query/accountsand require exactly one account.cfut_and Wrangler OAuthcfoat_: query/userand/accountsin parallel and require user identity.401 invalid_tokenand return RFC 9728WWW-Authenticatemetadata with no-store headers.429 temporarily_unavailableresponses and preserve upstreamRetry-After(default 30 seconds)./userfailure; any simultaneous 5xx continues to take precedence as502.Root cause
The direct credential route inferred ownership entirely from
/userand/accountsresponses. Expected validation errors escaped asMcpError, so malformed values could become Worker exception responses. It also sent both identity requests for account-owned credentials even though current account-token formats encode their owner.The MCP OAuth token and the upstream Cloudflare credential are different layers:
workers-oauth-providervalidates its own token and restores the already-verified Cloudflare user context. Direct Cloudflare API and Wrangler OAuth credentials continue through the explicit credential-validation branch.Validation
pnpm check:depspnpm check:turbopnpm check:formatpnpm test— 283 testspnpm turbo deploy -- -e staging --dry-run— 17 Workerswrangler auth token --jsonOAuth credential — authenticated initialize200200