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

Aperta
#2,582 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
TypeScript
Stelle
975
Fork
189
Merge medio
19h 57m
PR unite (30g)
542

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/toolkit

Tutte le issue di getsentry/toolkit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.