flashman
← All guides

Bearer token handling across proxy boundaries

Carry Bearer authentication safely across browsers, redirects, proxies, and services with explicit trust ownership, bounded headers, redacted logs, and tests.

2026-09-08 · 8 min read

  • authentication
  • http
  • security

Bearer credentials grant access to whoever possesses them, so transport and observability boundaries matter as much as token verification. A gateway can remove an Authorization header, a redirect can change its forwarding behavior, or an application can mistakenly trust an identity header supplied by the public client.

A secure architecture assigns authentication to a specific component and defines exactly what authenticated context crosses each internal boundary.

Choose one authentication ownership model

Either forward the bearer credential to a service that verifies it, or authenticate at the edge and send integrity-protected identity context through a trusted channel. Document the model per route instead of mixing assumptions.

  • Strip client-supplied internal identity headers at the edge.
  • Allowlist trusted proxy hops and authenticated upstreams.
  • Verify issuer, audience, signature, time, and token profile.
  • Authorize from verified claims, not from decoded content alone.

Control redirects and header forwarding

Avoid redirecting authenticated API requests when a direct canonical endpoint is available. Client libraries may remove credentials when the authority changes, while permissive custom redirect code can leak them to an unintended destination.

Define behavior for scheme, host, port, and path changes. Keep TLS across every bearer-token hop, and validate forwarded host and protocol metadata before using it to construct redirects.

Design safe limits and diagnostics

Set compatible request-header limits through CDN, proxy, server, and application layers. Return standards-based authentication challenges and stable internal error categories while keeping credentials out of logs, traces, analytics, crash reports, and URLs.

  • Record header presence and bounded length, not its value.
  • Use synthetic tokens for integration diagnostics.
  • Separate absent, malformed, invalid, expired, and forbidden cases.
  • Redact before data enters a telemetry pipeline.

Test the complete request path

Use Flashman's JWT tool only for synthetic token inspection, URL tool for authority and redirect checks, diff for proxy policies, timestamp converter for expiry fixtures, and JSON formatter for sanitized authentication events.

Test direct and proxied routes, same-authority and cross-authority redirects, header-size boundaries, duplicate headers, malformed schemes, key rotation, token expiry, gateway failover, logging failures, and attempts to inject internal identity fields.

Try these tools