Skip to content

fix(cli): Validate regionUrl is absolute to prevent URL parsing errors - #1567

Merged
BYK merged 3 commits into
mainfrom
seer/fix/cli-region-url-validation
Sep 22, 2026
Merged

BYK merged 3 commits into
mainfrom
seer/fix/cli-region-url-validation

Conversation

@sentry

@sentry sentry Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Previously, resolveOrgRegionUncached in packages/cli/src/lib/region.ts would accept and cache a relative regionUrl if provided by a self-hosted Sentry instance (e.g., /). This relative URL, when subsequently used as a base for API calls, would lead to Failed to parse URL errors.

This change modifies the logic to explicitly validate that the regionUrl obtained from the API response is an absolute URL. If it's relative or malformed, the CLI now correctly falls back to the configured baseUrl and logs a debug message for diagnostic purposes.

New test cases have been added to packages/cli/test/lib/region.test.ts to cover scenarios where the API returns a relative or malformed regionUrl.

Fixes CLI-2DJ

@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 Sep 9, 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 22, 2026 1:53pm UTC
sentry-local Ready Ready Preview Sep 22, 2026 1:53pm UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – sentry-local September 9, 2026 10:47 Inactive
@sentry
sentry Bot marked this pull request as ready for review September 9, 2026 10:54
@sentry
sentry Bot requested a review from BYK September 9, 2026 10:54

@BYK BYK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would be better to convert the relative URL into an absolute URL as the fix

@BYK BYK removed the risk: medium label Sep 9, 2026
@github-actions github-actions Bot added the risk: low PR risk score: low label Sep 21, 2026
@betegon betegon added the jared Trigger the Jared agent to work on stuff label Sep 22, 2026

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

lgtm. the absolute-url check is the right fix: a relative regionUrl like "/" is truthy but breaks fetch when used as a base, and this correctly falls back to baseUrl for both the relative and malformed cases.

verified locally:

  • vitest run test/lib/region.test.ts — 25 passed, including the two new cases
  • biome check — clean

one minor note (non-blocking): when rawRegionUrl is falsy the fallback is silent (no debug log), which matches the prior behavior, so no change needed. logger usage matches the rest of the lib.

@betegon

betegon commented Sep 22, 2026

Copy link
Copy Markdown
Member

then do it jared

per review feedback, convert a relative regionUrl (e.g. "/" from a
self-hosted instance behind a reverse proxy) into an absolute URL by
resolving it against baseUrl, rather than dropping it and falling back.
already-absolute values are used verbatim; truly unparseable values still
fall back to baseUrl with a debug log.
@vercel
vercel Bot temporarily deployed to Preview – sentry-local September 22, 2026 11:44 Inactive
@jared-outpost

jared-outpost Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

done. switched the fix to resolve a relative regionUrl into an absolute one against baseUrl instead of discarding it, per @BYK's review:

  • already-absolute regionUrl → used verbatim
  • relative (e.g. / from a self-hosted instance behind a reverse proxy) → resolved against baseUrl to an absolute origin
  • unparseable → falls back to baseUrl with a debug log

added a test covering the relative→absolute resolution; all 25 region tests pass, biome clean. pushed as f065476.

@BYK

BYK commented Sep 22, 2026

Copy link
Copy Markdown
Member

Jared fix CI

@BYK
BYK enabled auto-merge (squash) September 22, 2026 13:21
@jared-outpost

jared-outpost Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

ci was failing on test/lib/org-list.test.ts > auto-paginates when limit exceeds API_MAX_PER_PAGE (expected perPage [100,100,100], got [100,100,50]). that assertion belongs to the pagination-budget change in #1606/#1615, which landed on main after this branch was cut — the branch was just stale, not broken by the regionUrl fix.

merged latest main into the branch (791579b). the previously-failing test now passes, and the region tests still pass (25/25). pushed; leaving the PR for the CI webhook to confirm green.

@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 791579b. Configure here.

throw response.error;
}

const regionUrl = response.data?.links?.regionUrl || baseUrl;

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.

Cached region URLs skip validation

Medium Severity

resolveOrgRegionUncached returns a cached regionUrl without running toAbsoluteRegionUrl. A relative value already stored in the region cache, or one written by listOrganizationsUncached, is still used as a fetch base and reproduces the original URL parse failure.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 791579b. Configure here.

@BYK
BYK merged commit 6391b7e into main Sep 22, 2026
35 of 36 checks passed
@BYK
BYK deleted the seer/fix/cli-region-url-validation branch September 22, 2026 14:01
@BYK

BYK commented Sep 22, 2026

Copy link
Copy Markdown
Member

Jared, fix this: #1567 (comment)

This branch was successfully deployed

2 active deployments
Preview – sentry-local 791579b9 Deployed Sep 22, 2026 by vercel[bot]
Preview – cli 791579b9 Deployed Sep 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

jared Trigger the Jared agent to work on stuff risk: low PR risk score: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants