mirror of
https://github.com/caddyserver/caddy.git
synced 2026-04-24 17:59:50 -04:00
Some checks failed
Tests / test (./cmd/caddy/caddy, ~1.26.0, ubuntu-latest, 0, 1.26, linux) (push) Failing after 1m51s
Tests / test (s390x on IBM Z) (push) Has been skipped
Tests / goreleaser-check (push) Has been skipped
Cross-Build / build (~1.26.0, 1.26, aix) (push) Successful in 1m41s
Cross-Build / build (~1.26.0, 1.26, darwin) (push) Successful in 1m37s
Cross-Build / build (~1.26.0, 1.26, dragonfly) (push) Successful in 1m30s
Cross-Build / build (~1.26.0, 1.26, freebsd) (push) Successful in 1m44s
Cross-Build / build (~1.26.0, 1.26, illumos) (push) Successful in 1m36s
Cross-Build / build (~1.26.0, 1.26, linux) (push) Successful in 1m36s
Cross-Build / build (~1.26.0, 1.26, netbsd) (push) Successful in 1m31s
Cross-Build / build (~1.26.0, 1.26, openbsd) (push) Successful in 1m42s
Cross-Build / build (~1.26.0, 1.26, solaris) (push) Successful in 1m47s
Cross-Build / build (~1.26.0, 1.26, windows) (push) Successful in 1m56s
Lint / lint (ubuntu-latest, linux) (push) Successful in 2m49s
Lint / govulncheck (push) Successful in 2m5s
Lint / dependency-review (push) Failing after 1m0s
OpenSSF Scorecard supply-chain security / Scorecard analysis (push) Failing after 42s
Tests / test (./cmd/caddy/caddy, ~1.26.0, macos-14, 0, 1.26, mac) (push) Has been cancelled
Tests / test (./cmd/caddy/caddy.exe, ~1.26.0, windows-latest, True, 1.26, windows) (push) Has been cancelled
Lint / lint (macos-14, mac) (push) Has been cancelled
Lint / lint (windows-latest, windows) (push) Has been cancelled
* admin: Redact sensitive request headers in API logs * Fix govulncheck and typed atomic lint failures * Sync Go module metadata after dependency downgrade
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package internal
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
// LoggableHTTPHeader makes an HTTP header loggable with zap.Object().
|
|
// Headers with potentially sensitive information (Cookie, Set-Cookie,
|
|
// Authorization, and Proxy-Authorization) are logged with empty values.
|
|
type LoggableHTTPHeader struct {
|
|
http.Header
|
|
|
|
ShouldLogCredentials bool
|
|
}
|
|
|
|
// MarshalLogObject satisfies the zapcore.ObjectMarshaler interface.
|
|
func (h LoggableHTTPHeader) MarshalLogObject(enc zapcore.ObjectEncoder) error {
|
|
if h.Header == nil {
|
|
return nil
|
|
}
|
|
for key, val := range h.Header {
|
|
if !h.ShouldLogCredentials {
|
|
switch strings.ToLower(key) {
|
|
case "cookie", "set-cookie", "authorization", "proxy-authorization":
|
|
val = []string{"REDACTED"} // see #5669. I still think ▒▒▒▒ would be cool.
|
|
}
|
|
}
|
|
enc.AddArray(key, LoggableStringArray(val))
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// LoggableStringArray makes a slice of strings marshalable for logging.
|
|
type LoggableStringArray []string
|
|
|
|
// MarshalLogArray satisfies the zapcore.ArrayMarshaler interface.
|
|
func (sa LoggableStringArray) MarshalLogArray(enc zapcore.ArrayEncoder) error {
|
|
if sa == nil {
|
|
return nil
|
|
}
|
|
for _, s := range sa {
|
|
enc.AppendString(s)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Interface guards
|
|
var (
|
|
_ zapcore.ObjectMarshaler = (*LoggableHTTPHeader)(nil)
|
|
_ zapcore.ArrayMarshaler = (*LoggableStringArray)(nil)
|
|
)
|