Commits
Tarun Sukhani authored cd2d09320a5
fix(security)!: verify the SMTP hostname on the starttls channel (PF-160) BREAKING CHANGE: mail.smtp.channel=starttls now checks that the server's certificate names the host being connected to. Servers presenting a certificate for a different name — internal relays reached by IP, or shared hosting where the certificate names the provider — will stop accepting mail. Fix the certificate, or set mail.smtp.ssl.cavalidation=false. The starttls branch never installed YesSSLSocketFactory, so the certificate chain has always been validated here; 1.13.49 fixed the ssl channel and left this one alone deliberately. What was missing is the identity check. jakarta.mail 2.0.x defaults checkserveridentity to false, so a certificate trusted by the JVM but issued for any unrelated domain also completed the handshake — enough to intercept the message and the SMTP AUTH credentials that follow. Weaker than the pre-1.13.49 ssl bug, which accepted even self-signed certificates, but a valid certificate for some domain is free. Reuses mail.smtp.ssl.cavalidation rather than adding a second key, so there is one switch for "I accept an unverified SMTP peer". The property read moves above the channel branches so the two cannot drift apart. The opt-out is deliberately narrower here than on ssl: it drops the identity check but does NOT loosen chain validation to trust-all. Making it symmetric would silently *weaken* starttls on upgrade for anyone who set the property in 1.13.49 for the ssl channel, where it was a no-op on this branch. Tests: two added to MailSslTest — the secure default, and that the opt-out drops identity checking without introducing ssl.trust or a permissive socket factory. Verified by removing the checkserveridentity line: 1 of 4 goes red. Config docs updated to cover both channels and what the opt-out concedes in each. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>