summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2020-07-17 17:54:58 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2020-07-17 17:54:58 -0600
commit246a31aacd7159acc009ff6d6497596a96533f73 (patch)
tree0cf0dbbec26b8f4e287c0f8808df2983398e10f3
parent0665a86eb72a178a42741d477b765169d7423fd8 (diff)
reverseproxy: Restore request's original host and header (fix #3509)
We already restore them within the retry loop, but after successful proxy we didn't reset them, so as handlers bubble back up, they would see the values used for proxying. Thanks to @ziddey for identifying the cause.
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 7971348..bb1453a 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -329,10 +329,17 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
fmt.Errorf("preparing request for upstream round-trip: %v", err))
}
- // we will need the original headers and Host
- // value if header operations are configured
- reqHeader := r.Header
+ // we will need the original headers and Host value if
+ // header operations are configured; and we should
+ // restore them after we're done if they are changed
+ // (for example, changing the outbound Host header
+ // should not permanently change r.Host; issue #3509)
reqHost := r.Host
+ reqHeader := r.Header
+ defer func() {
+ r.Host = reqHost
+ r.Header = reqHeader
+ }()
start := time.Now()