From d91f2177f7690ca6011df4f42c94ecfe20d71ba4 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 23 Nov 2020 12:01:53 -0700 Subject: [PATCH] add debug Printf --- internal/http01proxy/proxy.go | 15 +++++++++++++-- internal/mgmt/route.go | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/internal/http01proxy/proxy.go b/internal/http01proxy/proxy.go index bd1f8a4..6f8ec83 100644 --- a/internal/http01proxy/proxy.go +++ b/internal/http01proxy/proxy.go @@ -1,6 +1,7 @@ package http01proxy import ( + "log" "net/http" "net/http/httputil" "net/url" @@ -24,14 +25,24 @@ func ListenAndServe(target string, timeout time.Duration) error { req.Header.Del("X-Forwarded-For") req.Header.Del("X-Forwarded-Proto") req.Header.Del("X-Forwarded-Port") + req.Header.Del("X-Forwarded-Host") + + // We want the incoming host header to remain unchanged, + // which is the domain name that is being challenged + log.Printf("[debug] Incoming Host: %q", req.Header.Get("Host")) + req.Header.Set("X-Forwarded-Host", req.Header.Get("Host")) targetQuery := targetURL.RawQuery req.URL.Scheme = targetURL.Scheme + // But we want the proxy target to be updated to the new target req.URL.Host = targetURL.Host - req.Host = targetURL.Host - //req.Header.Set("Host", targetURL.Host) + //req.Host = targetURL.Host req.URL.Path, req.URL.RawPath = joinURLPath(targetURL, req.URL) + log.Printf("[debug] Target Host: %q", req.URL.Host) + log.Printf("[debug] Target Path: %q", req.URL.Path) + log.Printf("[debug] Target RawPath: %q", req.URL.Path) + if targetQuery == "" || req.URL.RawQuery == "" { req.URL.RawQuery = targetQuery + req.URL.RawQuery } else { diff --git a/internal/mgmt/route.go b/internal/mgmt/route.go index 1196c9b..b54b7c3 100644 --- a/internal/mgmt/route.go +++ b/internal/mgmt/route.go @@ -44,6 +44,12 @@ func RouteStatic(r chi.Router) chi.Router { func getACMEChallenges(w http.ResponseWriter, r *http.Request) { //token := chi.URLParam(r, "token") host := r.Host + xHost := r.Header.Get("X-Forwarded-Host") + fmt.Printf("[debug] Host: %q\n[debug] X-Host: %q", host, xHost) + if len(xHost) > 0 { + // TODO TrustProxy option? + host = xHost + } if strings.ContainsAny(host, "/:|\\") { host = "" }