Skip to content

fix(cli): Name both orgs when an org auth token targets another org - #2168

Merged
betegon merged 5 commits into
mainfrom
fix/cli-org-mismatch-hint
Nov 11, 2026
Merged

betegon merged 5 commits into
mainfrom
fix/cli-org-mismatch-hint

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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.

via @betegon.

--

View Session in Sentry

@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 11, 2026 11:32am UTC

Request Review

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5e11cc3. Configure here.

@sentry-junior
sentry-junior Bot force-pushed the fix/cli-scope-challenge-hint branch from 0e645c4 to 617827e Compare November 11, 2026 09:13
@sentry-junior
sentry-junior Bot force-pushed the fix/cli-org-mismatch-hint branch from 5e11cc3 to 4e11f86 Compare November 11, 2026 09:13
@sentry-junior
sentry-junior Bot force-pushed the fix/cli-org-mismatch-hint branch from 4e11f86 to 3f969ff Compare November 11, 2026 09:24
betegon added a commit that referenced this pull request Nov 11, 2026
Split out of #2160.

401/403s from the CI commands (`release *`, `sourcemap upload`) are
silenced as user errors, and the detail on their spans is mostly
scrubbed to `[Filtered]`, so we can't tell them apart. Over 14 days that
was about 217k failures from about 1.5k orgs. This PR records a fixed
reason category for each one. The CLI's own output doesn't change.

### Before

```
# cli.command span
api_error.status:  401
api_error.message: Failed to create release: 401 Unauthorized
api_error.detail:  [Filtered]

# cli.error.silenced metric
error_class: ApiError   reason: api_user_error   api_status: 401

# cli.api_error_silenced log
status: 401   endpoint: …   detail: [Filtered]
```

### After

```
# cli.command span
api_error.status:        401
api_error.message:       Failed to create release: 401 Unauthorized
api_error.denial_reason: unrecognized

# cli.error.silenced metric
error_class: ApiError   reason: api_user_error   api_status: 401   api_denial_reason: unrecognized

# cli.api_error_silenced log
status: 401   endpoint: …   denial_reason: unrecognized
```

The values are `insufficient_scope`, `access_denied`, `expired`,
`unrecognized`, `member_policy` and `seat_limit`; #2168 adds
`org_mismatch`. On 401/403s, `denial_reason` replaces `detail`. The
values avoid words such as "auth" and "token", because scrubbing turns
values containing them into `[Filtered]`.

<!-- 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]>
sentry-junior Bot and others added 2 commits November 11, 2026 11:07
…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
betegon force-pushed the fix/cli-scope-challenge-hint branch from 8ad0950 to 84f9ce1 Compare November 11, 2026 10:08
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]>
@sentry-junior
sentry-junior Bot force-pushed the fix/cli-org-mismatch-hint branch from 3f969ff to 9c790b4 Compare November 11, 2026 11:28
An org auth token only works in its own organization. Sentry answers
403 when the target org is on the same server and 401 "Invalid org
token" when it isn't, and neither says why. Compare the `sntrys_` claim
of the token the request sent with the org in the request path, and
name both orgs when they differ. Numeric org IDs are skipped.

Co-Authored-By: bete <[email protected]>
@sentry-junior
sentry-junior Bot force-pushed the fix/cli-org-mismatch-hint branch from 9c790b4 to 1025dbd Compare November 11, 2026 11:28
Base automatically changed from fix/cli-scope-challenge-hint to main November 11, 2026 11:29
…hint

# Conflicts:
#	packages/cli/src/lib/api/infrastructure.ts
#	packages/cli/test/lib/api/infrastructure.test.ts
@betegon
betegon merged commit de6a899 into main Nov 11, 2026
26 checks passed
@betegon
betegon deleted the fix/cli-org-mismatch-hint branch November 11, 2026 19:59

This branch was previously deployed

1 inactive deployment
Preview — 1754a3fd Deployed Nov 11, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant