Skip to content

Strip CR/LF from SMTP subjects derived from event data - #4258

Open
shaggyinsomniac wants to merge 1 commit into
apache:2.xfrom
shaggyinsomniac:smtp-subject-crlf
Open

Strip CR/LF from SMTP subjects derived from event data#4258
shaggyinsomniac wants to merge 1 commit into
apache:2.xfrom
shaggyinsomniac:smtp-subject-crlf

Conversation

@shaggyinsomniac

Copy link
Copy Markdown

Description

The SmtpAppender subject is produced by a PatternLayout serializer and commonly embeds event data (message, MDC, throwable). CR/LF sequences in that data currently flow into MimeMessage.setSubject unsanitized, allowing mail header injection when an attacker can influence logged content — for example a logged username or error message containing \r\nBcc: attacker@example.com results in an injected Bcc header relayed through the application's SMTP credentials.

This strips CR and LF from the subject in:

  • MimeMessageBuilder.setSubject (log4j-core and log4j-jakarta-smtp)
  • the multipart send paths of both SmtpManager variants

Testing

MimeMessageBuilderTest (new): asserts a plain subject round-trips unchanged, and a subject containing CRLF has all CR/LF removed (making the remainder inert text within the single subject value). Both pass; no other behavior changes.

The SmtpAppender subject is produced by a PatternLayout serializer and
commonly embeds event data (message, MDC, throwable). CR/LF sequences in
that data flow into MimeMessage.setSubject unsanitized, allowing mail
header injection when an attacker can influence logged content (for
example a 'Bcc' header relayed through the application's SMTP
credentials).

Strip CR and LF from subjects in MimeMessageBuilder.setSubject and in
the SmtpManager multipart send paths of both the javax (log4j-core) and
jakarta (log4j-jakarta-smtp) modules.

Signed-off-by: Sagar Chanchal <Sagarr2112@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

1 participant