Skip to content
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

Use of rtrim before encryption introduces blank line in headers when header contains lines with only whitespace characters #525

Open
alexaka1 opened this issue Sep 22, 2023 · 1 comment

Comments

@alexaka1
Copy link

alexaka1 commented Sep 22, 2023

I have setup an alias to a GOG account, and I forward it to an email. Encryption is turned on, although I don't think it matters (I have disabled encryption for now, but GOG is yet to send the next newsletter).

When I receive the email it contains a partial header in the body, and then the email html is included as multipart/mixed content-type.
The email header contains a List-Unsubscribe key and the value contains a new line with 2 spaces.

List-Unsubscribe: <mailto:[email protected]?subject=redacted>,
  
 <https://gog.salesmanago.com/optOut.htm?uid=redacted&sec=redacted&conversation=redacted&optOutLanguage=en&auto=true>

The email body that I see in the client starts exactly after the new line, and contains the <url> and the the remaining part of the header.

I have enabled a different mail client as the forward address to see if this is a provider issue, as well as disabled encryption, to see if decryption goes wrong (also unlikely). I will update the post if a new email is sent out.
2FA emails from GOG don't contain a List-Unsubscribe, and are rendered correctly (even with encryption).

I have sent you two sample emails for investigation.

Edit: When encryption is off, the email is correctly handled by both providers, despite having the same header with the line-break. Interesting...

@alexaka1
Copy link
Author

alexaka1 commented Sep 24, 2023

Since then I have concluded that only the encrypted messages are messed up.
I have looked at the code and I think this code introduces a completely empty line in the email headers, because of the original header containing a line with 2 spaces.

$lines[$i] = rtrim($lines[$i])."\r\n";

And since at this point the email is provided as is to gnupg for encryption, I looked for RFC-5322:

The body is simply a sequence of
characters that follows the header section and is separated from the
header section by an empty line (i.e., a line with nothing preceding
the CRLF).

So because GOG sends this strange header, AnonAddy cleans this up, but ends up introducing a bug, by inserting a blank line into the headers, which then gets interpreted as start of body by gnupg email parser.

So that was a rabbithole 🙂

I don't have an immediate solution to this, other than GOG smgrid.pl should not compose their headers in such a way. While their header is valid, according to the spec (there are characters before crlf), it makes no sense why it is composed in such a way.

@alexaka1 alexaka1 changed the title GOG.com newsletter seemingly breaks content-type because of weird List-Unsubscribe header Use of rtrim before encryption introduces blank line in headers, making email parser parse wrong body Sep 24, 2023
@alexaka1 alexaka1 changed the title Use of rtrim before encryption introduces blank line in headers, making email parser parse wrong body Use of rtrim before encryption introduces blank line in headers when header contains lines with only whitespace characters Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant