Skip to content

fix(cli): Reject non-absolute region URLs in SDK config and cache - #1613

Closed
sentry[bot] wants to merge 2 commits into
mainfrom
seer/fix/cli-2de-validate-region-urls
Closed

sentry[bot] wants to merge 2 commits into
mainfrom
seer/fix/cli-2de-validate-region-urls

Conversation

@sentry

@sentry sentry Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

In CLI 0.40.0, querying organizations on self-hosted instances whose API returns an empty or relative links.regionUrl (e.g. "/" or "") led to SDK calls constructing relative URLs like /api/0/organizations/<org>/projects/?per_page=100, which Node's new Request() rejected with TypeError: Failed to parse URL.

While current main resolves relative/empty region URLs against the origin at fetch time, two defensive gaps remained:

  1. If a non-absolute region URL had been stored in org_regions by older CLI versions, getOrgRegion and getOrgByNumericId would return it verbatim as an authoritative cache hit, bypassing resolution and reproducing the crash indefinitely.
  2. If getSdkConfig ever receives a non-absolute base URL from any caller, the error only surfaces deeply inside undici as an opaque URL-parse error.

Changes

  • packages/cli/src/lib/db/regions.ts: Validate cached region_url on read via usableRegionUrl(). Treat non-absolute URLs as a cache miss with a debug log so the CLI falls back to fresh resolution.
  • packages/cli/src/lib/sentry-client.ts: In getSdkConfig(), assert that the normalized base URL is an absolute HTTP(S) URL via normalizeHttpOrigin(), throwing an informative ConfigError with a hint to set SENTRY_URL instead of letting undici fail.
  • Tests added in packages/cli/test/lib/db/regions.focused.test.ts, packages/cli/test/lib/region.test.ts, and packages/cli/test/lib/sentry-client.test.ts.

Fixes CLI-2DE

@sentry <feedback>: Autofix iterates on these changes
@sentry stop iterating: Autofix stops iterating on this run

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@vercel

vercel Bot commented Oct 23, 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 Oct 23, 2026 12:00pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 23, 2026

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

Closing this one: main already fixes CLI-2DE at the source, so the extra guards aren't needed.

  • Relative and empty regionUrl values are resolved, not passed through. #1567 (getsentry/cli#1567, first shipped in [email protected]) and the later origin-scoping work send links.regionUrl through normalizeRegionBaseUrl(raw, responseOrigin) in src/lib/region.ts and src/lib/api/organizations.ts. A value like "/" becomes the self-hosted instance's absolute URL. If the value is empty, it falls back to the known base URL or response origin. test/lib/region.test.ts already covers "resolves a relative regionUrl against baseUrl".
  • Bad values can't be written to the cache. setOrgRegion runs every URL through requireRegionBaseUrl() in src/lib/db/regions.ts, which throws on anything that isn't an absolute, credential-free HTTP(S) URL.
  • Old cached rows are already gone. Schema migration 17 (src/lib/db/schema.ts) drops and rebuilds org_regions, so rows saved by older CLIs like 0.40.0 no longer exist. That makes the read-side usableRegionUrl() check dead code.
  • The getSdkConfig check has no realistic trigger. Its inputs are getApiBaseUrl() (configured URL, credential host, or default) or region URLs that already passed the checks above.

The event in CLI-2DE came from 0.40.0, which shipped before #1567. Upgrading fixes it.

@sentry-junior sentry-junior Bot closed this Oct 23, 2026

This branch was previously deployed

1 inactive deployment
Preview — aab9ca13 Deployed Oct 23, 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.

0 participants