From 76353ddae32807a0ad6e364a85e5c3d3ddac941a Mon Sep 17 00:00:00 2001 From: ThinkChaos Date: Mon, 1 Apr 2024 21:35:36 -0400 Subject: [PATCH] fix(log): don't print querylog target password when using a database --- config/query_log.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/config/query_log.go b/config/query_log.go index 616ecdfd8..bb19a4a5c 100644 --- a/config/query_log.go +++ b/config/query_log.go @@ -1,6 +1,8 @@ package config import ( + "net/url" + "github.com/sirupsen/logrus" ) @@ -32,7 +34,7 @@ func (c *QueryLog) LogConfig(logger *logrus.Entry) { logger.Infof("type: %s", c.Type) if c.Target != "" { - logger.Infof("target: %s", c.Target) + logger.Infof("target: %s", c.censoredTarget()) } logger.Infof("logRetentionDays: %d", c.LogRetentionDays) @@ -41,3 +43,15 @@ func (c *QueryLog) LogConfig(logger *logrus.Entry) { logger.Infof("flushInterval: %s", c.FlushInterval) logger.Infof("fields: %s", c.Fields) } + +func (c *QueryLog) censoredTarget() string { + target, err := url.Parse(c.Target) + if err != nil || target.User == nil { + return c.Target + } + + // Drop the password + target.User = url.User(target.User.Username()) + + return target.String() +}