Details
Observed:
wire RCPT TO : RCPT TO:<[email protected](x)evil.com>
envelope.to: [ '[email protected](x)evil.com' ]
The same recipient string sent at a real, conformant SMTP server (aiosmtpd, a widely used reference-grade Python SMTP implementation) instead of the sink above:
Error: Can't send mail - all recipients were rejected: 501 Syntax: RCPT TO: <address> [SP <mail-parameters>]
code: 'EENVELOPE', responseCode: 501, command: 'RCPT TO',
rejected: [ '[email protected](x)evil.com' ]
So against a strict receiver the immediate, concretely demonstrated outcome is that the message is bounced: an ordinary-looking recipient address that a sender/application believes is valid (and, see below, that some app-side validators *do* read as valid, at good-corp.com) silently fails to send.
Interpretation-conflict confirmation (same class as GHSA-cc9r-2j5m-2m83)
The same string, read by two other parsers an application might use to gate on the recipient's domain, produces two more, mutually different readings:
>>> import email.utils
>>> email.utils.parseaddr('Legit User <[email protected](x)evil.com>')
('Legit User (x)', '[email protected]')
>>> import email.policy, email.parser
>>> msg = email.parser.Parser(policy=email.policy.default).parsestr(
... 'To: Legit User <[email protected](x)evil.com>\n\n')
>>> addr = msg['To'].addresses[0]
>>> addr.username, addr.domain
('user', 'good-corp.com')
So for the exact same bytes:
| Parser | Domain read |
|---|---|
| Python email.utils.parseaddr | good-corp.comevil.com (attacker-registrable) |
| Python email.policy.default (defects not inspected) | good-corp.com (clean, would pass an allow-list check) |
| Nodemailer addressparser (this report) | good-corp.com(x)evil.com (illegal characters, rejected by a strict MTA) |
This is the exact "which parser sees what" comparison table from GHSA-cc9r-2j5m-2m83, reproduced through a different, unpatched code path: an application validating with email.policy.default without checking .defects (a documented pattern in that advisory) approves good-corp.com and hands the string to Nodemailer, which then emits a different, malformed value on the wire.
Version range
The built addressparser/sendMail output was tested for this exact input across published releases:
| Version | envelope.to |
|---|---|
| 6.9.16 | [email protected](x)evil.com |
| 9.0.6 | [email protected](x)evil.com |
| 9.1.0 (fixed GHSA-cc9r-2j5m-2m83) | [email protected](x)evil.com |
| 10.0.1 | [email protected](x)evil.com |
| 10.0.12 / current HEAD (fixed GHSA-g57g-f23g-4646) | [email protected](x)evil.com |
Unchanged across every one of the three address-parser advisory fixes, because none of them touch the tokenizer's single-slot operatorExpecting state or the _handleAddress state-machine reset on ).
Impact
- Confirmed, demonstrated impact: a recipient address that contains a perfectly legal RFC 5322 comment inside angle brackets — the single most common way a
To/Cc/Bcc/From/Reply-Tovalue is written (Display Name <user@domain>) — is parsed into a value containing SMTP-illegal characters ((,)) that a conformant receiving SMTP server rejects outright, silently failing message delivery to what the sender/application believed was a valid, already-validated recipient (CWE-20, availability/reliability impact on outbound mail). - Demonstrated interpretation conflict (CWE-436): the malformed value that reaches
envelope.toand the wireRCPT TOcommand disagrees with how other parsers, including ones explicitly called out as an at-risk validation pattern in GHSA-cc9r-2j5m-2m83 (Python'semail.policy.defaultwithout defect inspection), read the exact same bytes. An application gating outbound mail on "is the recipient's domain in my allow-list" using such a validator can approve a value that Nodemailer then sends corrupted, and depending on the receiving MTA's own comment handling, a different domain than either the sender or the validator believed was being used. - Reachability: every code path that ends up calling
MimeNode._parseAddresses()—to,cc,bcc,from,replyTo, and the explicitenvelopeoption — is affected identically, since they all funnel through the sameaddressparser()/_handleAddress()logic.
Suggested fix
The underlying issue is architectural: Tokenizer.operatorExpecting is a single value, so it cannot represent "currently inside an angle-address, and also currently inside a comment nested within it." A minimal fix is to make the tokenizer maintain a stack of expected closing characters (pushing ')' when entering a comment while another operator scope, e.g. '>', is already open, and popping back to the outer expectation on )), so a comment can be recognized and stripped no matter what scope it is nested inside. _handleAddress's state machine would then need to restore the previous state on a comment close instead of unconditionally resetting to 'text', so recognized-but-stripped comment content inside <...> continues to accumulate as address rather than leaking into text.
As defense in depth, _recoverAddrSpec() (or an equivalent check run specifically on data.address for the angle-bracket case) should also reject/clean any parsed address value that still contains RFC 5322 special characters such as (/) regardless of whether whitespace is present, since envelope.to is used directly to build an SMTP command and any character outside Mailbox (RFC 5321 §4.1.2) reaching that string is already the wrong outcome, independent of how it got there.
Regression test suggestion
Name <[email protected](x)evil.com> and the bcc/cc/from/replyTo/envelope equivalents should all parse to { address: '[email protected]', name: 'Name evil.com' } or be rejected outright by sendMail, never silently carry (/) into envelope.to.