Skip to content

fix(cli): route to org-auth token host when no URL is configured - #1575

Open
jared-outpost[bot] wants to merge 2 commits into
mainfrom
issue-1568-org-auth-host
Open

fix(cli): route to org-auth token host when no URL is configured#1575
jared-outpost[bot] wants to merge 2 commits into
mainfrom
issue-1568-org-auth-host

Conversation

@jared-outpost

@jared-outpost jared-outpost Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Problem

When only SENTRY_AUTH_TOKEN is set — an sntrys_ org-auth token embedding a custom instance URL (e.g. http://localhost:8000) — and no SENTRY_URL/SENTRY_HOST/--url is provided, commands such as sentry debug-files upload fail with:

Error: Credentials: https://sentry.io
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://localhost:8000).

Root cause

getConfiguredSentryUrl() (used by getApiBaseUrl()/getControlSiloUrl()) only reads SENTRY_HOST/SENTRY_URL and otherwise falls back to DEFAULT_SENTRY_URL (https://sentry.io). It never consults the sntrys_ token's embedded url claim.

Meanwhile getActiveTokenHost() does treat the org-auth token's embedded claim URL as authoritative for the host-scope trust check. With only SENTRY_AUTH_TOKEN set, the two resolutions disagree: the request destination defaults to https://sentry.io while the trust check computes the token host as http://localhost:8000. The mismatch trips the host-scoping guard, producing the confusing error even though no host override was intentionally requested.

Fix

Route the base URL to the active token host before falling back to DEFAULT_SENTRY_URL:

getConfiguredSentryUrl() ?? getActiveTokenHost() ?? DEFAULT_SENTRY_URL

This aligns the request destination with the trust anchor. Explicit SENTRY_HOST/SENTRY_URL/--url (which the boot path also populates from .sentryclirc and stored defaults) still take precedence, so no configured behavior changes. No new credential-leak path is introduced: requests are only routed to the host the credentials are already trusted for.

Tests

Added test/lib/sentry-client.base-url.test.ts:

  • defaults to SaaS when nothing is configured
  • falls back to the sntrys_ token claim host when no URL is set
  • explicit SENTRY_URL/SENTRY_HOST override the token claim host
  • non-sntrys_ env token without a URL still defaults to SaaS

Test results (with pipefail):

  • sentry-client.base-url + env-token-host + token-host + token-claims: 60 passed
  • sentry-client + sentry-client.invalidation: 13 passed
  • biome lint on both changed files: clean

Fixes #1568

getConfiguredSentryUrl() only reads SENTRY_HOST/SENTRY_URL and otherwise
falls back to DEFAULT_SENTRY_URL (https://sentry.io), ignoring the sntrys_
org-auth token's embedded url claim. With only SENTRY_AUTH_TOKEN set, the
request destination resolved to sentry.io while the host-scoping guard
trusts the token claim host, tripping the confusing "Refusing to route
requests" error.

Fall back to the active token host before DEFAULT_SENTRY_URL so the request
destination agrees with the trust anchor. Explicit SENTRY_HOST/SENTRY_URL/
--url still take precedence.

Fixes #1568
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cli Ready Ready Preview Sep 11, 2026 10:02am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Sep 11, 2026 10:02am UTC

Request Review

@jared-outpost
jared-outpost Bot marked this pull request as ready for review September 11, 2026 09:39

@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.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e59cf08. Configure here.

Comment thread packages/cli/src/lib/sentry-client.ts
Comment thread packages/cli/src/lib/sentry-client.ts
resolveOrgRegion() resolved its org-details base URL via getSentryBaseUrl(),
a separate resolver from getApiBaseUrl() that still defaulted to sentry.io
when only a bare sntrys_ token was set. Org-scoped commands (debug-files
upload, releases, etc.) therefore still requested sentry.io and tripped the
host-scoping guard, so the first commit only fixed part of #1568.

Route the org-details request through getApiBaseUrl() (which already falls
back to the active token host). Kept getSentryBaseUrl() as-is to avoid a
sentry-urls -> token-host -> db/auth -> telemetry -> sentry-urls module-init
cycle; its remaining callers build web links and telemetry tags, not requests.

Adds a region test asserting a bare sntrys_ token routes org discovery to its
claim host.
@jared-outpost

jared-outpost Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

The one issue Bugbot flagged (org-scoped commands still routing to sentry.io with only a bare sntrys_ token) was real and is fixed in abb5a8f: resolveOrgRegion now resolves the org-details base URL through getApiBaseUrl(), which falls back to the active token host. Details and the reasoning for not touching getSentryBaseUrl() directly (module-init cycle) are on the inline thread. A region regression test covers the bare-token case.

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.

Env org-auth token host claim ignored when picking request base URL

0 participants