Skip to content

Fold header lines with CRLF instead of a bare LF - #279

Merged
tsegismont merged 1 commit into
vert-x3:4.xfrom
tsegismont:backport/221-to-4.x
Nov 14, 2026
Merged

tsegismont merged 1 commit into
vert-x3:4.xfrom
tsegismont:backport/221-to-4.x

Conversation

@tsegismont

Copy link
Copy Markdown
Member

Backport of #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)

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>
@tsegismont
tsegismont merged commit e525409 into vert-x3:4.x Nov 14, 2026
4 checks passed
@tsegismont
tsegismont deleted the backport/221-to-4.x branch November 14, 2026 14:39
@tsegismont tsegismont added this to the 4.5.37 milestone Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant