Repository navigation
fix(cli): Trust a .sentryclirc url that matches its org token's claim - #2538
Conversation
A `sntrys_` org auth token that the `.sentryclirc` shim injects is now scoped to the server named in its own `url` claim, so a self-hosted rc `url` that matches the claim passes the host check. A `url` for any other host is still refused, as are opaque rc tokens with a self-hosted `url`. `SENTRY_CUSTOM_HEADERS` keep the host they had before (the boot `SENTRY_HOST`/`SENTRY_URL`, else SaaS), so they never reach a host that only the rc file names. Fixes #2537 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
…t host The authenticated fetch applied `SENTRY_CUSTOM_HEADERS` when the request matched the credential's host. For a `.sentryclirc` `sntrys_` token that host is now its claim, which the rc file chose, so a forged token with a matching rc url would have received the headers. `prepareHeaders` now uses the same rule as `isRequestOriginTrustedForCustomHeaders`: an rc claim-scoped token is checked against its boot host.
BYK
left a comment
There was a problem hiding this comment.
Based on the threat model, (let's assume GitHub Actions with a fork etc), is the env var safe? I think anyone can drop an env var in a subsequent stage by writing into $GITHUB_ENV or something?
|
@BYK Short answer: the token stays safe. The custom headers have one narrow gap, and this PR doesn't widen it. Token. An injected Custom headers on authenticated requests. These are safe for the same reason. Custom headers on unauthenticated requests. For a claim-scoped rc token, custom headers are checked against the boot env host. That's the same host the rc token was scoped to before this PR, so nothing new is exposed. The one path that sends them without the credential guard is the unauthenticated shared-issue lookup ( Tracking. The |
…ged-in hosts (#2548) Fixes #2545. `getSharedIssue` sends no bearer token, so `assertCredentialScope` never runs on it. Its custom-header check (`isRequestOriginTrustedForCustomHeaders`) fell back to the active credential's host. For an env token, and for an rc `sntrys_` token, that host is the boot-time `SENTRY_URL`/`SENTRY_HOST`. A CI step that can write `$GITHUB_ENV` can set that without reading the token, so a later `sentry issue view <share-url>` for its host would send it `SENTRY_CUSTOM_HEADERS`. `isRequestOriginTrustedForCustomHeaders` is now the check for every request that has no credential guard. It trusts only: - this invocation's login trust anchor (`sentry auth login --url`), or - a usable stored login on the request's server (`hasStoredAccountForHost`). It no longer looks at the active credential, so env and rc tokens are both covered. `isRequestOriginTrusted` was only used by the old branch, so this removes it. **Paths that use this check** (all callers of `applyCustomHeaders` that don't pass their own trust): - `getSharedIssue` (`lib/api/issues.ts`): the reported path. - OAuth device code and token polling, and the setup-code exchange (`lib/oauth.ts`), when there's no `--url` anchor. These were already behind the login host guard (`isLoginHostTrusted` / `isAutoLoginHostTrusted`). With `auth login --url`, the anchor still trusts the host. - `sentry api` pagination (`commands/api.ts`) calls it only to build a cache-key fingerprint. Nothing is sent there. The real request goes through the authenticated transport. **Not changed:** authenticated requests (`sentry-client.ts` `prepareHeaders`) still pass trust from the credential that `assertCredentialScope` matched, through #2538's `isRequestOriginTrustedForCustomHeadersInContext`, so rc `sntrys_` tokens keep its boot-host rule there. Token refresh (`refreshAccessToken`) still trusts the stored credential host. Agent handoff still uses its own host guard (`isAutoLoginHostTrusted`). **Behavior change:** if you're behind IAP or a proxy and only set `SENTRY_URL`/`SENTRY_HOST` with an env or `.sentryclirc` token, the share-link lookup in `sentry issue view <share-url>` no longer gets custom headers. To get them, run `sentry auth login --url <your-url>` once. The self-hosted docs now say this. Authenticated commands against the token's host still send the headers. The docs change went into `apps/cli-docs/src/content/docs/self-hosted.md`, the hand-written IAP section, because neither file under `apps/cli-docs/src/fragments/` covers custom headers. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A4dd9ae661b8a199ef3fb06c8525c3907 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A4dd9ae661b8a199ef3fb06c8525c3907) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A4dd9ae661b8a199ef3fb06c8525c3907/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
Fixes #2537
A project
.sentryclircthat holds ansntrys_org auth token and the self-hostedurlit was issued for (whatsentry wizardwrites) was refused by every command. The env-token host snapshot is taken at boot, before the rc shim injects the token, so the rc token fell back to SaaS and never matched its own server.The shim now scopes an injected
sntrys_token to its embeddedurlclaim (scopeRcTokenToClaiminenv-token-host.ts).assertRcUrlTrustedand the fetch guard then compare against that claim with the existingisHostTrustedrules. An rcurlfor any other host is still refused. Opaque rc tokens, env tokens, and stored logins keep today's behavior. The rc token also doesn't become an env account (getTrustedEnvTokenHostis unchanged), and the rc shim still doesn't register a login trust anchor.sentry mcpnow serves such a token too; the test that pinned the old refusal is updated.Threat model. The attacker can write or append to a
.sentryclirc, or add a project-level one under a global rc that holds the token, but can't read the token. The rcurlis compared against the claim inside the token, never against anything else in the file, so changing only theurlcan't redirect an existing token. A "url and token come from the same file" rule would not be safe, because an append-only write puts the attacker'surlin the token's file.SENTRY_CUSTOM_HEADERScome from the user's env, so for a claim-scoped rc token they are checked against the host the token had before this change (the bootSENTRY_HOST/SENTRY_URL, else SaaS). A host that only the rc file names never gets them.Trade-off: a self-hosted IAP setup that relies on
SENTRY_CUSTOM_HEADERSwith only an rcurlstill gets no custom headers. It needsSENTRY_URLin the env orsentry auth login --url, as today.via @BYK.
--
View Session [Sentry]