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

Skip to content

[Mailer / Amazon Mailer] Valid AWS secret key characters removed / throwing invalid DSN exception #36669

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

Closed
nspyke opened this issue May 3, 2020 · 6 comments

Comments

@nspyke
Copy link

nspyke commented May 3, 2020

Symfony version(s) affected: 4.4.8

Description
I am setting up the Symfony Amazon mailer component and passed my AWS key and AWS secret to the mailer DSN. My AWS secret contains a + character in it, eg A57+VZcaA (obviously not a real key). I noticed I was getting signature errors.
Adding a dump and echo to line 41 of Symfony\Component\Mailer\Bridge\Amazon\Transport\SesHttpTransport using the example secret above outputs the following;

https://pasteboard.co/J6ErpBL.png

As a workaround, I generated a new access key and secret, and this time it contains two / characters in it eg ...se/J1/0p, and am getting the exception;

 The "ses://xxxxx:xxxxse/J1/0p@default?region=us-west-2" mailer DSN is invalid

How to reproduce
Setup symfony/mailer with the Amazon SES mailer.
Generate a access key and secret that has a + or / character in it.
Add;

        echo($this->secretKey);
        dd($this->secretKey);

to line 41 of Symfony\Component\Mailer\Bridge\Amazon\Transport\SesHttpTransport

Additional context
I also tried to reference a service parameter instead of a .env variable and the plus character was also removed from that as well.
When I edited the SesHttpTransport class and changed the $secretKey variable to my actual key in the constructor, the email was sent successfully.

In an attempt to figure out where the cause is a dd($dsn) on line 96 of Symfony\Component\Mailer\Transport shows the full correct key being presented to the Transport classes.

A further dump on line 125 of the same class shows the secret with the + symbol removed.

@nspyke nspyke added the Bug label May 3, 2020
@nspyke nspyke changed the title + (plus) character removed configuration + (plus) character removed from configuration value May 3, 2020
@nspyke nspyke changed the title + (plus) character removed from configuration value [Mailer / Amazon Mailer] Valid AWS secret key characters removed / throwing invalid DSN exception May 3, 2020
@Nyholm
Copy link
Member

Nyholm commented May 3, 2020

Hm.

I had a similar issue in another DSN parser: Nyholm/dsn#12

The nyholm/dsn package is very similar to how the CacheComponent parses Redis DSN and I think also similar here.

@drekinov
Copy link

drekinov commented May 7, 2020

mailer/Transport/DSN.php urldecode username and password - you can check source code.

so you need to encode username and password(replace + with %2B and etc urlencode())
then DSN works.

Tricky part is that there is no ENV processor to urlencode value on the fly. so if you are constructing dsn in config you cant use default AWS_* envs but you should have:
AWS_SECRET_ACCESS_KEY - regular
AWS_SECRET_ACCESS_KEY_ENCODED - use in dsn

async aws sdk in symfony 5.1 should solve most of the issues i have with EC2 role authentication which is not supported right now :)

@xabbuh xabbuh added the Mailer label May 7, 2020
@Nyholm Nyholm mentioned this issue May 28, 2020
3 tasks
@fabpot
Copy link
Member

fabpot commented Jun 10, 2020

Closing as @drekinov gave the current solution.

@fabpot fabpot closed this as completed Jun 10, 2020
@nspyke
Copy link
Author

nspyke commented Jun 11, 2020 via email

@fabpot
Copy link
Member

fabpot commented Jun 11, 2020

You're right, can you open an issue on the docs repo?

@nspyke
Copy link
Author

nspyke commented Jun 14, 2020

You're right, can you open an issue on the docs repo?

Hi @fabpot . I've submitted a docs PR.
symfony/symfony-docs#13838

javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Jun 19, 2020
This PR was squashed before being merged into the 4.4 branch.

Discussion
----------

Added a caution about encoding DSN credentials

Refer to issue symfony/symfony#36669

Commits
-------

e1da71c Added a caution about encoding DSN credentials
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants