admin: redact sensitive request headers in API logs

The admin API handler was logging request headers using zap.Reflect,
which serializes the raw header map without any redaction. This could
expose sensitive headers like Cookie, Set-Cookie, Authorization, and
Proxy-Authorization in logs.

This change uses LoggableHTTPHeader instead, which redacts these
sensitive headers unless ShouldLogCredentials is explicitly enabled.
This is consistent with how headers are logged everywhere else in the
codebase.

Fixes #7566
This commit is contained in:
OpenClaw Agent 2026-03-30 04:43:45 +00:00
parent 30b80bece8
commit 2ad511c1fb

View file

@ -45,6 +45,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
)
// testCertMagicStorageOverride is a package-level test hook. Tests may set
@ -800,7 +802,7 @@ func (h adminHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
zap.String("uri", r.RequestURI),
zap.String("remote_ip", ip),
zap.String("remote_port", port),
zap.Reflect("headers", r.Header),
zap.Object("headers", caddyhttp.LoggableHTTPHeader{Header: r.Header}),
)
if r.TLS != nil {
log = log.With(