← ALL ADVISORIES

MEDIUM BYTERAY-2026-0338Disclosed

wolfSSL — Cleartext Storage of Session Secrets in Persisted Session Cache File

wolfSSL_save_session_cache writes the in-memory session cache to a file verbatim, including each session's master secret and ticket data, with no encryption. On POSIX the file is created with mode 0600 since 5.9.4; in 5.9.2 and on other platforms its permissions come from a plain fopen call.

Advisory
BYTERAY-2026-0338
CWE
CWE-312
CVSS
6.8 (CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with PERSIST_SESSION_CACHE (--enable-savesession), when the application calls wolfSSL_save_session_cache
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL can save its TLS session cache to a file so that sessions survive a process restart. wolfSSL_save_session_cache() does this by writing the cache structures to the file exactly as they sit in memory. Each cached session carries its master secret (for TLS 1.3, the resumption master secret), its session ID and any stored session ticket. Nothing is encrypted.

Protection of the file rests on file permissions alone. At the tested commit and in 5.9.4, POSIX builds create the file with mode 0600. In 5.9.2, and on any platform where the owner-only helper is not available, the file is opened with a plain fopen call and gets whatever mode the process umask and platform produce.

Anyone who can read the file obtains the secrets of every session in the cache. That includes other code running as the same user, privileged users, and anything that later handles a copy of the file, such as a backup.

The feature is optional and off by default. wolfSSL's API documentation at the tested commit warns that the file holds these secrets in the clear, so this is documented behaviour that integrators need to account for.

Affected Products and Versions

  • Component: session cache persistence, wolfSSL_save_session_cache() in src/ssl_sess.c.
  • Required build: PERSIST_SESSION_CACHE, set by --enable-savesession (configure.ac:3614-3623), by --enable-all (configure.ac:1430), by --enable-jni (configure.ac:9952-9956) and by the CMake option WOLFSSL_SAVESESSION. A file system is required.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.4-stable tag has the same code as the tested commit.
  • The v5.9.2-stable tag writes the same structures, and opens the file with XFOPEN(fname, "w+b") instead of the owner-only helper.
  • Not fixed on master.
  • A default ./configure build does not include this function. Earlier releases were not checked.

Technical Details

The function is at lines 600 to 678 of src/ssl_sess.c. It opens the file at src/ssl_sess.c:610, writes a small header, and then writes each cache row (src/ssl_sess.c:645) and the client cache (src/ssl_sess.c:666):

    file = wc_fopen_owner_only(fname);
    ...
        ret = (int)XFWRITE(&SessionCache[i], SIZEOF_SESSION_ROW, 1, file);
    ...
    ret = (int)XFWRITE(ClientCache, sizeof(ClientCache), 1, file);

A SessionRow embeds its WOLFSSL_SESSION entries by value (wolfssl/ssl_sess.h:93-109). The fields of WOLFSSL_SESSION that reach the file include:

  • masterSecret[SECRET_LEN] (wolfssl/internal.h:5096). For TLS 1.3 sessions this field holds the resumption master secret.
  • The session ID (wolfssl/internal.h:5092-5094).
  • The TLS 1.3 ticket nonce (wolfssl/internal.h:5129) and the inline ticket buffer staticTicket[] (wolfssl/internal.h:5136).

No field is removed, encrypted or wrapped before the write.

wc_fopen_owner_only() (wolfcrypt/src/wc_port.c:6158-6182) opens with O_RDWR | O_CREAT | O_TRUNC and mode S_IRUSR | S_IWUSR, then calls fchmod with the same mode unless WOLFSSL_NO_FCHMOD is defined. The real function exists only on Unix-like builds that have XFDOPEN. Elsewhere the name is a macro for XFOPEN((path), "w+b") (wolfssl/wolfcrypt/wc_port.h:2168-2194).

The owner-only open was added by wolfSSL pull request 11291, merged on 2026-09-03, before ByteRay's report. The same change added a warning to the API documentation (doc/dox_comments/header_files/ssl.h:3423-3429) which says the file "holds session master secrets and resumption credentials in the clear" and that the caller must place it where only the intended user can read it.

Reachability and Preconditions

  • The library is built with session cache persistence.
  • The application calls wolfSSL_save_session_cache(). Nothing in the library calls it on its own.
  • The attacker can read the resulting file:
    • In 5.9.4 on POSIX: as the owning user or a privileged user, or through a copy of the file that left the host.
    • In 5.9.2, or on a platform without the owner-only helper: additionally any local account, when the umask or the platform default leaves the file readable.
  • No network position is needed to read the file. Using the secrets requires either a captured handshake or the ability to connect to the same peer.

Impact

Confirmed from source: the file contains, in cleartext, the master secret of every session in the cache at the time of the save, with the session ID and stored ticket data.

A TLS 1.2 master secret, combined with the random values that are visible in a captured handshake, is the input from which that connection's record keys are derived. A reader of the file who also holds a capture of such a connection can decrypt it. The stored secrets and tickets are also the credentials a peer presents to resume a session, so a reader may be able to resume a cached session for as long as the other side still accepts it.

How far this reaches depends on the deployment: file location, umask, release, and who else runs code under the same account. ByteRay did not examine any deployment.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

Remediation and Mitigation

Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03).

On master the file is still a verbatim copy of the cache structures. Removing the exposure would mean encrypting the saved cache under a key the application supplies, or not persisting the secrets.

Integrators can reduce exposure now:

  • Do not build with --enable-savesession unless the application needs sessions to survive a restart. Note that --enable-all and --enable-jni turn it on.
  • If on 5.9.2, upgrade to 5.9.4 so that POSIX builds create the file with mode 0600, or set umask 077 before the call.
  • On platforms without the owner-only helper, place the file in a directory that only the service account can read.
  • Keep the file out of backups and images, and delete it after wolfSSL_restore_session_cache() has loaded it.

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.

References