Skip to content

Commit

Permalink
Merge pull request #911 from linka-cloud/do-not-leak-nats-credentials
Browse files Browse the repository at this point in the history
Do not log nats url credentials
  • Loading branch information
fancycode authored Jan 28, 2025
2 parents ca62fb5 + 471469f commit b719a56
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion natsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"encoding/json"
"fmt"
"log"
"net/url"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -101,7 +102,7 @@ func NewNatsClient(url string) (NatsClient, error) {

client.conn, err = nats.Connect(url)
}
log.Printf("Connection established to %s (%s)", client.conn.ConnectedUrl(), client.conn.ConnectedServerId())
log.Printf("Connection established to %s (%s)", removeURLCredentials(client.conn.ConnectedUrl()), client.conn.ConnectedServerId())
return client, nil
}

Expand Down Expand Up @@ -153,3 +154,11 @@ func (c *natsClient) Decode(msg *nats.Msg, vPtr interface{}) (err error) {
}
return
}

func removeURLCredentials(u string) string {
if u, err := url.Parse(u); err == nil && u.User != nil {
u.User = url.User("***")
return u.String()
}
return u
}

0 comments on commit b719a56

Please sign in to comment.