DEV Community

Ioneyrezende
Ioneyrezende

Posted on

Proxy-Authorization belongs to the proxy, not the application

Proxy-Authorization belongs to the proxy, not the application

HTTP has two related authentication headers with different scopes. Authorization identifies the client to the origin resource. Proxy-Authorization identifies the client to a proxy. The names are close enough that a chain of reverse proxies and application gateways can blur them.

RFC 9110 describes Proxy-Authorization as applying to the next inbound proxy that requested authentication. When multiple proxies are present, the first inbound proxy that expects the credentials consumes them. A proxy may relay them to the next proxy if that is how the proxies cooperatively authenticate, but it is not a general requirement to pass them to the origin application. That distinction is the core of the boundary.

A common design puts an authenticated gateway in front of an application. The gateway verifies a session or an access token and then adds identity headers for the application. If the gateway also accepts arbitrary inbound Proxy-Authorization, Authorization, and X-Forwarded-* headers from the internet, the app may be confused about which identity is authoritative. A client could send a proxy credential to the gateway while the gateway treats another header as the user.

The reverse direction has the same problem. If the application forwards its own proxy credential to an upstream service, the upstream may log it or apply it to the wrong hop. Credentials should be injected by the component that owns the connection to that proxy. They should not be copied from an incoming request or stored in a generic proxy header.

Use explicit header handling at every boundary. Strip hop-by-hop and proxy authentication headers at the public ingress. Add the correct outbound proxy credential only in the egress client. Never log either header in full. Keep a distinct credential per proxy realm and rotate it when a route changes. If the architecture uses an HTTP CONNECT tunnel, document whether the proxy sees the tunnel setup, the origin TLS session, or both.

The application should also decide whether a direct request is allowed to look like a proxied request. Trusting an X-Forwarded-For or a custom user header without a mTLS or network proof is a familiar mistake. The same principle applies to proxy authorization: a header is data unless a trusted transport authenticates its origin.

During testing, send a request with a forged Proxy-Authorization header, a forged Authorization header, and conflicting forwarded identities. Verify the gateway rejects or normalizes each case. Then inspect upstream logs to confirm no credential is present. A header that is harmless in one route can become an identity source in another.

Proxy credentials are credentials. Treat them as hop-scoped secrets with the same care as origin tokens, and make the routing decision visible in code and configuration.

References

Top comments (0)