Skip to content

Commit

Permalink
Obfuscate DSN password when logging connection details, fixes #174 (#176
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chiefy authored and dannyvankooten committed Oct 30, 2018
1 parent 02c2eb9 commit acd1826
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/datastore/sqlstore/sqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"errors"
"regexp"
"time"

_ "github.com/go-sql-driver/mysql" // mysql driver
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit acd1826

Please sign in to comment.