Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't override Host when forward-proxying - effectively preserving the transparent proxy approach #678

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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