symfony icon indicating copy to clipboard operation
symfony copied to clipboard

[Mailer] Option to enforce STARTTLS

Open Swanty opened this issue 3 years ago • 10 comments

Description

// https://github.com/symfony/mailer/blob/6.1/Transport/Smtp/EsmtpTransport.php#L136

if (!$stream->isTLS() && \defined('OPENSSL_VERSION_NUMBER') && \array_key_exists('STARTTLS', $this->capabilities)) {

That line will be true only if server reports that it has STARTTLS support, but during a man-in-the-middle attack one could remove this capability and communication would happen in cleartext.

It would be great if there was an option to enforce STARTTLS :pray:

Example

No response

Swanty avatar Nov 23 '22 11:11 Swanty

This sounds a lot like MTA-STS.

plandolt avatar Nov 28 '22 07:11 plandolt

This sounds a lot like MTA-STS.

The RFC says This document defines a mechanism for recipient domains to publish policies, via a combination of DNS and HTTPS, but that's not exactly what I'm suggesting, since I have no control over recipient servers.

I'm working on a hotel management software, where each hotel can specify SMTP recipient server for mailing their hotel emails and I'd like to make it more secure for cases when port 587 is used or when hotel staff knows that the recipient server port supports STARTTLS.
e.g. a checkbox in our UI "Enforce STARTTLS". When enabled, it would forcefully attempt STARTTLS and if it cannot be established then mail sending would throw an error, instead of continuing in cleartext.

The alternative is to use port 465 (implicit SSL/TLS), but not all recipient servers support TLS on that port (some only SSL, which is outdated).

Swanty avatar Nov 28 '22 09:11 Swanty

Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature?

carsonbot avatar Jul 04 '23 09:07 carsonbot

I would like to see this feature.

In my use-case, I have an open source application with configurable SMTP details, so it's used with many different mail services. I want to be able to provide assurance that that emails are being sent over TLS or STARTTLS. Initially I incorrectly assumed that TLS and STARTTLS would be equally supported by email services, so I forced full TLS usage in these scenarios but this caused problems where only STARTTLS is supported, and not full TLS.

I tried to extend the existing Esmtp transport but I could not find a clean way of doing this. For now I'm keeping a fork which patches in the ability to require TLS or STARTTLS. Note: this is not PR ready since it's targeting an old branch and lacks added tests.

I'd be happy to work on and provide a PR for this. Would Symfony be willing to review a PR if I put one forward?

@Swanty Would it work for you if the option enforces either STARTTLS or TLS? Or do you need specific indication of STARTTLS usage (so fail if TLS is used instead)?

ssddanbrown avatar Jul 04 '23 14:07 ssddanbrown

@Swanty Would it work for you if the option enforces either STARTTLS or TLS? Or do you need specific indication of STARTTLS usage (so fail if TLS is used instead)?

Yes, your patch works great for my use case - thank you 🙏 As long as there's no chance for mails to be sent in cleartext I'm happy :>

Swanty avatar Aug 31 '23 13:08 Swanty

fixed in #53621

xabbuh avatar Jan 31 '24 10:01 xabbuh

@xabbuh #53621 was about disabling STARTTLS while this issue is about enforcing it. Those are two different things.

derrabus avatar Jan 31 '24 12:01 derrabus

#53621 paved the way to show how this should be done. Could be by renaming auto_tls to just tls and support bool|auto as a value. PR welcome.

nicolas-grekas avatar Jan 31 '24 12:01 nicolas-grekas

Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature?

carsonbot avatar Aug 01 '24 13:08 carsonbot

Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3

carsonbot avatar Aug 15 '24 13:08 carsonbot

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

carsonbot avatar Aug 29 '24 13:08 carsonbot

It's somewhat sad to see that this was closed automatically.

Being able to make sure a SMTP session uses TLS would be very useful, especially regarding Art. 25 GDPR https://gdpr-info.eu/art-25-gdpr/

KirbyDE avatar Oct 01 '24 09:10 KirbyDE

The thing is, if nobody builds a certain feature, we just won't have it. The auto-close of the ticket does not mean that it's a won't fix. We would still accept a PR that delivers the feature.

If you believe that this feature is useful, or even better, you actually need it, you would be in the best position to build it.

derrabus avatar Oct 01 '24 09:10 derrabus

I've started a PR for this at #59479

ssddanbrown avatar Jan 11 '25 16:01 ssddanbrown