Skip to content

Commit

Permalink
fix: redact query of location header (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl authored Feb 20, 2025
1 parent b546637 commit 04d5c5b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions logrusx/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,23 @@ func (l *Logger) HTTPHeadersRedacted(h http.Header) map[string]interface{} {
headers := map[string]interface{}{}

for key, value := range h {
keyLower := strings.ToLower(key)
if keyLower == "authorization" || keyLower == "cookie" || keyLower == "set-cookie" || keyLower == "x-session-token" {
switch keyLower := strings.ToLower(key); keyLower {
case "authorization", "cookie", "set-cookie", "x-session-token":
headers[keyLower] = l.maybeRedact(value)
} else {
case "location":
locationURL, err := url.Parse(h.Get("Location"))
if err != nil {
headers[keyLower] = l.maybeRedact(value)
continue
}
if l.leakSensitive {
headers[keyLower] = locationURL.String()
} else {
locationURL.RawQuery = ""
locationURL.Fragment = ""
headers[keyLower] = locationURL.Redacted()
}
default:
headers[keyLower] = h.Get(key)
}
}
Expand Down

0 comments on commit 04d5c5b

Please sign in to comment.