Skip to content

Commit

Permalink
dont override Host when forward-proxying
Browse files Browse the repository at this point in the history
Signed-off-by: Or Koren <[email protected]>
  • Loading branch information
Or Koren committed Jun 27, 2023
1 parent de8e9e0 commit 543c124
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions interceptor/request_forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ func forwardRequest(
) {
proxy := httputil.NewSingleHostReverseProxy(fwdSvcURL)
proxy.Transport = roundTripper
superDirector := proxy.Director
proxy.Director = func(req *http.Request) {
superDirector(req)
req.URL = fwdSvcURL
req.Host = fwdSvcURL.Host
req.URL.Path = r.URL.Path
req.URL.RawQuery = r.URL.RawQuery
// delete the incoming X-Forwarded-For header so the proxy
// puts its own in. This is also important to prevent IP spoofing
req.Header.Del("X-Forwarded-For ")
req.Header.Del("Forwarded")
req.Header.Del("X-Forwarded-For")
req.Header.Del("X-Forwarded-Host")
req.Header.Del("X-Forwarded-Proto")
}
proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
w.WriteHeader(502)
Expand Down

0 comments on commit 543c124

Please sign in to comment.