wolfSSL — Improper Handling of Handshake Messages Fragmented Across Records in the TLS Sniffer
The wolfSSL sniffer discards a handshake message that continues in a later TLS record unless the rest of the message is already buffered. An endpoint of a monitored connection can fragment its handshake so that the sniffer never decodes the session.
- Advisory
- BYTERAY-2026-0353
- CVSS
- 5.3 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 through 5.9.4, builds with --enable-sniffer
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
The wolfSSL sniffer follows a TLS connection passively and decrypts it for an operator who holds the server key. To do that it has to read the handshake. TLS allows one handshake message to be carried in several records, and DoHandShake() in src/sniffer.c has a reassembly buffer for that case.
The reassembly is only reached when the bytes buffered behind the first record already cover the whole message. When the first fragment arrives on its own, which is the normal shape when each record travels in its own TCP segment, an earlier branch sets the remaining byte count to zero and returns success. The fragment is consumed and nothing is saved. The next record is then read as if it began a new handshake message. Builds without HAVE_MAX_FRAGMENT have no reassembly at all and always take the discarding branch.
Record boundaries are chosen by the sender. A client or server on a monitored connection can split a handshake message this way, and the sniffer loses the session while the real endpoints complete the handshake. There is no memory corruption. The sniffer is not part of a default build.
Affected Products and Versions
- Component: wolfSSL sniffer,
DoHandShake()and its callerProcessMessage()insrc/sniffer.c. - Required build:
WOLFSSL_SNIFFER(--enable-sniffer,configure.ac:3160-3165).HAVE_MAX_FRAGMENTchanges which branch is taken but both variants are affected.--enable-snifferdoes not defineHAVE_MAX_FRAGMENT;--enable-maxfragmentor--enable-tlsxdoes (configure.ac:9295-9299,configure.ac:9524-9532). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same branch order inDoHandShake(). - Partially fixed on master: builds with
HAVE_MAX_FRAGMENTnow reassemble; builds without it still discard. No release contains the change. - A default
./configurebuild does not include the sniffer. Earlier releases were not checked.
Technical Details
ProcessMessage() waits until a full record is buffered (src/sniffer.c:6722-6739) and then calls DoHandShake() with the record length rhSize and with sslBytes, the number of bytes from the start of this record's body to the end of the buffered input (src/sniffer.c:6814-6820). sslBytes includes any further records that are already buffered.
DoHandShake() reads the four-byte handshake header and compares the declared message size with what is buffered, at src/sniffer.c:4953-4964:
type = input[0];
size = (input[1] << 16) | (input[2] << 8) | input[3];
input += HANDSHAKE_HEADER_SZ;
*sslBytes -= HANDSHAKE_HEADER_SZ;
startBytes = *sslBytes;
if (*sslBytes < size) {
Trace(SPLIT_HANDSHAKE_MSG_STR);
*sslBytes = 0;
return ret;
}
ret is 0 here. The only record of the event is a trace line. The reassembly code follows this branch, at src/sniffer.c:4971-4996, and is compiled only with HAVE_MAX_FRAGMENT. It starts when rhSize < size, allocates session->tlsFragBuf and stores the first fragment. Because it sits after the branch above, it runs only when *sslBytes >= size, that is, when the buffered input behind the header is already at least as long as the whole message.
For a first fragment whose record ends the buffered input:
*sslBytesafter the header isrhSize - 4, which is less thansize. The branch atsrc/sniffer.c:4960-4964zeroes*sslBytesand returns 0.ProcessMessage()accepts the return value, computesusedas everything that was buffered and advances past it (src/sniffer.c:6825-6834). The input buffer is cleared atsrc/sniffer.c:7016-7017.session->tlsFragBufis stillNULL, so when the continuation record arrives the block atsrc/sniffer.c:4928-4946is skipped and its first four bytes are parsed as a handshake header atsrc/sniffer.c:4953-4954. The type and length are whatever the message body contains at that point.- If the dropped message was the ClientHello,
session->flags.clientHellostays 0 andProcessServerHello()ignores the ServerHello (src/sniffer.c:3931-3935). The sniffer has no cipher suite or randoms for the session.
Once reassembly has started, later fragments are appended correctly by the block at src/sniffer.c:4928-4946. The defect is in how the first fragment is handled.
Reachability and Preconditions
- The library is built with
--enable-snifferand an application uses the sniffer API on captured traffic. - The attacker is an endpoint of a connection the sniffer watches, for example a client connecting to a monitored server. No credentials are needed. Handshake records before the key change are sent in clear, and the sender chooses where records end.
- The peer has to accept a fragmented handshake message for the real handshake to succeed. TLS permits this fragmentation.
- No operator action is involved. Traffic that fragments handshake messages for ordinary reasons has the same effect.
Impact
Confirmed from source: a handshake message whose first fragment is not followed in the buffer by the rest of the message is consumed without being processed, no error is set, and the following record is misparsed as a new message. When the ClientHello is lost this way the sniffer ignores the ServerHello and cannot set up keys for the session. The operator gets no decrypted data for that connection. The effect is limited to the sessions whose handshake is fragmented. The monitored endpoints are not affected.
Not traced in detail: the exact error the session ends in when a later message than the ClientHello is lost. That depends on the message, the protocol version and the cipher suite.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
Partially fixed on wolfSSL master. Commit 4ce677e00e5eb2e791f1f20309e91ee1102667f9 (PR 11589, merged 2026-10-18) passes DoHandShake() only the bytes of the current record and moves the reassembly test ahead of the discarding branch. In builds with HAVE_MAX_FRAGMENT, a message longer than its record is now stored and completed from the following records regardless of what else is buffered.
Builds without HAVE_MAX_FRAGMENT are not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03). The reassembly code is still compiled out there, and the same branch still zeroes the count and returns success for every message that is longer than its record. --enable-sniffer alone produces such a build. Also on master, in both variants, a record that carries fewer than four bytes of a new handshake message ends the session with a fatal error.
The remaining fix is to compile the reassembly path whenever the sniffer is built, and to return a distinguishable result when a message cannot be completed so that the session is flagged and not silently desynchronised. Until then, sniffer deployments should build master with --enable-maxfragment (or --enable-tlsx) in addition to --enable-sniffer. On the 5.9.2 and 5.9.4 releases that option does not help for fragments that arrive in separate TCP segments. Operators should treat sessions that produce the "Handshake Message Split Across TLS Records" trace as not inspected.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-09-29 — Pull request 11589 opened upstream.
- 2026-10-18 — Pull request 11589 merged to master.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.