sanitise password in logs

This commit is contained in:
sentriz
2021-03-23 21:15:56 +00:00
parent 51dc407f2e
commit e7d4b857f7

View File

@@ -63,7 +63,13 @@ func (c *Controller) WithLogging(next http.Handler) http.Handler {
// other middlewares and the custom ResponseWriter has been written
sw := &statusWriter{ResponseWriter: w}
next.ServeHTTP(sw, r)
log.Printf("response %s for `%s`", statusToBlock(sw.status), r.URL)
// sanitise password
if q := r.URL.Query(); q.Get("p") != "" {
q.Set("p", "REDACTED")
r.URL.RawQuery = q.Encode()
}
log.Printf("response %s for `%v`", statusToBlock(sw.status), r.URL)
})
}