Restore Forwarded header in reverse proxy Rewrite mode - #575
Open
lodener wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The standard RFC 7239
Forwardedheader was being silently dropped by gorouter and never reaching backend apps.The cause is the switch from the deprecated
ReverseProxy.DirectortoReverseProxy.Rewritein ebe6fed (#573), done for Go 1.26 staticcheck compliance. Go'sRewritemode stripsForwarded,X-Forwarded-For,X-Forwarded-Host, andX-Forwarded-Protofrom the outbound request before it calls the rewrite func (seeoutreq.Header.Del("Forwarded")innet/http/httputil/reverseproxy.go).Directormode never stripped any of these. That commit put back the threeX-Forwarded-*headers but missedForwarded, so client-setForwardedheaders stopped gettingforwarded.
This change copies
Forwardedfrom 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 theX-Forwarded-*headers inproxy/proxy.go. It also adds regression tests for a single value, multiple values, and the case where the client sends no header.net/http/httputilReverseProxy.Rewritestrips forwarding headers before calling the rewrite funcBackward 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.