Repository navigation
fix(cli): Name the scopes Sentry accepts when a 403 says which are missing - #2165
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This was referenced Nov 11, 2026
sentry-junior
Bot
force-pushed
the
fix/cli-scope-challenge-hint
branch
from
November 11, 2026 09:13
0e645c4 to
617827e
Compare
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 617827e. Configure here.
…ssing Sentry answers a token that lacks every scope an endpoint accepts with `WWW-Authenticate: Bearer error="insufficient_scope", scope="..."`. Read it and list those scopes, with advice for the credential the request sent: an org:ci hint for personal tokens, "org auth tokens only have org:ci" for org auth tokens, and for a login either `auth login --force` or `auth refresh --scope` with the default scopes kept. Co-Authored-By: bete <[email protected]>
Sentry lists accepted scopes alphabetically, so the first one is often `org:admin` when `org:write` would do, or a scope `auth refresh` rejects, such as `org:billing`. Pick the first accepted scope in SENTRY_SCOPES order (read, write, admin per namespace), and skip the refresh hint when no accepted scope can be requested.
betegon
force-pushed
the
fix/cli-scope-challenge-hint
branch
from
November 11, 2026 10:08
8ad0950 to
84f9ce1
Compare
Keep one table of 403 messages per credential (personal token, org auth token, login) plus the no-challenge fallback. Drop the parser unit tests; the message tests cover the header parsing. Co-Authored-By: bete <[email protected]>
betegon
approved these changes
Nov 11, 2026
betegon
added a commit
that referenced
this pull request
Nov 11, 2026
…2167) Stacked on #2165. Split out of #2160. About 1% of `release create` and `sourcemap upload` runs hit a 401: over 14 days, about 75k and 59k on 0.45 (about 100 each on 0.49). Most CI setups use org auth tokens, but the 401 message sends every env token to the personal token page. ### Before `release create`, with an org auth token (`sntrys_…`) in `SENTRY_AUTH_TOKEN`: ``` Error: Failed to create release: 401 Unauthorized Invalid org token Your SENTRY_AUTH_TOKEN token is not recognized or has been revoked. Create a new token at: <sentry-url>/settings/account/api/auth-tokens/ ``` ### After ``` Error: Failed to create release: 401 Unauthorized Invalid org token Your SENTRY_AUTH_TOKEN org auth token is not recognized or has been revoked. Create a new one in your organization's Settings > Auth Tokens. ``` On `Token expired`, the third line reads `Your SENTRY_AUTH_TOKEN org auth token has expired.` instead. A stored `sntrys_…` token reads `Your stored org auth token …`. A `sentry auth login` session with a leftover `SENTRY_AUTH_TOKEN` now gets `Re-authenticate with: sentry auth login` instead of advice about the env token. <!-- junior-request-attribution:start --> via @betegon. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A28e783cd48c13b214d69caf6d8977a0c --> -- [View Session in Sentry](https://sentry.sentry.io/explore/conversations/agent%3A28e783cd48c13b214d69caf6d8977a0c/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: bete <[email protected]>
betegon
added a commit
that referenced
this pull request
Nov 11, 2026
…2168) Stacked on #2165. Split out of #2160. An org auth token works only in its own org. When it targets another org, Sentry answers 403 if both orgs are on the same server, or 401 "Invalid org token" if they aren't, and neither response says why. The CLI now compares the org in the token (`sntrys_…`) with the org in the request path and names both orgs when they differ. ### Before `release create` for `other-org`, with an org auth token for `my-org` in `SENTRY_AUTH_TOKEN`: ``` Error: Failed to create release: 403 Forbidden You do not have permission to perform this action. Your SENTRY_AUTH_TOKEN token may lack the required scope for this operation. Check token scopes at: <sentry-url>/settings/account/api/auth-tokens/ ``` ``` Error: Failed to create release: 401 Unauthorized Invalid org token Your SENTRY_AUTH_TOKEN token is not recognized or has been revoked. Create a new token at: <sentry-url>/settings/account/api/auth-tokens/ ``` ### After ``` Error: Failed to create release: 403 Forbidden You do not have permission to perform this action. This org auth token belongs to organization 'my-org', but the request is for 'other-org'. Use an auth token created in 'other-org', or target 'my-org' instead. ``` ``` Error: Failed to create release: 401 Unauthorized Invalid org token This org auth token belongs to organization 'my-org', but the request is for 'other-org'. Use an auth token created in 'other-org', or target 'my-org' instead. ``` These errors are recorded with `denial_reason: org_mismatch` (#2163). Numeric org IDs are skipped, and the org comparison ignores case. <!-- junior-request-attribution:start --> via @betegon. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A28e783cd48c13b214d69caf6d8977a0c --> -- [View Session in Sentry](https://sentry.sentry.io/explore/conversations/agent%3A28e783cd48c13b214d69caf6d8977a0c/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: bete <[email protected]>
7 tasks done
This branch was previously deployed
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.

Stacked on #2163.
Split out of #2160.
About 1% of
release set-commitsruns hit a 403 on the repos list: over 14 days, about 41k on 0.45 and 126 on 0.49. The repos list acceptsorg:cibut notproject:releases, so a personal token made for releases fails there with no hint why. Since getsentry/sentry#118612, Sentry lists the accepted scopes inWWW-Authenticate: Bearer error="insufficient_scope", scope="...". The CLI now shows them.Before
release set-commits, with a personal token inSENTRY_AUTH_TOKENthat lacksorg:ci:After
The second line depends on the credential that sent the request:
org:cican't satisfy:Org auth tokens only have org:ci. Use a personal token with one of these scopes instead.sentry auth loginsession:Your login lacks the scope this request needs. Any one of these works: …, followed byauth login --force, orauth refresh --scope <default scopes>,<needed scope>when none of the default scopes is accepted.Self-hosted servers older than getsentry/sentry#118612 don't send the header, so they keep the "may lack the required scope" message.
via @betegon.
--
View Session in Sentry