GHSA-4ffr-jq9g-5ffx: Nodemailer: Quadratic backtracking in SMTP AUTH mechanism detection regexes allows pre-auth remote denial of service
Nodemailer 3.0.0 through 10.0.12 uses four regular expressions in SMTPConnection._actionEHLO to detect AUTH mechanisms, and they backtrack quadratically. A malicious or man-in-the-middle SMTP server can answer EHLO with 250-AUTH plus a long run of spaces and freeze the Node.js process before any login. Upgrade to nodemailer 10.0.13.
Published Oct 27, 2026 · Analysis Nov 1, 2026
What an attacker can do
After EHLO, the client runs four patterns, one each for PLAIN, LOGIN, CRAM-MD5 and XOAUTH2, against the server's reply. Each contains the sub-pattern (?:(\s+|=)[^\n]*\s+|\s+|=) before the mechanism name. Both [^\n]* and \s+ can match the same whitespace. When the mechanism name is missing, the engine tries every split of the whitespace run, which costs O(n^2).
The attacker is the SMTP server, or someone who can intercept a plaintext or pre-STARTTLS connection. They reply 250-AUTH, a long run of whitespace, and a token that matches nothing. The advisory's benchmark shows 2,000 spaces take about 10 seconds for the four patterns, and 3,000 take about 35 seconds. About 4,000 spaces already block each pattern for tens of seconds, far under the 1 MB response cap.
Node.js runs this on its single thread. No requests are served and no timers fire, and the 10-minute socket timeout cannot interrupt it. No credentials are needed. Multi-tenant mailers that let tenants set their own SMTP host are the clearest exposure. The impact is availability only.
Who is affected
nodemailer on npm from 3.0.0 through 10.0.12. The regexes arrived when the SMTP client was folded into nodemailer at 3.0.0. Applications that connect only to SMTP servers they trust, over verified TLS, have little exposure. Check the version:
npm ls nodemailernodemailer
- Ecosystem
- npm
- Affected
- >= 3.0.0, <= 10.0.12
- Fixed in
- 10.0.13
- Check
npm ls nodemailer
How to fix it
Upgrade to nodemailer 10.0.13:
npm install [email protected]The 10.0.13 release notes say it reads the advertised SASL methods without backtracking regexes. The advisory's interim mitigation is to allow only known SMTP hosts. That does not help when users configure their own servers, or when a plaintext hop can be intercepted before STARTTLS.
How to tell if you were hit
Look for Node.js processes that stop responding for seconds or minutes right after opening an SMTP connection, with CPU pinned on one core. Check which SMTP host the stalled connection was talking to, and whether it is user-configured. Packet captures of the EHLO reply show a 250-AUTH line followed by a very long whitespace run.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
Summary
Nodemailer's SMTP client applies four regular expressions to a peer's EHLO response to detect the supported SASL mechanisms. Each pattern uses an alternation with two overlapping whitespace-matching sub-patterns, which produces quadratic (O(n^2)) backtracking whenever the mechanism name is absent from the line. A malicious or MITM SMTP server that answers EHLO with 250-AUTH followed by a long whitespace-only run and a non-matching token blocks the Node.js event loop for tens of seconds to hours during a pre-authentication handshake. No authentication to the target SMTP server is required, and any application that connects to an attacker-influenced host is affected.
Root Cause
Each of the four AUTH mechanism regexes in SMTPConnection._actionEHLO contains the sub-pattern (?:(\s+|=)[^\n]*\s+|\s+|=) before the mechanism literal. [^\n]* and the trailing \s+ both match whitespace and can consume the same characters, so when the mechanism literal is absent, the regex engine must try every partition of the whitespace run between [^\n]* and \s+ before failing. The four regexes run unconditionally on every EHLO response, with no length cap, no shape validation, and no early rejection before the engine enters the ambiguous alternation.
Component: nodemailer (npm), SMTP client
Function: SMTPConnection._actionEHLO
Location: src/smtp-connection/index.ts, lines 2162, 2167, 2172, 2177
Patterns: /[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)PLAIN/i
/[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)LOGIN/i
/[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)CRAM-MD5/i
/[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)XOAUTH2/iImpact
Algorithmic-complexity denial of service against any Node.js process that opens an SMTP connection to an attacker-controlled or attacker-influenced host. Node.js is single threaded, so the process stalls entirely while the regex engine backtracks: no other requests are served, no timers fire, and the built-in socket timeout (10 minutes) cannot interrupt synchronous JavaScript. A 4,000-character whitespace run inside a single continuation line already blocks each regex for tens of seconds; the client bounds a response at 1 MB, which leaves headroom for blocking runs measured in hours across the four patterns. Two realistic attacker positions reach the sink pre-authentication: a hosted mailer that lets tenants configure their own SMTP server, and any network-adjacent attacker able to man-in-the-middle a cleartext SMTP connection (including before STARTTLS negotiation).
Proof of Concept
The PoC exercises the exact four regexes copied from src/smtp-connection/index.ts against a synthesized 250-AUTH<whitespace>NOMATCH line, so no live SMTP server is needed to reproduce the timing.
Runtime: Node.js >= 20
Dependencies: none
Invocation: node poc.js'use strict';
const AUTH_REGEXES = [
/[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)PLAIN/i,
/[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)LOGIN/i,
/[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)CRAM-MD5/i,
/[ -]AUTH(?:(\s+|=)[^\n]*\s+|\s+|=)XOAUTH2/i,
];
function bench(n) {
const line = '250-AUTH' + ' '.repeat(n) + 'NOMATCH';
const start = Date.now();
for (const re of AUTH_REGEXES) re.test(line);
return Date.now() - start;
}
for (const n of [500, 1000, 2000, 3000]) {
console.log(`n=${n} four-regex time=${bench(n)} ms`);
}
const control = '250-AUTH PLAIN LOGIN CRAM-MD5 XOAUTH2';
const t0 = Date.now();
for (const re of AUTH_REGEXES) re.test(control);
console.log(`well-formed control four-regex time=${Date.now() - t0} ms`);n=500 four-regex time=914 ms
n=1000 four-regex time=1348 ms
n=2000 four-regex time=10558 ms
n=3000 four-regex time=35251 ms
well-formed control four-regex time=0 msDoubling the whitespace run multiplies the wall time by roughly four, which matches the expected O(n^2) growth. The well-formed control shows that a normal EHLO response is parsed in effectively zero time.
Attack Chain
- Exposure: The victim application, or any dependent that uses
nodemailerto send mail, opens a TCP or TLS connection to an SMTP host the attacker controls. This happens automatically for multi-tenant mailers whose tenants configure their own outbound SMTP server, and for any client whose plaintext SMTP session can be intercepted by a network-adjacent attacker before STARTTLS negotiation. - Control: The attacker fully controls the bytes returned in response to
EHLO. In particular, the attacker chooses the length and content of every250-continuation line up to the client's 1 MB response cap. - Path: Socket bytes are reassembled by
_onData, decoded by_processResponse, and dispatched to_actionEHLO. On the first EHLO after the greeting (malicious server with no STARTTLS), on the second EHLO after a successful STARTTLS upgrade, or on the first EHLO whenignoreTLSis set, control reaches the AUTH detection block near the end of_actionEHLO. - Guard: The only bounds on this path are
maxResponseSize(1 MB by default) and the 421 or non-2xx status-code check. Neither prevents O(n^2) backtracking: 4,000 whitespace characters already block each regex for tens of seconds, well below the 1 MB cap. No length, shape, or sanitization check runs before the regexes. - Primitive: Four
RegExp.prototype.testcalls execute against the crafted line, each entering catastrophic backtracking because[^\n]*and\s+share the whitespace alphabet and the mechanism literal never matches. - Result: The Node.js event loop is blocked for the duration of the four regex evaluations. All other work in the process, including timers, unrelated requests, keep-alive traffic, and the SMTP socket timeout itself, is suspended until the regexes return.
Bypass Evidence
The only response-side protection in this code path is maxResponseSize, introduced by the fix for GHSA-4g23-2xm8-66gc (commit f2d82fa). That fix targeted quadratic reassembly of long multiline replies inside _onData and left the AUTH regex evaluation in _actionEHLO untouched. maxResponseSize does not prevent this issue: at 4,000 whitespace characters, roughly 0.4 percent of the default 1 MB cap, a single continuation line already blocks each of the four regexes for tens of seconds. No status-code or length gate rejects the payload before the regex engine enters the ambiguous alternation, and Node.js's single-threaded event loop cannot service the socket timeout while a synchronous test() call is running. Two other recent linear-time fixes in this project (the addressparser fallback for GHSA-v53p-9fqp-m79j and the DKIM header unfolding for GHSA-39m8-27wv-hr27) address entirely different modules and inputs and do not touch the AUTH mechanism regexes.
Affected Versions
- Ecosystem:
npm - Package:
nodemailer - Confirmed affected range:
>= 3.0.0, <= 10.0.12 - Latest release checked:
10.0.12(npm registry) - Fix status: 10.0.13
The four AUTH mechanism regexes were introduced when the SMTP client was bundled into nodemailer at 3.0.0 (previously a separate smtp-connection package). The vulnerable alternation (?:(\s+|=)[^\n]*\s+|\s+|=) is present, unchanged, in every published release from 3.0.0 (lib/smtp-connection/index.js) through 10.0.12 (dist/esm/smtp-connection/index.js and dist/cjs/smtp-connection/index.js). A later refactor added a leading [ -] character class but did not alter the ambiguous inner alternation. No release, and no development branch inspected at the current HEAD (30e4cfd), contains a fix for this pattern.
Suggested Fix
Replace the four backtracking regexes with a non-ambiguous parse of the AUTH extension. The invariant the fix must enforce is that mechanism detection runs in time linear in the response length regardless of whitespace shape. A minimal approach: match the AUTH extension value with a single non-backtracking pattern (for example, /[ -]AUTH(?:\s+|=)([^\r\n]*)/i) and then check for each mechanism name against the whitespace-split tokens with a Set lookup or includes. The fix must cover both continuation forms (250-AUTH ... and 250 AUTH ...) and both delimiters (space and =), and must handle the "AUTH advertised with no mechanisms" case without walking the whitespace run. As an interim mitigation, callers who never connect to an untrusted SMTP peer can restrict SMTP endpoints to a known allowlist; this does not help clients that must interoperate with arbitrary user-configured servers or with any cleartext SMTP path exposed to a network-adjacent attacker before STARTTLS.
---
Reported by zx (GitHub: @manus-pi).
Credited to manus-pi, manus-use.
Questions
- Does the attacker need credentials for the SMTP server?
No. The regexes run on the EHLO reply, before authentication. The attacker only needs to be the server your code connects to, or sit on an unprotected path to it.
- Does the 1 MB response cap protect me?
No. The advisory shows about 4,000 whitespace characters, roughly 0.4 percent of the cap, already block each pattern for tens of seconds.
- How is this different from GHSA-4g23-2xm8-66gc?
GHSA-4g23-2xm8-66gc is quadratic reassembly of multiline replies, fixed in 10.0.10. This one is regex backtracking in AUTH detection, fixed in 10.0.13. The first fix left these regexes untouched.
References
Read for this analysis:
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More npm vulnerabilities
All npm entriesGHSA-4g23-2xm8-66gc
Nodemailer: Quadratic (O(n^2)) SMTP client reply parsing lets a malicious server or MITM cause a pre-auth remote denial of service
medium5.9Oct 27, 2026GHSA-g73g-hqqh-jr95
Nodemailer: RFC 5322 comment inside an angle-bracket address is never stripped
medium5.3Oct 27, 2026GHSA-85x2-q946-cp5h
Nodemailer: A ">" inside a quoted local part ends an angle-addr early in addressparser, delivering to a domain the header does not name
medium6.5Oct 23, 2026GHSA-8c8m-p3m8-cjg8
Nodemailer: A nested comment ends early in addressparser, releasing the rest of the comment as a recipient
medium6.5Oct 23, 2026GHSA-m943-m63m-w62w
Nodemailer: A ";" inside a quoted string or comment ends an address group early in addressparser, turning display text into a recipient
medium6.5Oct 23, 2026CVE-2026-110871
Nodemailer: Quadratic (O(n^2)) DKIM header unfolding lets a large folded header cause remote denial of service during signing
medium6.5Oct 22, 2026
