Details
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
{
"attackerConfiguredServername": "attacker.test",
"victimConfiguredServername": "victim.test",
"serverObservedSniForBothConnections": [
"attacker.test",
"attacker.test"
],
"serverReceivedCredentials": [
"\\[email protected]\\u0000attacker-secret",
"\\[email protected]\\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:
- send the attacker's server name as SNI;
- be routed to the attacker's TLS virtual host;
- validate the attacker's certificate against the stale name, even though strict certificate validation is enabled; and
- 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
hostcache key and differenttls.servernamevalues. - 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:
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.