`.sentryclirc` with a self-hosted `url` refuses commands and SDK calls whose `SENTRY_URL`, `SENTRY_HOST` or `url` option names another server

Abierto
#2,582 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
22/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
nodejs, typescript

Línea de trabajo

Start with assertRcUrlTrusted in packages/cli/src/lib/sentryclirc.ts (around L422-457) and its call sites in packages/cli/src/lib/command.ts (L588-589, L895-898), then compare with the override handling in applySentryCliRcEnvShim (L398-408) and the existing mcp.ts host check (L419-429). Run the linked repro.mjs with a self-hosted .sentryclirc url and SENTRY_URL set. Done means the reproducer exits 0 for the runs that name the stand-in, while the token-trust and no-override refusals still hold.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Environment
  • sentry built from main at 5f11870fefae0818025715619f41a597607c4ef9 (sentry --version: 0.52.0-dev.0), and [email protected] from npm, which does the same
  • node v26.12.1 on win32 x64, and node v20.20.2, which does the same
Steps to Reproduce
  1. Write ~/.sentryclirc:
    [defaults]
    url=https://sentry.example.com
    
  2. Run sentry release view example-org/1.0.0 with SENTRY_AUTH_TOKEN set and SENTRY_URL naming another server (here a local stand-in for the Sentry API).
  3. Run it again with SENTRY_HOST naming that server instead of SENTRY_URL.
  4. Call createSentrySDK({ url, token }).release.view({ orgVersion: "example-org/1.0.0" }) with url naming that server.
  5. Repeat steps 2 to 4 with no ~/.sentryclirc, and with one whose url is https://sentry.io/.
Expected Result

Steps 2 to 4 send their requests to the server they name and show the release, as every run of step 5 does. With SENTRY_URL or SENTRY_HOST set (the SDK's url sets SENTRY_HOST), the .sentryclirc URL is not applied (applySentryCliRcEnvShim). I ask this only where an explicit override names where the requests go: SENTRY_URL, SENTRY_HOST or the SDK's url.

The check stays:

  • for a self-hosted .sentryclirc URL the CLI applies, with neither variable set;
  • for a .sentryclirc whose [auth] token becomes the token in use (L385-L396), so the file's token does not go to the server the environment names.

I leave the refusal of createSentrySDK({ token }) without url as it is: its requests would go to sentry.io (sdk-types.ts#L21-L26) while the file names another server, so that refusal flags a real conflict.

Actual Result

Steps 2, 3 and 4 each fail with exit code 13 (Host Scope) before sending any request. Step 2:

$ SENTRY_URL=http://127.0.0.1:62387 SENTRY_AUTH_TOKEN=example-token sentry release view example-org/1.0.0
Error: Config at <tmp>\home-self-hosted\.sentryclirc: https://sentry.example.com
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://127.0.0.1:62387).
To use this host, run: sentry auth login --url https://sentry.example.com
To keep using your current credentials, remove this URL override.
exit 13; requests the stand-in received: none

Step 4:

> createSentrySDK({ url: "http://127.0.0.1:62387", token: "example-token" }).release.view({ orgVersion: "example-org/1.0.0" })
Config at <tmp>\home-self-hosted\.sentryclirc: https://sentry.example.com
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://127.0.0.1:62387).
To use this host, run: sentry auth login --url https://sentry.example.com
To keep using your current credentials, remove this URL override.
exitCode 13
exit 13; requests the stand-in received: none

Every run of step 5 reaches the server and shows the release.

assertRcUrlTrusted checks the .sentryclirc URL whether or not the environment overrides it, and the command wrapper calls it before every command that does not opt out (L588-L589, L895-L898).

docs/operations/stdio-auth.md describes this refusal for sentry mcp as "the same check every CLI command applies", made "instead of sending any token to that host". With SENTRY_URL or SENTRY_HOST set, no request goes to that host: with a .sentryclirc naming sentry.io, step 5's requests go to the server the environment names. sentry mcp --host, which the same page says runs "as if SENTRY_URL were set", already skips the check (mcp.ts#L419-L429, from #1801), while its deprecation warning says to "use SENTRY_HOST instead" (mcp.ts#L403-L407, mcp/args.ts#L99-L109), which this check refuses. No test that expects the refusal sets SENTRY_URL or SENTRY_HOST.

#2538 (for #2537) trusts a .sentryclirc URL that matches the url claim of an sntrys_ token read from a .sentryclirc. It leaves this case as it was: the token here comes from the environment, and the SDK's token becomes SENTRY_AUTH_TOKEN as well (sdk-invoke.ts#L46-L49). #2580 meets the same refusal from the SDK, under a .sentryclirc above the repository root that sentry commands do not read.

Reproducer

https://gist.github.com/YevheniiKotyrlo/04b4403a8fcd7cec71b53ccd051615cc

It runs steps 2 to 5 in a temporary folder against a local stand-in for the Sentry API that records each request. Each run starts from the caller's environment without its SENTRY_* and GIT_* variables and sets its own: TMPDIR, TEMP and TMP (a folder inside the temporary folder), HOME and USERPROFILE (one of three home folders), SENTRY_CONFIG_DIR (a folder of its own), the step's SENTRY_URL or SENTRY_HOST with SENTRY_AUTH_TOKEN (or the SDK's url and token), and SENTRY_CLI_NO_TELEMETRY, SENTRY_CLI_NO_UPDATE_CHECK and NO_COLOR. The verdict depends on the home folder, the server named and the token. SENTRY_CONFIG_DIR keeps out a stored login, which would let the check pass, and the response cache; the last three keep telemetry, the update check and colour out of the runs. It exits 1 while a run that names the stand-in is refused (exit 13, or the refusal's words, with no request sent), 0 once those runs reach the stand-in, 2 when a step fails or the run ends another way. A .sentryclirc that sets url in a folder above the temporary folder would apply to every run, so the reproducer then stops with 2; point TMPDIR (TEMP and TMP on Windows) at a folder with none above it. It needs Node 20+, and no Sentry account.

node repro.mjs              # sentry@latest from npm
node repro.mjs 0.50.0       # a given version from npm
node repro.mjs <toolkit>    # a getsentry/toolkit checkout: runs `pnpm run bundle` in packages/cli first

Its result on main:

RESULT (exit 1): defect shows (sentry 0.52.0-dev.0 built from 5f11870fefae): the self-hosted .sentryclirc URL refused 3 of 3 runs that name another server (SENTRY_URL, SENTRY_HOST, createSentrySDK url), with no request sent; the runs without it reached the stand-in
Its whole output on main
node v26.12.1 on win32 x64

$ # sentry: getsentry/toolkit at 5f11870fefae0818025715619f41a597607c4ef9, no uncommitted changes
$ pnpm run bundle   # in packages/cli

$ sentry --version
0.52.0-dev.0

# HOME: no .sentryclirc
$ SENTRY_URL=http://127.0.0.1:62387 SENTRY_AUTH_TOKEN=example-token sentry release view example-org/1.0.0
Release 1.0.0
━━━━━━━━━━━━━

╭─────────────┬─────────────╮
│ Version     │ 1.0.0       │
│ Status      │ Unreleased  │
│ Created     │ Jan 1       │
│ Released    │ —           │
│ First Event │ —           │
│ Last Event  │ —           │
│ Ref         │ —           │
│ Commits     │ 0           │
│ Deploys     │ 0           │
│ New Issues  │ 0           │
│ Projects    │ example-app │
╰─────────────┴─────────────╯
exit 0; requests the stand-in received: GET /api/0/organizations/example-org/ -> 200, GET /api/0/organizations/example-org/releases/1.0.0/ -> 200

# HOME: .sentryclirc naming sentry.io (url=https://sentry.io/)
$ SENTRY_URL=http://127.0.0.1:62387 SENTRY_AUTH_TOKEN=example-token sentry release view example-org/1.0.0
Release 1.0.0
━━━━━━━━━━━━━

╭─────────────┬─────────────╮
│ Version     │ 1.0.0       │
│ Status      │ Unreleased  │
│ Created     │ Jan 1       │
│ Released    │ —           │
│ First Event │ —           │
│ Last Event  │ —           │
│ Ref         │ —           │
│ Commits     │ 0           │
│ Deploys     │ 0           │
│ New Issues  │ 0           │
│ Projects    │ example-app │
╰─────────────┴─────────────╯
exit 0; requests the stand-in received: GET /api/0/organizations/example-org/ -> 200, GET /api/0/organizations/example-org/releases/1.0.0/ -> 200

# HOME: .sentryclirc naming a self-hosted server (url=https://sentry.example.com)
$ SENTRY_URL=http://127.0.0.1:62387 SENTRY_AUTH_TOKEN=example-token sentry release view example-org/1.0.0
Error: Config at <tmp>\home-self-hosted\.sentryclirc: https://sentry.example.com
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://127.0.0.1:62387).
To use this host, run: sentry auth login --url https://sentry.example.com
To keep using your current credentials, remove this URL override.
exit 13; requests the stand-in received: none

# HOME: no .sentryclirc
$ SENTRY_HOST=http://127.0.0.1:62387 SENTRY_AUTH_TOKEN=example-token sentry release view example-org/1.0.0
Release 1.0.0
━━━━━━━━━━━━━

╭─────────────┬─────────────╮
│ Version     │ 1.0.0       │
│ Status      │ Unreleased  │
│ Created     │ Jan 1       │
│ Released    │ —           │
│ First Event │ —           │
│ Last Event  │ —           │
│ Ref         │ —           │
│ Commits     │ 0           │
│ Deploys     │ 0           │
│ New Issues  │ 0           │
│ Projects    │ example-app │
╰─────────────┴─────────────╯
exit 0; requests the stand-in received: GET /api/0/organizations/example-org/ -> 200, GET /api/0/organizations/example-org/releases/1.0.0/ -> 200

# HOME: .sentryclirc naming sentry.io (url=https://sentry.io/)
$ SENTRY_HOST=http://127.0.0.1:62387 SENTRY_AUTH_TOKEN=example-token sentry release view example-org/1.0.0
Release 1.0.0
━━━━━━━━━━━━━

╭─────────────┬─────────────╮
│ Version     │ 1.0.0       │
│ Status      │ Unreleased  │
│ Created     │ Jan 1       │
│ Released    │ —           │
│ First Event │ —           │
│ Last Event  │ —           │
│ Ref         │ —           │
│ Commits     │ 0           │
│ Deploys     │ 0           │
│ New Issues  │ 0           │
│ Projects    │ example-app │
╰─────────────┴─────────────╯
exit 0; requests the stand-in received: GET /api/0/organizations/example-org/ -> 200, GET /api/0/organizations/example-org/releases/1.0.0/ -> 200

# HOME: .sentryclirc naming a self-hosted server (url=https://sentry.example.com)
$ SENTRY_HOST=http://127.0.0.1:62387 SENTRY_AUTH_TOKEN=example-token sentry release view example-org/1.0.0
Error: Config at <tmp>\home-self-hosted\.sentryclirc: https://sentry.example.com
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://127.0.0.1:62387).
To use this host, run: sentry auth login --url https://sentry.example.com
To keep using your current credentials, remove this URL override.
exit 13; requests the stand-in received: none

# HOME: no .sentryclirc
> createSentrySDK({ url: "http://127.0.0.1:62387", token: "example-token" }).release.view({ orgVersion: "example-org/1.0.0" })
returned release 1.0.0
exit 0; requests the stand-in received: GET /api/0/organizations/example-org/ -> 200, GET /api/0/organizations/example-org/releases/1.0.0/ -> 200

# HOME: .sentryclirc naming sentry.io (url=https://sentry.io/)
> createSentrySDK({ url: "http://127.0.0.1:62387", token: "example-token" }).release.view({ orgVersion: "example-org/1.0.0" })
returned release 1.0.0
exit 0; requests the stand-in received: GET /api/0/organizations/example-org/ -> 200, GET /api/0/organizations/example-org/releases/1.0.0/ -> 200

# HOME: .sentryclirc naming a self-hosted server (url=https://sentry.example.com)
> createSentrySDK({ url: "http://127.0.0.1:62387", token: "example-token" }).release.view({ orgVersion: "example-org/1.0.0" })
Config at <tmp>\home-self-hosted\.sentryclirc: https://sentry.example.com
Refusing to route requests here because it doesn't match the host your Sentry credentials are for (http://127.0.0.1:62387).
To use this host, run: sentry auth login --url https://sentry.example.com
To keep using your current credentials, remove this URL override.
exitCode 13
exit 13; requests the stand-in received: none

RESULT (exit 1): defect shows (sentry 0.52.0-dev.0 built from 5f11870fefae): the self-hosted .sentryclirc URL refused 3 of 3 runs that name another server (SENTRY_URL, SENTRY_HOST, createSentrySDK url), with no request sent; the runs without it reached the stand-in
Lenguaje dominante
TypeScript
Estrellas
975
Forks
189
Merge medio
19 h 57 min
PR fusionados (30 d)
542

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de getsentry/toolkit

Todos los issues de getsentry/toolkit

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.