From d9395b24551c5804557e00e0381c78a1e85d356e Mon Sep 17 00:00:00 2001 From: AlexDHoffer Date: Thu, 18 Aug 2022 16:27:19 -0700 Subject: [PATCH] Sanitize url for printing when given password passed as parameter Signed-off-by: AlexDHoffer --- cmd/postgres_exporter/util.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/postgres_exporter/util.go b/cmd/postgres_exporter/util.go index 3a125f1d3..af35d0ca2 100644 --- a/cmd/postgres_exporter/util.go +++ b/cmd/postgres_exporter/util.go @@ -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() }