Thanks to visit codestin.com
Credit goes to github.com

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

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

jnoordsij
Copy link
Contributor

@jnoordsij jnoordsij commented Jun 12, 2025

Q A
Branch? 6.4
Bug fix? 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 carsonbot added this to the 7.4 milestone Jun 12, 2025
@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
@symfony symfony deleted a comment from carsonbot Jun 16, 2025
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me as a bugfix, thus 6.4

@nicolas-grekas nicolas-grekas modified the milestones: 7.4, 6.4 Jun 16, 2025
@jnoordsij jnoordsij force-pushed the roundrobintransport-clone-message branch from adce748 to 251bf3a Compare June 18, 2025 08:27
@jnoordsij jnoordsij changed the base branch from 7.4 to 6.4 June 18, 2025 08:27
@jnoordsij
Copy link
Contributor Author

Rebased onto 6.4 (as bugfix)

@OskarStark OskarStark changed the title [Mailer] [Transport] Send clone of RawMessage instance in RoundRobinTransport [Mailer][Transport] Send clone of RawMessage instance in RoundRobinTransport Jun 18, 2025
@carsonbot carsonbot changed the title [Mailer][Transport] Send clone of RawMessage instance in RoundRobinTransport [Mailer] [Transport] Send clone of RawMessage instance in RoundRobinTransport Jun 18, 2025
@fabpot fabpot force-pushed the roundrobintransport-clone-message branch from 251bf3a to 0972774 Compare June 20, 2025 10:40
@fabpot
Copy link
Member

fabpot commented Jun 20, 2025

Thank you @jnoordsij.

@fabpot fabpot merged commit cdedbab into symfony:6.4 Jun 20, 2025
11 checks passed
@jnoordsij jnoordsij deleted the roundrobintransport-clone-message branch June 20, 2025 11:03
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.

4 participants