SNI routing bypass to default SslContext via leading zero-length TLS handshake record (incomplete fix of CVE-2026-75595)
Description
Netty's SslClientHelloHandler inspects the first bytes of an inbound TLS connection to locate the ClientHello, parse the SNI host name, and select the matching per-host SslContext (for example a context that enforces client-certificate/mTLS). When the very first TLS record is a zero-length handshake record (22 03 03 00 00), decode() takes the packetLength == SSL_RECORD_HEADER_LENGTH branch and immediately calls select(ctx, null), which resolves to the default SslContext. Netty then replays the still-buffered bytes (the empty record followed by the attacker's real ClientHello) to a fresh SslHandler built from that default context. A compliant JDK/JSSE server SSLEngine skips the empty handshake record, parses the following ClientHello, extracts the real SNI, and completes a handshake on the wrong context. An unauthenticated remote attacker who prepends one empty handshake record can therefore have a connection whose SNI names a stricter, per-SNI-gated route served instead by the permissive default context. This is the same impact class as CVE-2026-75595 (GHSA-c4c3-7fpv-j4q5), reached through an input the fix for that issue does not cover.
Root Cause
Per-SNI context selection is a security decision: the handler must route a ClientHello to the SslContext bound to its SNI, or fail closed, so that any policy attached to that context (client-certificate/mTLS requirement, distinct trust settings) is enforced. The empty-handshake-record branch violates that invariant. A zero-length handshake record has packetLength == SSL_RECORD_HEADER_LENGTH, so the handler classifies it as "no ClientHello present" and calls select(ctx, null) instead of skipping the empty record and scanning the following record for the real ClientHello. A null ClientHello becomes a null SNI host name, and the domain-name mapping returns its default value for a null key, so the connection is served by the default context. The fix for CVE-2026-75595 added handshake reassembly logic to handle a handshake header split across records, but the empty-record branch returns before that logic runs, so the guard added by that fix never applies to this input.
Affected component: io.netty:netty-handler, package io.netty.handler.ssl
Primary function: io.netty.handler.ssl.SslClientHelloHandler.decode
Location: handler/src/main/java/io/netty/handler/ssl/SslClientHelloHandler.java (packetLength == SSL_RECORD_HEADER_LENGTH branch, select(ctx, null) early return)
Contributing (correct by design for a genuine no-SNI case):
io.netty.handler.ssl.AbstractSniHandler.lookup (null ClientHello -> null host name)
io.netty.util.DomainNameMapping.map (null key -> default value)Impact
An unauthenticated remote attacker who can open a TCP connection to a Netty TLS server that uses SNI-based context selection (SniHandler, or any AbstractSniHandler/SslClientHelloHandler subclass) can force selection of the default SslContext for a connection whose real SNI is mapped to a different, stricter context. In the worst credible in-scope deployment, per-SNI selection is the sole gate for a client-certificate/mTLS requirement and the default context is permissive; the attacker then reaches, over a completed TLS handshake, a route that should have required mutual authentication, bypassing that control. The confidentiality and integrity exposure is the service fronted by the default context, and it is gated on the deployment's context mapping (the same precondition as CVE-2026-75595). Where the default context fronts a sensitive backend that the SNI-selected context gates behind mTLS, the real-world consequence can be more severe; that escalation is plausible and deployment-dependent rather than demonstrated here. The demonstrated primitive is the routing/context-selection bypass itself, proven for the JDK (JSSE) TLS provider.
Proof of Concept
Reproduction uses a stock JDK (verified on JDK 17.0.20). No Netty runtime is required to demonstrate the two independent halves of the chain: (a) the handler's decode decision, reproduced by a source-faithful replica of the decode branch logic, and (b) the JSSE server engine's tolerance of a leading empty handshake record, reproduced against a real javax.net.ssl.SSLEngine in server mode.
Steps:
- Send, on a single connection, the five bytes
22 03 03 00 00(a handshake record of declared length 0), immediately followed by a normal TLS ClientHello record carryingserver_name = secure.example.com. - Observe that the handler selects the default context (decode replica output below).
- Feed the same byte sequence to a server-mode
SSLEngineand observe that it tolerates the empty record and still extracts the real SNI.
# Handler decode decision (source-faithful replica)
CONTROL (plain ClientHello record): CLIENT_HELLO (single record) -> extractSniHostname
ATTACK (empty handshake record + CH): SELECT_NULL (empty handshake record)
# Real JSSE server SSLEngine leniency (javax.net.ssl.SSLEngine, server mode)
CONTROL plain ClientHello: FINAL hs=NEED_WRAP remaining=0 sniSeen=secure.example.com
1x empty handshake record + ClientHello: FINAL hs=NEED_WRAP remaining=0 sniSeen=secure.example.com
3x empty handshake record + ClientHello: FINAL hs=NEED_WRAP remaining=0 sniSeen=secure.example.comNegative controls confirm the empty handshake record is uniquely effective: prepending an empty ChangeCipherSpec, Alert, or application-data record instead causes the engine to throw (Unrecognized SSL message, Invalid Alert message), so only the empty handshake record is both tolerated by the engine and mis-handled by the handler.
Attack Chain
- Exposure: An unauthenticated remote attacker opens a TCP connection to a Netty server whose pipeline performs SNI-based
SslContextselection. The decode path runs pre-handshake, before any authentication. - Control: The attacker fully controls the raw record bytes and sends a zero-length handshake record (
22 03 03 00 00) followed by a real ClientHello naming a target SNI. The bytes are read before any parsing or normalization can neutralize them. - Path:
SslClientHelloHandler.decodecomputespacketLength = getUnsignedShort(readerIndex+3) + 5 = 5; the record is complete, sopacketLength == SSL_RECORD_HEADER_LENGTHis true and the handler callsselect(ctx, null); return;with noskipBytes(the buffered bytes are retained).AbstractSniHandler.lookupmaps the null ClientHello to a null host name; the synchronous domain-name mapping returns the default value for the null key. - Guard: The
packetLength == SSL_RECORD_HEADER_LENGTHcheck is the only relevant guard and it fails open, defaulting instead of skipping the empty record or failing closed. The reassembly logic added by the fix for CVE-2026-75595 sits after this branch and is never reached for this input. - Primitive: The default
SslHandleris installed and, on removal of the byte decoder, the retained bytes (empty record plus real ClientHello) are forwarded to it. A compliant JDKSSLEngineskips the empty record, parses the real ClientHello, extracts the real SNI, and reachesNEED_WRAP. - Result: A valid TLS handshake completes on the default context for a connection whose SNI is mapped to a different, stricter context, bypassing the per-SNI policy (for example a client-certificate/mTLS requirement) attached to the intended route.
Bypass Evidence
The prior advisory GHSA-c4c3-7fpv-j4q5 (CVE-2026-75595) describes a distinct mechanism: a first-record handshake payload of 1 to 3 bytes makes handshakeLength = in.getUnsignedMedium(readerIndex + SSL_RECORD_HEADER_LENGTH + 1) throw IndexOutOfBoundsException, which is caught and routed to select(ctx, null). Its fix (released in 4.2.17.Final and 4.1.137.Final) is the ClientHello reassembly block that follows the empty-record branch. A source diff of the pre-fix and fixed releases confirms the fix rewrote only the reassembly logic and left the packetLength == SSL_RECORD_HEADER_LENGTH branch unchanged.
The zero-length case never reaches the reassembly mechanism, because the dedicated empty-record branch returns first. Independent tracing shows that if the empty-record branch did not short-circuit, the fixed reassembly logic would actually handle the empty record correctly: writeBytes(..., packetLength - 5 = 0) writes nothing, handshakeBuffer.readableBytes() (0) < 4 triggers continue, and the loop advances to the following record to parse the real ClientHello. This confirms the early return is the defect and that the fix is genuinely incomplete for this input rather than this being the same, already-covered vector.
Refutations attempted and defeated: (a) "the empty record makes the JDK engine reject or close the connection, so this is a self-inflicted denial of service rather than a routing bypass" was disproven by reproducing a real server SSLEngine reaching NEED_WRAP with the real SNI extracted for 1 and 3 leading empty records; (b) "the empty-record bytes are consumed and never replayed" was disproven by reading the branch (no skipBytes, aggregatedBytes == 0, cumulation forwarded on decoder removal); (c) "same input as the prior advisory, therefore a duplicate" was disproven by the distinct byte-length trigger and untouched code branch above. One limitation is recorded: engine leniency was proven only for the JDK (JSSE) TLS provider; OpenSSL/BoringSSL record-layer leniency for a leading empty handshake record was not tested and is excluded from this claim.
Affected Versions
Ecosystem: mavenPackage: io.netty:netty-handlerConfirmed affected range: >= 4.1.46.Final, <= 4.1.138.Final || >= 4.2.0.Final, <= 4.2.18.FinalLatest release checked: 4.2.18.Final (Maven Central)Fix status: not fixed
The vulnerable branch is present and unchanged in the latest released artifacts on both maintained lines, 4.1.138.Final and 4.2.18.Final, and in the reviewed checkout of the 4.2 branch. The SslClientHelloHandler class (and this branch) was introduced in 4.1.46.Final; it is absent in 4.1.45.Final, which establishes the lower boundary of the 4.1.x range. All 4.2.x releases inherit the branch. Because two maintained release lines are affected, the range is a union with no single global upper bound. The 5.0.0.Alpha prerelease line is outside the supported stable claim and was not tested (likely affected but unverified).
Suggested Fix
Enforce that a zero-length handshake record is skipped, not treated as "no ClientHello present". In SslClientHelloHandler.decode, the packetLength == SSL_RECORD_HEADER_LENGTH case should advance past the empty record and continue scanning subsequent records for the real ClientHello (the reassembly path already handles this correctly when reached), or fail the handshake closed, rather than calling select(ctx, null) and defaulting. The remediation must cover the empty-record case for every record position (a leading empty record and one or more empty records interleaved before the ClientHello), not only a single leading record, and it should be validated against the same JSSE leniency that makes the mismatch exploitable. As an interim mitigation without a code change, operators who rely on per-SNI SslContext selection as a security boundary should add a secondary peer-certificate/authentication check at the application layer and avoid a permissive default context, so that selection of the default context does not by itself bypass a route's mTLS or policy requirement.
Reported by zx (GitHub: @manus-pi).