wolfSSL — Incomplete Reset of the ECH Transcript Hash State in wolfSSL_clear
wolfSSL_clear() re-initializes the main handshake transcript but leaves the ECH transcript state in ssl->hsHashesEch. After an ECH handshake is aborted and the object is recycled, the next ECH handshake hashes its inner ClientHello onto the previous connection's transcript, the acceptance confirmation cannot match, and the handshake fails.
- Advisory
- BYTERAY-2026-0397
- CWE
- CWE-665
- CVSS
- 6.5 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:L)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds with HAVE_ECH (--enable-ech), TLS 1.3 applications that reuse WOLFSSL objects with wolfSSL_clear()
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
For Encrypted Client Hello (ECH), wolfSSL keeps a second handshake transcript in ssl->hsHashesEch. It is connection state: teardown frees it, and each path that completes or rejects ECH frees it and sets the pointer to NULL.
wolfSSL_clear(), which recycles a WOLFSSL object for a new connection, re-initializes the main transcript and does not touch the ECH one. The ECH code treats a non-NULL pointer as already initialized for the current connection. If a handshake is aborted after the ECH transcript was allocated, and the object is then recycled, the next ECH handshake skips initialization and hashes its inner ClientHello on top of the earlier connection's transcript.
The server then computes its ECH acceptance confirmation over the contaminated transcript, while the client verifies it over a clean one. The values do not match, ECH is rejected and the handshake fails. An unauthenticated peer can set this up by starting an ECH handshake and disconnecting partway through. ECH is not part of a default build.
Affected Products and Versions
- Component:
src/ssl.c,wolfSSL_clear(). The stale state is consumed byEchHashHelloInner()insrc/tls13.c. - Required build:
HAVE_ECHwith TLS 1.3 (the field is compiled only then,wolfssl/internal.h:6641-6643).--enable-echis off by default (configure.ac:2621-2623). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not include this code. Applications that allocate a newWOLFSSLobject per connection are not affected. - Other releases were not checked.
Technical Details
wolfSSL_clear() (src/ssl.c:5774-6089) resets options, keys, received-message flags and pending messages, and calls InitHandshakeHashes() for the main transcript (src/ssl.c:6073-6074). It has no reference to ssl->hsHashesEch. Teardown does free the field (src/internal.c:9931-9935), as do the ECH completion and rejection paths (src/tls13.c:5511-5515, src/tls13.c:5526-5533, src/tls13.c:6176-6177, src/tls13.c:7866-7871).
EchHashHelloInner() adopts the pointer and initializes only when it is NULL (src/tls13.c:4051-4057):
ssl->hsHashes = ssl->hsHashesEch;
if (ssl->hsHashes == NULL) {
ret = InitHandshakeHashes(ssl);
The sequence:
- Connection A allocates the ECH transcript. On a client this happens in
SendTls13ClientHello()(src/tls13.c:5296), on a server inDoTls13ClientHello()(src/tls13.c:8372-8381). The handshake then aborts before the acceptance step that frees it. - The application calls
wolfSSL_clear(). The main transcript is fresh.hsHashesEchstill points at connection A's hash contexts. - Connection B reaches
EchHashHelloInner(). The pointer is not NULL, so no initialization happens, and connection B's inner ClientHello is hashed into connection A's transcript. - On a server, decryption of the inner ClientHello still succeeds. The server adopts the contaminated transcript and writes its ECH acceptance confirmation over it (
src/tls13.c:7866-7871). - The client verifies the confirmation over its own transcript. The comparison fails, the client treats ECH as rejected (
src/tls13.c:5526-5533), and the handshake fails.
A completed ECH handshake without HelloRetryRequest frees the slot itself, so only aborted handshakes leave it set. The stale allocation and its hash contexts stay in memory across reuse cycles until the object is freed.
Reachability and Preconditions
- Build with
HAVE_ECH; ECH is configured and in use. - The application reuses
WOLFSSLobjects withwolfSSL_clear(). - A handshake on the object was aborted after the ECH transcript was allocated. On a server, an unauthenticated client causes this by sending a ClientHello with a valid ECH extension and then disconnecting. The next connection on the object uses ECH.
Impact
The next ECH handshake on the recycled object fails. A remote peer can repeat the setup each time the object is recycled, so the failure is repeatable. Connections served by such an object do not get the protection of client metadata that ECH provides. The inner ClientHello is discarded and is not sent in the clear, so its contents are not disclosed directly. There is no memory-unsafe access; the failure is fail-closed.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.
The fix direction is for wolfSSL_clear() to free ssl->hsHashesEch and set it to NULL, in the same way teardown does. More generally, each field that teardown releases needs a matching reset in wolfSSL_clear(). EchHashHelloInner() can also stop inferring freshness from a non-NULL pointer. Applications can avoid the condition by allocating a new WOLFSSL object per connection instead of calling wolfSSL_clear().
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.