Repository navigation
fix(cli): Reject non-absolute region URLs in SDK config and cache - #1613
Closed
sentry[bot] wants to merge 2 commits into
Closed
sentry[bot] wants to merge 2 commits into
sentry[bot] wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Contributor
There was a problem hiding this comment.
Closing this one: main already fixes CLI-2DE at the source, so the extra guards aren't needed.
- Relative and empty
regionUrlvalues are resolved, not passed through. #1567 (getsentry/cli#1567, first shipped in [email protected]) and the later origin-scoping work sendlinks.regionUrlthroughnormalizeRegionBaseUrl(raw, responseOrigin)insrc/lib/region.tsandsrc/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.tsalready covers"resolves a relative regionUrl against baseUrl". - Bad values can't be written to the cache.
setOrgRegionruns every URL throughrequireRegionBaseUrl()insrc/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 rebuildsorg_regions, so rows saved by older CLIs like 0.40.0 no longer exist. That makes the read-sideusableRegionUrl()check dead code. - The
getSdkConfigcheck has no realistic trigger. Its inputs aregetApiBaseUrl()(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.
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.
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'snew Request()rejected withTypeError: Failed to parse URL.While current
mainresolves relative/empty region URLs against the origin at fetch time, two defensive gaps remained:org_regionsby older CLI versions,getOrgRegionandgetOrgByNumericIdwould return it verbatim as an authoritative cache hit, bypassing resolution and reproducing the crash indefinitely.getSdkConfigever 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 cachedregion_urlon read viausableRegionUrl(). 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: IngetSdkConfig(), assert that the normalized base URL is an absolute HTTP(S) URL vianormalizeHttpOrigin(), throwing an informativeConfigErrorwith a hint to setSENTRY_URLinstead of letting undici fail.packages/cli/test/lib/db/regions.focused.test.ts,packages/cli/test/lib/region.test.ts, andpackages/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 runThis PR was automatically generated by Sentry. You can adjust this setting at any time.