Summary
A flaw in Deno's Node.js TLS compatibility layer can cause a client to send application data in cleartext after a connection retry, even though the application expects TLS.
When a network condition triggers the autoSelectFamily retry, the replacement TCP connection may never be upgraded to TLS, allowing an on-path attacker to observe or modify traffic the client believes is encrypted.
Affected context
This vulnerability appears in Deno applications that:
- Use the Node.js-compatible
tlslayer or modules relying on it - Enable
autoSelectFamilyfor connection handling - Perform connection retries across address families (e.g., IPv4/IPv6) under failure conditions
It becomes relevant in environments where a network intermediary or misconfiguration can force the first address-family attempt to fail, causing the client to transparently retry over a new TCP connection that might never be upgraded to TLS.
Exploit preconditions
- Attack surface: Client-side TLS connections made through Deno's Node.js compatibility layer.
- Required access: Ability for an attacker to position themselves on the network path (on-path/Man-in-the-Middle) and influence connectivity (e.g., dropping IPv6 traffic on dual-stack hosts).
- Trigger point: The initial address-family connection attempt must fail while
autoSelectFamilyis enabled, causing a retry over a new TCP socket. - Why exploitation is possible: The socket reinitialization path reuses a stale TLS upgrade hook bound to the original, failed handle, so the new TCP connection never completes the TLS handshake before application data is written and sent in plaintext.
Why this happens
At its core, the issue stems from incorrect state management in the TLS upgrade logic during socket reinitialization. When autoSelectFamily is enabled and the first connection attempt fails, the system creates a new TCP socket but continues to rely on a TLS upgrade hook associated with the now-invalid original socket.
This broken lifecycle management means the replacement connection bypasses the expected TLS handshake, mapping directly to CWE-319: Cleartext Transmission of Sensitive Information, where data assumed to be protected is instead sent without cryptographic safeguards.
Potential impact
- Network attackers may read application-layer data that was expected to be encrypted.
- Attackers could tamper with or inject messages into the connection before the client detects any anomaly.
- Sensitive information such as credentials, session tokens, or API payloads can be exposed in transit.
- Application protocols relying on TLS for integrity and confidentiality may be downgraded, enabling broader compromise.
General mitigation guidance
Effective mitigation patterns focus on ensuring that connection retries cannot bypass the security handshake and that transport security state is tied to the actual socket in use:
- Use connection management logic that rebinds TLS upgrade hooks to the current, live socket and validates that a full TLS handshake has completed before allowing application writes.
- Introduce explicit checks that prevent sending application data until a secure-connect signal from the active transport channel is observed, rather than relying on legacy or cached state.
- Design client connection abstractions so that address-family fallbacks and other retries cannot silently change the security properties of the underlying connection.
- Apply defense-in-depth by minimizing sensitive data in early client requests and using protocol-level safeguards (e.g., application-layer authentication and integrity checks) even over TLS.
How teams detect issues like this
To detect similar vulnerabilities, teams can:
- Use static analysis to flag patterns where TLS state or event hooks are stored and reused across socket lifecycles without explicit rebinding or verification.
- Conduct code reviews focused on connection retry logic, ensuring that every new transport instance re-enters a clear handshake state before application traffic is permitted.
- Employ runtime testing and chaos experiments that intentionally break initial connections (e.g., selectively dropping IPv6) and verify that retries retain full TLS protection.
- Integrate automated security checks into CI/CD pipelines that validate assumptions about encryption at the protocol level, such as inspecting test traffic captures for unexpected plaintext.

