Skip to content

feat(integrations): Add signed ViewerContext header propagation#112430

Draft
gricha wants to merge 1 commit intomasterfrom
gricha/feat/viewer-context-header-propagation
Draft

feat(integrations): Add signed ViewerContext header propagation#112430
gricha wants to merge 1 commit intomasterfrom
gricha/feat/viewer-context-header-propagation

Conversation

@gricha
Copy link
Copy Markdown
Member

@gricha gricha commented Apr 7, 2026

Add infrastructure for propagating ViewerContext across HTTP service
boundaries using HMAC-signed headers. This is part of the ViewerContext
RFC rollout.

When Sentry (or an internal service like Seer) makes an HTTP call to
another service, the active ViewerContext needs to cross the wire. This
PR adds the sending and receiving sides of that mechanism.

Sending side (viewer_context.py):

  • inject_viewer_context_headers(headers, secret, issuer) reads the
    contextvar, serializes to JSON, HMAC-signs with the caller's shared
    secret, and sets three headers: X-Viewer-Context,
    X-Viewer-Context-Signature, and X-Viewer-Context-Issuer.
  • ViewerContext.deserialize() classmethod for reconstructing from
    JSON payloads.

Receiving side (middleware/viewer_context.py):

  • ViewerContextMiddleware now checks for signed headers before
    falling back to request-based auth derivation.
  • Maps the issuer string to its known shared secret (sentry
    RPC_SHARED_SECRET, seerSEER_RPC_SHARED_SECRET, etc.).
  • Verifies the HMAC signature (with key rotation support). Unknown
    issuers or invalid signatures silently fall through to normal auth.
  • Documented inline with the full protocol and instructions for adding
    new services.

Security: external users cannot forge the header because they don't
have the shared secrets. The signature is verified before the payload
is trusted. This is the same trust model used for cross-silo RPC.

Add infrastructure for propagating ViewerContext across HTTP service
boundaries using signed headers.

Sending side: inject_viewer_context_headers() serializes the active
ViewerContext into X-Viewer-Context with an HMAC-SHA256 signature and
issuer identifier. Each internal service uses its own shared secret.

Receiving side: ViewerContextMiddleware checks for signed headers before
falling back to request-based auth. Maps the issuer to a known shared
secret, verifies the signature, and only then trusts the payload.
Unknown issuers or invalid signatures fall through to normal auth.

Includes ViewerContext.deserialize() classmethod for reconstructing
from JSON payloads.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant