Skip to content

fix(cli): Send custom headers on unauthenticated requests only to logged-in hosts - #2548

Merged
BYK merged 2 commits into
mainfrom
fix/cli-custom-headers-unauth-login-only
Nov 27, 2026
Merged

BYK merged 2 commits into
mainfrom
fix/cli-custom-headers-unauth-login-only

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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.

via @BYK.

--

View Session [Sentry]

…ged-in hosts

The share lookup (`getSharedIssue`) and the OAuth device and setup-code
exchanges go out without a credential guard, so the custom-header trust
check fell back to the active credential's host. For an env token, and an
rc `sntrys_` token, that host comes from boot-time `SENTRY_URL`/`SENTRY_HOST`,
which a CI step that can write `$GITHUB_ENV` sets without reading the token.

Trust only this invocation's `auth login --url` anchor or a stored login on
the request's server. Authenticated requests keep checking the credential
that `assertCredentialScope` matched.

Fixes #2545

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 26, 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 Nov 26, 2026 11:50pm UTC
sentry-local Ready Ready Preview Nov 26, 2026 11:50pm UTC

Request Review

…s-unauth-login-only

# Conflicts:
#	packages/cli/src/lib/token-host.ts
@BYK
BYK merged commit 00c8810 into main Nov 27, 2026
30 checks passed
@BYK
BYK deleted the fix/cli-custom-headers-unauth-login-only branch November 27, 2026 00:07
BYK added a commit that referenced this pull request Nov 27, 2026
…in (#2559)

#2548 removed `isRequestOriginTrusted` while
#2519 still used it in the wizard's login check, so
`main` no longer builds.

This uses `isRequestOriginTrustedForContext` with
`getCredentialContext()`, the same check the removed helper did.
Behaviour doesn't change.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A2b65e7fbe80bb65b0774094cf19fc343 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A2b65e7fbe80bb65b0774094cf19fc343)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2b65e7fbe80bb65b0774094cf19fc343/?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>
BYK added a commit that referenced this pull request Nov 27, 2026
Gets `main` ready for a GitHub merge queue. #2548
removed `isRequestOriginTrusted`, then #2519 merged
still importing it and broke `main`. Each PR was fine on its own; a
merge queue tests them together. Same approach as getsentry/junior#4469
and getsentry/junior#4533.

Merge queue entries skip the per-project matrix. The `quality` job
typechecks, builds, and policy-checks the whole workspace instead, which
is what two PRs can break together. The `test` aggregator already
accepts the skipped jobs.

`SENTRY_AUTH_TOKEN` stays off the `quality` job on purpose: when it's
set, `@sentry/mcp-cloudflare`'s Vite plugin creates a Sentry release.

## Follow-up (admin)

After this merges, a toolkit admin adds a `merge_queue` rule to the
repo's `Default` ruleset (id 5058262), with Junior's values: SQUASH, max
5 entries to build, 1 to 5 entries to merge, 5 minute wait, ALLGREEN
grouping, 60 minute check timeout, and `test` as the required status.

First, confirm the Craft release bot (`sentry-release-bot`) is in the
ruleset's `bypass_actors`, because it pushes merge-backs straight to
`main`. No getsentry/security-as-code change is needed.

<!-- junior-request-attribution:start -->
via @BYK.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3A3843e79a6a769b421c483201d98d7d4e -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3A3843e79a6a769b421c483201d98d7d4e)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A3843e79a6a769b421c483201d98d7d4e/?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>

This branch was successfully deployed

2 active deployments
Preview – sentry-local — bc9a2347 Deployed Nov 26, 2026 by vercel[bot]
Preview – cli — bc9a2347 Deployed Nov 26, 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.

Shared-issue lookup can send SENTRY_CUSTOM_HEADERS to an env-injected host

1 participant