From acd182689bc75d4af1e93f0e571886ed8982acc2 Mon Sep 17 00:00:00 2001 From: "Christopher \"Chief\" Najewicz" Date: Tue, 30 Oct 2018 15:10:22 -0400 Subject: [PATCH] Obfuscate DSN password when logging connection details, fixes #174 (#176) --- pkg/datastore/sqlstore/sqlstore.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/datastore/sqlstore/sqlstore.go b/pkg/datastore/sqlstore/sqlstore.go index 12c156a8..739944d4 100644 --- a/pkg/datastore/sqlstore/sqlstore.go +++ b/pkg/datastore/sqlstore/sqlstore.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "errors" + "regexp" "time" _ "github.com/go-sql-driver/mysql" // mysql driver @@ -39,8 +40,9 @@ func New(c *Config) *sqlstore { } db := &sqlstore{dbx, c.Driver, c} - // write log statement - log.Printf("Connected to %s database: %s", c.Driver, c.DSN()) + // write log statement, sanitize password + re := regexp.MustCompile(`password=[^ ]+`) + log.Printf("Connected to %s database: %s", c.Driver, re.ReplaceAllString(c.DSN(), `xxxxx`)) // run migrations db.Migrate()