Skip to content

Commit

Permalink
fix: prevent SMTP URL leak on unparsable URL (#3770)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Feb 21, 2024
1 parent b8b747b commit c5f39f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion courier/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strconv"
"time"

"github.com/pkg/errors"

"github.com/ory/herodot"
"github.com/ory/kratos/driver/config"

Expand All @@ -27,7 +29,7 @@ type SMTPClient struct {
func NewSMTPClient(deps Dependencies, cfg *config.SMTPConfig) (*SMTPClient, error) {
uri, err := url.Parse(cfg.ConnectionURI)
if err != nil {
return nil, herodot.ErrInternalServerError.WithError(err.Error())
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("The SMTP connection URI is malformed. Please contact a system administrator."))
}

var tlsCertificates []tls.Certificate
Expand Down
17 changes: 17 additions & 0 deletions courier/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ import (
gomail "github.com/ory/mail/v3"
)

func TestNewSMTPClientPreventLeak(t *testing.T) {
// Test for https://hackerone.com/reports/2384028

ctx := context.Background()
conf, reg := internal.NewFastRegistryWithMocks(t)

invalidURL := "sm<>t>p://f%oo::bar:baz@my-server:1234:122/"
conf.MustSet(ctx, config.ViperKeyCourierSMTPURL, invalidURL)
channels, err := conf.CourierChannels(ctx)
require.NoError(t, err)
require.Len(t, channels, 1)

_, err = courier.NewSMTPClient(reg, channels[0].SMTPConfig)
require.Error(t, err)
assert.NotContains(t, err.Error(), invalidURL)
}

func TestNewSMTP(t *testing.T) {
ctx := context.Background()
conf, reg := internal.NewFastRegistryWithMocks(t)
Expand Down

0 comments on commit c5f39f4

Please sign in to comment.