Skip to content

Commit

Permalink
Redact the Authorization header for safer sharing
Browse files Browse the repository at this point in the history
This redacts the Authorization header, but shows whether a
Basic or Bearer token was used, just not the value.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Nov 22, 2023
1 parent f0bcb31 commit 3e76c8c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,21 @@ func (c *Client) newRequest(method, path string, query url.Values, body io.Reade
if os.Getenv("FAAS_DEBUG") == "1" {
fmt.Printf("%s %s\n", req.Method, req.URL.String())
for k, v := range req.Header {
fmt.Printf("%s: %s\n", k, v)
if k == "Authorization" {
auth := "[REDACTED]"
if len(v) == 0 {
auth = "[NOT_SET]"
} else {
l, _, ok := strings.Cut(v[0], " ")
if ok && (l == "Basic" || l == "Bearer") {
auth = l + " REDACTED"
}
}
fmt.Printf("%s: %s\n", k, auth)

} else {
fmt.Printf("%s: %s\n", k, v)
}
}

if len(bodyDebug) > 0 {
Expand Down

0 comments on commit 3e76c8c

Please sign in to comment.