Repository navigation
Fold header lines with CRLF instead of a bare LF - #279
Merged
Merged
Conversation
Backport of vert-x3#221 to 4.x. The encoder folded long header values with a bare `\n`: the continuation of an encoded word in `encodeHeader`, the address and display name folds in `encodeEmailList` and `encodeHeaderEmail`, and the `name` and `filename` parameter folds in `AttachmentPart`. RFC 5322 section 2.1.1 requires lines of a message to be terminated by CRLF, and a bare LF inside the DATA payload is what the SMTP smuggling countermeasure described at https://www.postfix.org/smtp-smuggling.html looks for. Recent Postfix releases reject such a submission with `554 bare <LF> received after DATA`, so mail with a long subject, a long recipient list or a long attachment name could not be sent at all. Those seven fold sites now emit `\r\n ` and the RFC 2047 and RFC 5322 references explaining the limits are recorded next to them. Only the folds inside a header value change. `EncodedPart.asString` still joins the headers of a part with a bare `\n` for its debug and test representation, while the wire format is written by `SMTPSendMail`, which terminates every header with CRLF already. On the test side `SMTPTestWiser` now wraps the Wiser message handler with `SMTPTestBareLfMessageHandlerFactory`, which scans the received DATA for a bare LF and rejects the message, so every Wiser based test guards against a regression. `SMTPSendMailTest` checks that rejection by driving the SMTP dialogue itself, with a bare LF in the middle of the body, a bare LF as the last character of the body and a body that only uses CRLF, and adds coverage for long recipient lists, long display names, long subjects and multi line bodies. Assisted-by: Anthropic Claude (Opus 5) Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #221 to 4.x.
The encoder folded long header values with a bare
\n: the continuation of an encoded word inencodeHeader, the address and display name folds inencodeEmailListandencodeHeaderEmail, and thenameandfilenameparameter folds inAttachmentPart.RFC 5322 section 2.1.1 requires lines of a message to be terminated by CRLF, and a bare LF inside the DATA payload is what the SMTP smuggling countermeasure described at https://www.postfix.org/smtp-smuggling.html looks for. Recent Postfix releases reject such a submission with
554 bare <LF> received after DATA, so mail with a long subject, a long recipient list or a long attachment name could not be sent at all.Those seven fold sites now emit
\r\nand the RFC 2047 and RFC 5322 references explaining the limits are recorded next to them.Only the folds inside a header value change.
EncodedPart.asStringstill joins the headers of a part with a bare\nfor its debug and test representation, while the wire format is written bySMTPSendMail, which terminates every header with CRLF already.On the test side
SMTPTestWisernow wraps the Wiser message handler withSMTPTestBareLfMessageHandlerFactory, which scans the received DATA for a bare LF and rejects the message, so every Wiser based test guards against a regression.SMTPSendMailTestchecks that rejection by driving the SMTP dialogue itself, with a bare LF in the middle of the body, a bare LF as the last character of the body and a body that only uses CRLF, and adds coverage for long recipient lists, long display names, long subjects and multi line bodies.Assisted-by: Anthropic Claude (Opus 5)