Skip to content

Commit

Permalink
obfuscate email address on logs (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk39 authored Apr 29, 2023
1 parent 26487f3 commit efa2300
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/lib/pq v1.10.7
github.com/lucsky/cuid v1.2.1
github.com/nats-io/nats.go v1.23.0
github.com/networkteam/obfuscate v0.1.0
github.com/ory/dockertest v3.3.5+incompatible
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8=
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/networkteam/obfuscate v0.1.0 h1:T8n7RfGFDo8fgbnrHEpPx0uuWHhMqp6jYDoC3IpYRGo=
github.com/networkteam/obfuscate v0.1.0/go.mod h1:LFKp/VuLZDPsCuRhGmZWByYO0ZqPS1xWZbqWSgu/La4=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
Expand Down
4 changes: 2 additions & 2 deletions pkg/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ func handleMessage(msg *nats.Msg, sender smtp.Sender, nc *nats.Conn) error {
}
sendErr := sender.Send(data.ReturnPath, data.To, data.Body)
if sendErr != nil {
logrus.Infof("Cannot send email %v - %v: %v", data.To, data.EmailId, sendErr.Error())
logrus.Infof("Cannot send email %v - %v: %v", data.GetObfuscatedTo(), data.EmailId, sendErr.Error())
return handleSendError(sendErr, data, nc)
}
logrus.Infof("Email delivered: %v - %v", data.To, data.EmailId)
logrus.Infof("Email delivered: %v - %v", data.GetObfuscatedTo(), data.EmailId)
return handleSendSuccess(data, nc)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func handleStats(ctx context.Context, js nats.JetStreamContext, q *sq.Queries) {
logrus.Errorf("cannot marshal message %v", err.Error())
} else {
stype := sq.GetStatsType(data)
logrus.Printf("[%s] %s %s", StatsShow[stype], data.Email, data.MessageId)
logrus.Printf("[%s] %s %s", StatsShow[stype], data.GetObfuscatedEmail(), data.MessageId)
err := q.InsertStat(ctx, sq.InsertStatParams{
Email: data.Email,
MessageID: data.MessageId,
Expand Down
7 changes: 7 additions & 0 deletions proto/kannon/mailer/types/email.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package types

import "github.com/networkteam/obfuscate"

func (ets *EmailToSend) GetObfuscatedTo() string {
return obfuscate.EmailAddressPartially(ets.To)
}
5 changes: 5 additions & 0 deletions proto/kannon/stats/types/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql/driver"
"fmt"

"github.com/networkteam/obfuscate"
"google.golang.org/protobuf/encoding/protojson"
)

Expand All @@ -26,3 +27,7 @@ func (d *StatsData) Scan(src interface{}) error {
func (d *StatsData) Value() (driver.Value, error) {
return protojson.Marshal(d)
}

func (d *Stats) GetObfuscatedEmail() string {
return obfuscate.EmailAddressPartially(d.Email)
}

0 comments on commit efa2300

Please sign in to comment.