Skip to content

Commit

Permalink
Hide sensitive info in HTTP logs
Browse files Browse the repository at this point in the history
Prevent auth and csp auth tokens from being dumped into logs
Signed-off-by: Anna Khmelnitsky <[email protected]>
  • Loading branch information
annakhm committed Sep 21, 2023
1 parent 9d06ea9 commit 7261591
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,14 @@ func (processor logRequestProcessor) Process(req *http.Request) error {
if err != nil {
log.Fatal(err)
}
log.Printf("Issuing request towards NSX:\n%s", reqDump)

// Replace sensitive information in HTTP headers
authHeaderRegexp := regexp.MustCompile("(?i)Authorization:.*")
cspHeaderRegexp := regexp.MustCompile("(?i)Csp-Auth-Token:.*")
replaced := authHeaderRegexp.ReplaceAllString(string(reqDump), "<Omitted Authorization header>")
replaced = cspHeaderRegexp.ReplaceAllString(replaced, "<Omitted Csp-Auth-Token header>")

log.Printf("Issuing request towards NSX:\n%s", replaced)
return nil
}

Expand Down

0 comments on commit 7261591

Please sign in to comment.