summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/reverseproxy
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-12-02 15:26:24 -0500
committerGitHub <noreply@github.com>2021-12-02 13:26:24 -0700
commit5bf0adad8748e96e10529d5fc5777afc9236a7b5 (patch)
treeb26d766d1686f39d5d43847d4742782fa5524c4f /modules/caddyhttp/reverseproxy
parent8e5aafa5cdb0bd6ad062014172ed21fdc1012cc1 (diff)
caddyhttp: Make logging of credential headers opt-in (#4438)
Diffstat (limited to 'modules/caddyhttp/reverseproxy')
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index c629ef6..b418953 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -574,6 +574,9 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, repl *
// point the request to this upstream
h.directRequest(req, di)
+ server := req.Context().Value(caddyhttp.ServerCtxKey).(*caddyhttp.Server)
+ shouldLogCredentials := server.Logs != nil && server.Logs.ShouldLogCredentials
+
// do the round-trip; emit debug log with values we know are
// safe, or if there is no error, emit fuller log entry
start := time.Now()
@@ -582,14 +585,20 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, repl *
logger := h.logger.With(
zap.String("upstream", di.Upstream.String()),
zap.Duration("duration", duration),
- zap.Object("request", caddyhttp.LoggableHTTPRequest{Request: req}),
+ zap.Object("request", caddyhttp.LoggableHTTPRequest{
+ Request: req,
+ ShouldLogCredentials: shouldLogCredentials,
+ }),
)
if err != nil {
logger.Debug("upstream roundtrip", zap.Error(err))
return err
}
logger.Debug("upstream roundtrip",
- zap.Object("headers", caddyhttp.LoggableHTTPHeader(res.Header)),
+ zap.Object("headers", caddyhttp.LoggableHTTPHeader{
+ Header: res.Header,
+ ShouldLogCredentials: shouldLogCredentials,
+ }),
zap.Int("status", res.StatusCode))
// duration until upstream wrote response headers (roundtrip duration)