Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: scrub Set-Cookie header in debug logs #1190

Merged
merged 5 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions internal/trace/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ import (
"sync/atomic"
)

// requestCount records the number of logged request-response pairs and will
// be used as the unique id for the next pair.
var requestCount uint64
var (
// requestCount records the number of logged request-response pairs and will
// be used as the unique id for the next pair.
requestCount uint64

// toScrub is a set of headers that should be scrubbed from the log.
toScrub = []string{
"Authorization",
"Set-Cookie",
}
)

// Transport is an http.RoundTripper that keeps track of the in-flight
// request and add hooks to report HTTP tracing events.
Expand Down Expand Up @@ -68,8 +76,10 @@ func logHeader(header http.Header) string {
if len(header) > 0 {
headers := []string{}
for k, v := range header {
if strings.EqualFold(k, "Authorization") {
v = []string{"*****"}
for _, h := range toScrub {
if strings.EqualFold(k, h) {
v = []string{"*****"}
}
}
headers = append(headers, fmt.Sprintf(" %q: %q", k, strings.Join(v, ", ")))
}
Expand Down