You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
smtps:// email connection string without a port connects to port 25 with no TLS #2697
SmtpUri sets port 465 for an smtps:// URI with no explicit port, then overwrites it with 25 a few lines later. Because the encryption default is derived from the port, the mailer then connects to port 25 with no TLS. The parsed IsSecure flag is never used.
Where
SmtpUri constructor sets Port = uri.IsDefaultPort ? 465 : uri.Port for smtps, then L41 unconditionally runs Port = uri.IsDefaultPort ? 25 : uri.Port. System.Uri has no default port for smtps, so IsDefaultPort is true and Port is -1 whenever the port is omitted.
MailKitMailSender connects with SecureSocketOptions.None and then authenticates.
Steps to reproduce
Set EX_ConnectionStrings__Email=smtps://user:password@smtp.example.com (no port) and leave EX_SmtpEncryption unset.
Trigger any email (e.g. a password reset). The mailer connects to smtp.example.com:25 without TLS and sends AUTH with the credentials in the clear, or fails if port 25 is blocked or the server requires TLS.
Expected
smtps://host connects to port 465 with implicit TLS (SslOnConnect). More generally, the smtps scheme should select TLS regardless of port.
Suggested fix
Remove the trailing Port = uri.IsDefaultPort ? 25 : uri.Port; in SmtpUri (the scheme branches already set the port). In EmailOptions, when SmtpEncryption isn't configured and uri.IsSecure is true, default to SSL for port 465 and StartTLS for other ports instead of None. Add SmtpUri tests for smtp://host, smtps://host, and smtps://host:587.
Activity