Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Mailer] EsmtpTransport throws too much information into TransportException #45308

Copy link
Copy link
Closed
@wikando-ck

Description

@wikando-ck
Issue body actions

Symfony version(s) affected

4.3-6.1

Description

When throwing a TransportException during authentication in EsmtpTransport, multiple authenticators are tried and their exceptions are collected in an array.
To generate the exception message for the resulting TransportException, this array is iterated and the exception is cast to string, leading to a full stack trace being passed inside the exception message.

        # https://github.com/symfony/mailer/blob/6.1/Transport/Smtp/EsmtpTransport.php:190
        $message = sprintf('Failed to authenticate on SMTP server with username "%s" using the following authenticators: "%s".', $this->username, implode('", "', $authNames));
        foreach ($errors as $name => $error) {
            $message .= sprintf(' Authenticator "%s" returned "%s".', $name, $error);
        }

When displaying the exception message to a user, there is way too much information about the backend inside and it is unreadable.

How to reproduce

Use a mailer with SMTPS, with invalid credentials and catch the resulting exception.
echo $exception->getMessage()

Possible Solution

Instead of the exception being cast to a string, $error->getMessage() should be used.

        $message = sprintf('Failed to authenticate on SMTP server with username "%s" using the following authenticators: "%s".', $this->username, implode('", "', $authNames));
        foreach ($errors as $name => $error) {
-            $message .= sprintf(' Authenticator "%s" returned "%s".', $name, $error);
+            $message .= sprintf(' Authenticator "%s" returned "%s".', $name, $error->getMessage());
        }

Additional Context

I'm happy to provide a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.