[wrangler] Fix Account API Tokens failing on /memberships#13858
Merged
Conversation
The fallback for Account API Tokens in `fetchAllAccounts` was checking for code 9109, but `/memberships` actually returns 9106 for that case. Correct the code so the fallback to `/accounts` triggers as intended. Fixes #13857
🦋 Changeset detectedLatest commit: 3ca1ec6 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
Contributor
|
Contributor
|
I'm Bonk, and I've done a quick review of your PR. This PR fixes the One issue found:
|
Co-authored-by: ask-bonk[bot] <249159057+ask-bonk[bot]@users.noreply.github.com>
dario-piotrowicz
approved these changes
May 7, 2026
workers-devprod
approved these changes
May 7, 2026
workers-devprod
left a comment
Contributor
There was a problem hiding this comment.
Codeowners reviews satisfied
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
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 #13857.
PR #13770 added a fallback to
/accountswhen/membershipsis inaccessible to the current auth, with code 9109 (Insufficient permissions) cited as the "structural Account API Token case". In practice,/membershipsactually returns code 9106 (Authentication failed) for Account API Tokens —/membershipsis a user-level endpoint and account-scoped tokens have no user identity, so the API rejects them at this endpoint even though a valid Bearer token is sent. (/useris the endpoint that returns 9109 for the same auth — seegetEmailinwhoami.ts.)Result: any user authenticating with an Account API Token saw
wrangler whoami(and any non-cached account selection) fail withA request to the Cloudflare API (/memberships) failed. Authentication failed (status: 400) [code: 9106]after upgrading to a Wrangler version with #13770.This fixes the fallback by replacing 9109 with 9106 in
MEMBERSHIPS_INACCESSIBLE_CODES. 10000 (Authentication error) is retained as-is. Tests are updated to assert the corrected code.Manual testing with account API tokens:
CLOUDFLARE_API_TOKEN=... pnpx wrangler@4.88 whoami✅CLOUDFLARE_API_TOKEN=... pnpx wrangler@4.89.1 whoami❌CLOUDFLARE_API_TOKEN=... pnpx https://pkg.pr.new/wrangler@9b148fb whoami✅