From 687b51eda90b41dc142594dc272c984abd896fc8 Mon Sep 17 00:00:00 2001 From: Amelia Downs Date: Tue, 7 Jul 2026 10:46:42 -0400 Subject: [PATCH 1/3] fix staticcheck SA1019/SA4023 failures for Go 1.26 - Replace deprecated ReverseProxy.Director with Rewrite in proxy/proxy.go - Replace deprecated ReverseProxy.Director with Rewrite in integration/route_services_test.go - Remove always-true nil check in route_fetcher/route_fetcher.go (SA4023) --- .../gorouter/integration/route_services_test.go | 8 ++++---- src/code.cloudfoundry.org/gorouter/proxy/proxy.go | 4 +++- .../gorouter/route_fetcher/route_fetcher.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/code.cloudfoundry.org/gorouter/integration/route_services_test.go b/src/code.cloudfoundry.org/gorouter/integration/route_services_test.go index a144ea08c..bbccfd4a9 100644 --- a/src/code.cloudfoundry.org/gorouter/integration/route_services_test.go +++ b/src/code.cloudfoundry.org/gorouter/integration/route_services_test.go @@ -94,8 +94,8 @@ var _ = Describe("Route services", func() { wsRouteService = httptest.NewUnstartedServer( &httputil.ReverseProxy{ - Director: func(req *http.Request) { - forwardedURLStr := req.Header.Get("X-Cf-Forwarded-Url") + Rewrite: func(r *httputil.ProxyRequest) { + forwardedURLStr := r.Out.Header.Get("X-Cf-Forwarded-Url") forwardedURL, err := url.Parse(forwardedURLStr) if err != nil { @@ -103,11 +103,11 @@ var _ = Describe("Route services", func() { return } - req.URL = &url.URL{ + r.Out.URL = &url.URL{ Scheme: "http", Host: fmt.Sprintf("127.0.0.1:%d", testState.cfg.Port), } - req.Host = forwardedURL.Host + r.Out.Host = forwardedURL.Host }, Transport: &http.Transport{ TLSClientConfig: &tls.Config{ diff --git a/src/code.cloudfoundry.org/gorouter/proxy/proxy.go b/src/code.cloudfoundry.org/gorouter/proxy/proxy.go index 6c1d9721e..46413b8b5 100644 --- a/src/code.cloudfoundry.org/gorouter/proxy/proxy.go +++ b/src/code.cloudfoundry.org/gorouter/proxy/proxy.go @@ -140,7 +140,9 @@ func NewProxy( ) rproxy := &httputil.ReverseProxy{ - Director: p.setupProxyRequest, + Rewrite: func(r *httputil.ProxyRequest) { + p.setupProxyRequest(r.Out) + }, Transport: prt, FlushInterval: 50 * time.Millisecond, BufferPool: p.bufferPool, diff --git a/src/code.cloudfoundry.org/gorouter/route_fetcher/route_fetcher.go b/src/code.cloudfoundry.org/gorouter/route_fetcher/route_fetcher.go index 6a0f86b64..cbbc66204 100644 --- a/src/code.cloudfoundry.org/gorouter/route_fetcher/route_fetcher.go +++ b/src/code.cloudfoundry.org/gorouter/route_fetcher/route_fetcher.go @@ -117,7 +117,7 @@ func (r *RouteFetcher) startEventCycle() { return } err = r.subscribeToEvents(token) - if err != nil && err.Error() == "unauthorized" { + if err.Error() == "unauthorized" { forceUpdate = true } else { forceUpdate = false From 30e4d3b150376534db526e42c9fc7c8710ac26c1 Mon Sep 17 00:00:00 2001 From: Amelia Downs Date: Tue, 7 Jul 2026 11:15:48 -0400 Subject: [PATCH 2/3] fix(proxy): restore X-Forwarded-* headers in Rewrite mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rewrite mode (replacing deprecated Director) strips X-Forwarded-For and X-Forwarded-Proto from r.Out before invoking the Rewrite func. Director mode never stripped these — it appended to X-Forwarded-For automatically and left X-Forwarded-Proto (set by the middleware) intact. Explicitly restore both headers to replicate the old behavior: - X-Forwarded-Proto: copied from r.In where the XForwardedProto middleware already set the correct value. - X-Forwarded-For: rebuilt from the incoming header plus the client IP from r.In.RemoteAddr, matching the append logic Director used. --- src/code.cloudfoundry.org/gorouter/proxy/proxy.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/code.cloudfoundry.org/gorouter/proxy/proxy.go b/src/code.cloudfoundry.org/gorouter/proxy/proxy.go index 46413b8b5..cb562ea2f 100644 --- a/src/code.cloudfoundry.org/gorouter/proxy/proxy.go +++ b/src/code.cloudfoundry.org/gorouter/proxy/proxy.go @@ -142,6 +142,20 @@ func NewProxy( rproxy := &httputil.ReverseProxy{ Rewrite: func(r *httputil.ProxyRequest) { p.setupProxyRequest(r.Out) + // Rewrite mode strips X-Forwarded-* from r.Out before calling this + // function. Restore them to replicate the behavior Director had: + // - X-Forwarded-Proto: copy the value already set by the XForwardedProto middleware. + // - X-Forwarded-For: append the client IP from r.In.RemoteAddr. + if proto := r.In.Header.Get("X-Forwarded-Proto"); proto != "" { + r.Out.Header.Set("X-Forwarded-Proto", proto) + } + if clientIP, _, err := net.SplitHostPort(r.In.RemoteAddr); err == nil { + if prior := r.In.Header.Get("X-Forwarded-For"); prior != "" { + r.Out.Header.Set("X-Forwarded-For", prior+", "+clientIP) + } else { + r.Out.Header.Set("X-Forwarded-For", clientIP) + } + } }, Transport: prt, FlushInterval: 50 * time.Millisecond, From f23092587ce05eb606f0423ca2dab48352a9d154 Mon Sep 17 00:00:00 2001 From: Amelia Downs Date: Tue, 7 Jul 2026 11:31:26 -0400 Subject: [PATCH 3/3] fix(proxy): also restore X-Forwarded-Host in Rewrite mode X-Forwarded-Host is also stripped by Rewrite mode. Copy it from r.In to r.Out to preserve client-supplied values, matching Director behavior. --- src/code.cloudfoundry.org/gorouter/proxy/proxy.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/code.cloudfoundry.org/gorouter/proxy/proxy.go b/src/code.cloudfoundry.org/gorouter/proxy/proxy.go index cb562ea2f..5c4b0e9cc 100644 --- a/src/code.cloudfoundry.org/gorouter/proxy/proxy.go +++ b/src/code.cloudfoundry.org/gorouter/proxy/proxy.go @@ -145,10 +145,14 @@ func NewProxy( // Rewrite mode strips X-Forwarded-* from r.Out before calling this // function. Restore them to replicate the behavior Director had: // - X-Forwarded-Proto: copy the value already set by the XForwardedProto middleware. + // - X-Forwarded-Host: preserve whatever the client/middleware set. // - X-Forwarded-For: append the client IP from r.In.RemoteAddr. if proto := r.In.Header.Get("X-Forwarded-Proto"); proto != "" { r.Out.Header.Set("X-Forwarded-Proto", proto) } + if host := r.In.Header.Get("X-Forwarded-Host"); host != "" { + r.Out.Header.Set("X-Forwarded-Host", host) + } if clientIP, _, err := net.SplitHostPort(r.In.RemoteAddr); err == nil { if prior := r.In.Header.Get("X-Forwarded-For"); prior != "" { r.Out.Header.Set("X-Forwarded-For", prior+", "+clientIP)