Skip to content
This repository was archived by the owner on Dec 15, 2020. It is now read-only.

Commit eb21211

Browse files
zwassdirectionless
authored andcommitted
Merge pull request from GHSA-6g7f-8qm4-f7h8
When LOGIN authentication was used, Fleet would send SMTP credentials even if the connection the SMTP server was not secured via TLS. Copying the pattern used in the standard library PlainAuth implementation, we now only send credentials when the connection is secure or the server is localhost.
1 parent bf36146 commit eb21211

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

server/mail/mail.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,26 @@ func (m mailService) SendEmail(e kolide.Email) error {
7474
type loginauth struct {
7575
username string
7676
password string
77+
host string
7778
}
7879

79-
func LoginAuth(username, password string) smtp.Auth {
80-
return &loginauth{username: username, password: password}
80+
func LoginAuth(username, password, host string) smtp.Auth {
81+
return &loginauth{username: username, password: password, host: host}
8182
}
8283

83-
func (l *loginauth) Start(serverInfo *smtp.ServerInfo) (proto string, toServer []byte, err error) {
84+
func isLocalhost(name string) bool {
85+
return name == "localhost" || name == "127.0.0.1" || name == "::1"
86+
}
87+
88+
func (l *loginauth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error) {
89+
if !server.TLS && !isLocalhost(server.Name) {
90+
return "", nil, errors.New("unencrypted connection")
91+
}
92+
93+
if server.Name != l.host {
94+
return "", nil, errors.New("wrong host name")
95+
}
96+
8497
return "LOGIN", nil, nil
8598
}
8699

@@ -111,7 +124,7 @@ func smtpAuth(e kolide.Email) (smtp.Auth, error) {
111124
case kolide.AuthMethodPlain:
112125
auth = smtp.PlainAuth("", e.Config.SMTPUserName, e.Config.SMTPPassword, e.Config.SMTPServer)
113126
case kolide.AuthMethodLogin:
114-
auth = LoginAuth(e.Config.SMTPUserName, e.Config.SMTPPassword)
127+
auth = LoginAuth(e.Config.SMTPUserName, e.Config.SMTPPassword, e.Config.SMTPServer)
115128
default:
116129
return nil, fmt.Errorf("unknown SMTP auth type '%d'", e.Config.SMTPAuthenticationMethod)
117130
}

0 commit comments

Comments
 (0)