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 cli@0.46.0) 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
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

`sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` is the form the
skill documents for looking up one endpoint. The positional was treated
as a resource name, so that string 404'd, and `--search` with a `GET `
prefix matched nothing because the path field does not contain the
method. Agents then fell through to `sentry api`.

Path-shaped input now resolves against the OpenAPI index: method + path
returns that endpoint's details, a bare `/api/0/...` lists the methods
on that URL, and `--search GET /path` (quoted or not) uses the same
matcher. `{param}` in the schema still matches a concrete slug; an
OpenAPI-style `{param}` in the query only matches a schema param, so
static siblings like `latest-base` are not swallowed.

Unknown resource names (`sentry schema issue`, typos) are unchanged —
they still go through the existing `ResolutionError` / did-you-mean
path.

## Test plan

- [ ] `sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` prints
`listOrganizationIssues` (exit 0)
- [ ] `sentry schema GET
/api/0/organizations/{organization_id_or_slug}/issues/` (unquoted) does
the same
- [ ] `sentry schema
/api/0/organizations/{organization_id_or_slug}/issues/` lists
GET/PUT/DELETE on that path only
- [ ] `sentry schema --search "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` returns that
one endpoint
- [ ] `sentry schema issues` and `sentry schema committers` are
unchanged
- [ ] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts` from
`packages/cli`


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

`sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` is the form the
skill documents for looking up one endpoint. The positional was treated
as a resource name, so that string 404'd, and `--search` with a `GET `
prefix matched nothing because the path field does not contain the
method. Agents then fell through to `sentry api`.

Path-shaped input now resolves against the OpenAPI index: method + path
returns that endpoint's details, a bare `/api/0/...` lists the methods
on that URL, and `--search GET /path` (quoted or not) uses the same
matcher. `{param}` in the schema still matches a concrete slug; an
OpenAPI-style `{param}` in the query only matches a schema param, so
static siblings like `latest-base` are not swallowed.

Unknown resource names (`sentry schema issue`, typos) are unchanged —
they still go through the existing `ResolutionError` / did-you-mean
path.

## Test plan

- [ ] `sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` prints
`listOrganizationIssues` (exit 0)
- [ ] `sentry schema GET
/api/0/organizations/{organization_id_or_slug}/issues/` (unquoted) does
the same
- [ ] `sentry schema
/api/0/organizations/{organization_id_or_slug}/issues/` lists
GET/PUT/DELETE on that path only
- [ ] `sentry schema --search "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` returns that
one endpoint
- [ ] `sentry schema issues` and `sentry schema committers` are
unchanged
- [ ] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts` from
`packages/cli`


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

`sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` is the form the
skill documents for looking up one endpoint. The positional was treated
as a resource name, so that string 404'd, and `--search` with a `GET `
prefix matched nothing because the path field does not contain the
method. Agents then fell through to `sentry api`.

Path-shaped input now resolves against the OpenAPI index: method + path
returns that endpoint's details, a bare `/api/0/...` lists the methods
on that URL, and `--search GET /path` (quoted or not) uses the same
matcher. `{param}` in the schema still matches a concrete slug; an
OpenAPI-style `{param}` in the query only matches a schema param, so
static siblings like `latest-base` are not swallowed.

Unknown resource names (`sentry schema issue`, typos) are unchanged —
they still go through the existing `ResolutionError` / did-you-mean
path.

## Test plan

- [ ] `sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` prints
`listOrganizationIssues` (exit 0)
- [ ] `sentry schema GET
/api/0/organizations/{organization_id_or_slug}/issues/` (unquoted) does
the same
- [ ] `sentry schema
/api/0/organizations/{organization_id_or_slug}/issues/` lists
GET/PUT/DELETE on that path only
- [ ] `sentry schema --search "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` returns that
one endpoint
- [ ] `sentry schema issues` and `sentry schema committers` are
unchanged
- [ ] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts` from
`packages/cli`


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

`sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` is the form the
skill documents for looking up one endpoint. The positional was treated
as a resource name, so that string 404'd, and `--search` with a `GET `
prefix matched nothing because the path field does not contain the
method. Agents then fell through to `sentry api`.

Path-shaped input now resolves against the OpenAPI index: method + path
returns that endpoint's details, a bare `/api/0/...` lists the methods
on that URL, and `--search GET /path` (quoted or not) uses the same
matcher. `{param}` in the schema still matches a concrete slug; an
OpenAPI-style `{param}` in the query only matches a schema param, so
static siblings like `latest-base` are not swallowed.

Unknown resource names (`sentry schema issue`, typos) are unchanged —
they still go through the existing `ResolutionError` / did-you-mean
path.

## Test plan

- [ ] `sentry schema "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` prints
`listOrganizationIssues` (exit 0)
- [ ] `sentry schema GET
/api/0/organizations/{organization_id_or_slug}/issues/` (unquoted) does
the same
- [ ] `sentry schema
/api/0/organizations/{organization_id_or_slug}/issues/` lists
GET/PUT/DELETE on that path only
- [ ] `sentry schema --search "GET
/api/0/organizations/{organization_id_or_slug}/issues/"` returns that
one endpoint
- [ ] `sentry schema issues` and `sentry schema committers` are
unchanged
- [ ] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts` from
`packages/cli`


Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

Agents sometimes pass an SDK/OpenAPI operation identifier directly, for
example `sentry schema listOrganizationEvents`. The CLI treated that as
a resource name and returned a `ResolutionError` even though the
endpoint was present in the generated schema.

A single positional now resolves an exact SDK function name or OpenAPI
operation ID and shows that endpoint. Matching stays exact so partial
names remain the job of `--search`; resource and METHOD + path lookup
behavior is unchanged.

Follow-up to getsentry#1613.

## Test plan

- [x] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts`
- [x] `pnpm --filter sentry run typecheck`
- [x] `pnpm --filter sentry run lint`
- [x] `pnpm --filter sentry run check:fragments`
- [x] `pnpm run cli schema listOrganizationEvents --json --fields
fn,method,path`
- [x] `pnpm run cli schema "Bulk Update Project Environments" --json
--fields fn,operationId,method,path`

Co-authored-by: Cursor <cursoragent@cursor.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

Agents sometimes pass an SDK/OpenAPI operation identifier directly, for
example `sentry schema listOrganizationEvents`. The CLI treated that as
a resource name and returned a `ResolutionError` even though the
endpoint was present in the generated schema.

A single positional now resolves an exact SDK function name or OpenAPI
operation ID and shows that endpoint. Matching stays exact so partial
names remain the job of `--search`; resource and METHOD + path lookup
behavior is unchanged.

Follow-up to getsentry#1613.

## Test plan

- [x] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts`
- [x] `pnpm --filter sentry run typecheck`
- [x] `pnpm --filter sentry run lint`
- [x] `pnpm --filter sentry run check:fragments`
- [x] `pnpm run cli schema listOrganizationEvents --json --fields
fn,method,path`
- [x] `pnpm run cli schema "Bulk Update Project Environments" --json
--fields fn,operationId,method,path`

Co-authored-by: Cursor <cursoragent@cursor.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

Agents sometimes pass an SDK/OpenAPI operation identifier directly, for
example `sentry schema listOrganizationEvents`. The CLI treated that as
a resource name and returned a `ResolutionError` even though the
endpoint was present in the generated schema.

A single positional now resolves an exact SDK function name or OpenAPI
operation ID and shows that endpoint. Matching stays exact so partial
names remain the job of `--search`; resource and METHOD + path lookup
behavior is unchanged.

Follow-up to getsentry#1613.

## Test plan

- [x] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts`
- [x] `pnpm --filter sentry run typecheck`
- [x] `pnpm --filter sentry run lint`
- [x] `pnpm --filter sentry run check:fragments`
- [x] `pnpm run cli schema listOrganizationEvents --json --fields
fn,method,path`
- [x] `pnpm run cli schema "Bulk Update Project Environments" --json
--fields fn,operationId,method,path`

Co-authored-by: Cursor <cursoragent@cursor.com>
joshuawayzwright pushed a commit to joshuawayzwright/sentry-mcp that referenced this pull request Nov 16, 2026
## Summary

Agents sometimes pass an SDK/OpenAPI operation identifier directly, for
example `sentry schema listOrganizationEvents`. The CLI treated that as
a resource name and returned a `ResolutionError` even though the
endpoint was present in the generated schema.

A single positional now resolves an exact SDK function name or OpenAPI
operation ID and shows that endpoint. Matching stays exact so partial
names remain the job of `--search`; resource and METHOD + path lookup
behavior is unchanged.

Follow-up to getsentry#1613.

## Test plan

- [x] `pnpm exec vitest run test/lib/api-schema.test.ts
test/commands/schema.test.ts test/commands/schema-path.test.ts`
- [x] `pnpm --filter sentry run typecheck`
- [x] `pnpm --filter sentry run lint`
- [x] `pnpm --filter sentry run check:fragments`
- [x] `pnpm run cli schema listOrganizationEvents --json --fields
fn,method,path`
- [x] `pnpm run cli schema "Bulk Update Project Environments" --json
--fields fn,operationId,method,path`

Co-authored-by: Cursor <cursoragent@cursor.com>

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