Skip to content

[Mailer] [Transport] Send clone of RawMessage instance in RoundRobinTransport #60772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 7.4
Choose a base branch
from

Conversation

jnoordsij
Copy link
Contributor

@jnoordsij jnoordsij commented Jun 12, 2025

Q A
Branch? 7.4
Bug fix? no (arguably yes)
New feature? no
Deprecations? no
Issues N/A
License MIT

When using an implementation of the TransportInterface, a common pattern (especially for mass bulk mailing services) is to use headers to communicate various pieces of metadata or settings to the receiving server for processing. Such options or headers might be very specific to the type of service used. Real world examples of such applications are https://github.com/symfony/mailgun-mailer/blob/7.2/Transport/MailgunApiTransport.php#L89 or https://www.reddit.com/r/symfony/comments/1cn32jx/add_header_based_on_transport/?rdt=36882.

However, when using such a transport as one of the transports in the RoundRobinTransport (or by extension the FailoverTransport), this may result in certain headers intended for transport service A to also be sent to transport service B if the former fails. Although this will likely be harmless in most cases, it may cause issues as the one described in laravel/framework#51872 (and https://stackoverflow.com/questions/78660310/why-the-failover-first-driver-fails-and-inline-attachment-image-path-is-wrong-in).

To prevent alterations to the message that happen within the scope of a specific transport to leak to another, this PR proposes to use a clone of the RawMessage instance whenever attempting a new transport service. This should ensure that any transport-specific manipulations should not leak to a next transport.

Note this is mostly a behavioral change, which I don't think should break any existing use case, but may considered to be noteworthy enough to list it somewhere. It may also even be considered a bug fix; if so, and it is better to target 7.3 or 6.4 instead, please let me know.

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.4" but it seems your PR description refers to branch "7.4 for features / 6.4, 7.2, or 7.3 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [Mailer][Transport] Send clone of RawMessage instance in RoundRobinTransport [Mailer] [Transport] Send clone of RawMessage instance in RoundRobinTransport Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants