Skip to content

Restore Forwarded header in reverse proxy Rewrite mode - #575

Open
lodener wants to merge 1 commit into
cloudfoundry:developfrom
lodener:develop
Open

Restore Forwarded header in reverse proxy Rewrite mode#575
lodener wants to merge 1 commit into
cloudfoundry:developfrom
lodener:develop

Conversation

@lodener

@lodener lodener commented Jul 24, 2026

Copy link
Copy Markdown

Summary

The standard RFC 7239 Forwarded header was being silently dropped by gorouter and never reaching backend apps.

The cause is the switch from the deprecated ReverseProxy.Director to ReverseProxy.Rewrite in ebe6fed (#573), done for Go 1.26 staticcheck compliance. Go's Rewrite mode strips Forwarded, X-Forwarded-For, X-Forwarded-Host, and X-Forwarded-Proto from the outbound request before it calls the rewrite func (see outreq.Header.Del("Forwarded") in net/http/httputil/reverseproxy.go). Director mode never stripped any of these. That commit put back the three X-Forwarded-* headers but missed Forwarded, so client-set Forwarded headers stopped getting
forwarded.

This change copies Forwarded from the inbound request to the outbound request as-is, keeping multiple header values intact per RFC 7239. It follows the same restore logic already used for the X-Forwarded-* headers in proxy/proxy.go. It also adds regression tests for a single value, multiple values, and the case where the client sends no header.

Backward Compatibility

Breaking Change? No

This puts back the pass-through behavior that existed before ebe6fed (#573), so it returns gorouter to how it used to work rather than adding new behavior. It is a plain verbatim pass-through with no new config, applies right away to all deployments, and needs no opt-in.

The migration from ReverseProxy.Director to Rewrite in ebe6fed
(cloudfoundry#573) restored X-Forwarded-For, X-Forwarded-Host, and
X-Forwarded-Proto, but missed the RFC 7239 Forwarded header.

Rewrite mode strips Forwarded, X-Forwarded-For, X-Forwarded-Host,
and X-Forwarded-Proto from the outbound request before calling the
Rewrite func. Director never stripped any of these, so client-set
Forwarded headers now get dropped.

Copy Forwarded from the inbound request verbatim, preserving
multiple header values, to match the previous pass-through
behavior. Add regression tests covering single value, multiple
values, and the absent-header case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant