Email Header Injection

User input containing line breaks reaches the headers of an email the application sends, so an attacker can add recipients or headers, or replace the message body.

SeverityMedium
CVSS 3.15.3 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N Open in the calculator
CVSS 4.06.9 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection')
OWASP Top 10A05:2025 Injection
MITRE ATT&CKT1566 Phishing
CategoryInjection

Description

The application sends email using values supplied by the user, such as the sender's name, reply-to address or subject in a contact, feedback or share form, and builds the message headers as text without removing carriage return and line feed characters. Email headers are separated by line breaks, so input containing an encoded CRLF sequence ends the intended header and adds new ones. Where the application talks to a mail server directly, the same characters can sometimes inject SMTP commands.

By adding headers such as Bcc: or Cc: with further recipients, or a blank line followed by content that replaces the message body, an attacker can use the application to send email with content they control to any recipients, through the organisation's own mail infrastructure. The messages pass the domain's sender authentication checks and carry its reputation, which makes them effective for spam and phishing, and abuse of this kind can get the domain or its mail servers placed on block lists. The weakness does not usually expose data held by the application unless the messages it sends contain such data.

It typically shows itself on a test when a field containing %0d%0aBcc: followed by an address under the tester's control causes a copy of the message to arrive at that address, or when the received message shows the injected headers. Some scanners report it as SMTP or email header injection. In some mail libraries the sender address is also passed to the local mail program as a command-line argument, which has led to more serious argument injection flaws.

Remediation

Build email headers in a way that input cannot alter:

  • Use a maintained mail library that sets headers through structured fields and rejects line breaks, rather than assembling header text in application code.
  • Reject carriage return, line feed and NUL characters in every value placed in a header, including names and subjects, and validate email addresses as a single address in the expected format.
  • Fix the recipients of contact and feedback forms on the server, and never take a recipient address from the request.
  • Do not pass user-supplied addresses to the mail program's command line, for example through the additional parameters of PHP's mail() function, unless they have been strictly validated.
  • Apply rate limits and bot protection to forms that send email, so that any remaining abuse is limited.

Confirm the fix by repeating the original submissions with encoded line breaks in each field, and checking that no additional recipients or headers appear in the delivered message.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding