Skip to content

feat(custom-headers): add SENTRY_CUSTOM_HEADERS for self-hosted proxy auth#761

Open
BYK wants to merge 3 commits intomainfrom
byk/feat-custom-headers
Open

feat(custom-headers): add SENTRY_CUSTOM_HEADERS for self-hosted proxy auth#761
BYK wants to merge 3 commits intomainfrom
byk/feat-custom-headers

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Apr 15, 2026

Summary

Adds support for injecting custom HTTP headers into all requests to self-hosted Sentry instances behind reverse proxies (e.g., Google IAP, Cloudflare Access).

  • SENTRY_CUSTOM_HEADERS env var — for CI/scripting overrides
  • sentry cli defaults headers — for persistent local configuration

Format: semicolon-separated Name: Value pairs (newlines also accepted as separators).

Self-hosted only

Custom headers are only applied when targeting a self-hosted instance (SENTRY_HOST/SENTRY_URL is set to a non-*.sentry.io URL). When configured on SaaS, headers are ignored with a one-time warning.

Injection points

Headers are injected at all three request paths to the Sentry server:

  1. Authenticated API requestsprepareHeaders() in sentry-client.ts
  2. OAuth device flowfetchWithConnectionError() in oauth.ts (fixes the login error from the issue)
  3. Shared issue resolutiongetSharedIssue() in api/issues.ts

Resolution priority

SENTRY_CUSTOM_HEADERS env var > defaults.headers in SQLite > none

Reserved headers

Authorization, Host, Content-Type, Content-Length, User-Agent, sentry-trace, baggage — these are managed by the CLI and cannot be overridden.

Usage

# Set via defaults (persistent)
sentry cli defaults headers "X-IAP-Token: abc123"

# Or via env var (CI/scripting)
SENTRY_CUSTOM_HEADERS="X-IAP-Token: abc123; X-Forwarded-For: 10.0.0.1"

# View current headers
sentry cli defaults headers

# Clear
sentry cli defaults headers --clear

Closes #759

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 15, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (custom-headers) Add SENTRY_CUSTOM_HEADERS for self-hosted proxy auth by BYK in #761
  • (init) Pre-supply existingSentry to eliminate roundtrip by betegon in #755

Bug Fixes 🐛

  • (arg-parsing) Normalize spaces in slugs and trim whitespace in issue IDs (CLI-14M, CLI-16M) by BYK in #757
  • (search) Rewrite OR queries to in-list syntax across all --query commands (CLI-16J) by BYK in #758
  • (upgrade) Retry spawn on EBUSY for Windows Defender file locking (CLI-16E) by BYK in #756

Internal Changes 🔧

  • (time-range) Parse --period at flag level via parsePeriod by BYK in #760
  • Regenerate docs by github-actions[bot] in 34bf056d

🤖 This preview updates automatically when you update the PR.

@BYK BYK marked this pull request as ready for review April 15, 2026 22:23
Comment thread src/lib/env-registry.ts Outdated
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8daba02. Configure here.

Comment thread src/lib/db/defaults.ts
BYK added 3 commits April 15, 2026 22:38
… auth

Add support for injecting custom HTTP headers into all requests to
self-hosted Sentry instances behind reverse proxies (e.g., Google IAP,
Cloudflare Access).

Two mechanisms are provided:
- `SENTRY_CUSTOM_HEADERS` env var for CI/scripting
- `sentry cli defaults headers` for persistent local config

Format: semicolon-separated `Name: Value` pairs (newlines also work).
Headers are only applied when targeting self-hosted instances; ignored
with a warning on SaaS (*.sentry.io).

Custom headers are injected at three request paths:
- Authenticated API requests (via prepareHeaders in sentry-client.ts)
- OAuth device flow (via fetchWithConnectionError in oauth.ts)
- Shared issue resolution (via getSharedIssue in api/issues.ts)

Closes #759
…DERS example

The example field should contain only the value, not the variable name,
since the doc generator produces `export ${name}=${example}`.
The DefaultsState type now includes `headers`, so toEqual assertions
need the field to pass strict deep equality checks.
@BYK BYK force-pushed the byk/feat-custom-headers branch from 22840e3 to 734f86d Compare April 15, 2026 22:38
@github-actions
Copy link
Copy Markdown
Contributor

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-761/

Built to branch gh-pages at 2026-04-15 22:38 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

Codecov Results 📊

134 passed | Total: 134 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 96.10%. Project has 1639 uncovered lines.
✅ Project coverage is 95.45%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
src/lib/oauth.ts 54.55% ⚠️ 5 Missing
src/lib/db/defaults.ts 92.31% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.45%    95.45%        —%
==========================================
  Files          236       237        +1
  Lines        35923     36049      +126
  Branches         0         0         —
==========================================
+ Hits         34290     34410      +120
- Misses        1633      1639        +6
- Partials         0         0         —

Generated by Codecov Action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow adding custom header to all requests

1 participant