Skip to content

Commit

Permalink
Sanitize url for printing when given password passed as parameter
Browse files Browse the repository at this point in the history
Signed-off-by: AlexDHoffer <alexdchoffer@gmail.com>
  • Loading branch information
AlexDCraig committed Aug 18, 2022
1 parent c84fc4a commit d9395b2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/postgres_exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,14 @@ func loggableDSN(dsn string) string {
pDSN.User = url.UserPassword(pDSN.User.Username(), "PASSWORD_REMOVED")
}

// Blank password data from parameters if not nil
q := pDSN.Query()
if q != nil {
if q.Get("password") != "" {
q.Set("password", "PASSWORD_REMOVED")
pDSN.RawQuery = q.Encode()
}
}

return pDSN.String()
}

0 comments on commit d9395b2

Please sign in to comment.