← ALL ADVISORIES

LOW BYTERAY-2026-0413Disclosed

wolfSSL — Cleartext Storage of TLS 1.3 Traffic Secrets in Keylog Export File

In keylog-export builds, wolfSSL appends every TLS 1.3 traffic secret to sslkeylog.log in the working directory through a plain fopen call. The file gets umask-governed permissions, so on a common umask any local account can read it and decrypt the process's TLS 1.3 sessions.

Advisory
BYTERAY-2026-0413
CWE
CWE-312
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 through 5.9.4, builds with --enable-keylog-export (SHOW_SECRETS, HAVE_SECRET_CALLBACK and WOLFSSL_SSLKEYLOGFILE) and TLS 1.3
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL can export TLS secrets in the NSS key log format so that a capture can be decrypted in a protocol analyser. The feature is enabled at build time with --enable-keylog-export. In such a build tls13ShowSecrets() in src/tls13.c is installed as the secret callback on every connection object and appends each TLS 1.3 traffic secret to a log file.

The file is opened with fopen in append mode. No permissions are set, so on a POSIX system a new file is created with mode 0666 masked by the process umask; with the common umask 022 it is readable by every local account. The default path is sslkeylog.log, relative to the working directory of the process. Each handshake adds the client and server handshake and application traffic secrets, which are sufficient to decrypt that connection from a capture.

Writing these secrets to a file is what the option is for, and wolfSSL labels it insecure in the configure help and prints a warning when it is selected. The point of this advisory is narrower: the export file is not restricted to its owner, and the export is active for every connection without a run-time switch. Default builds do not contain this code.

Affected Products and Versions

  • Component: TLS 1.3 key log export, tls13ShowSecrets() in src/tls13.c, registered by InitSSL() in src/internal.c.
  • Required build: SHOW_SECRETS, HAVE_SECRET_CALLBACK, WOLFSSL_SSLKEYLOGFILE and WOLFSSL_TLS13. The configure switch --enable-keylog-export (configure.ac:2661-2671) and the CMake option WOLFSSL_KEYLOG_EXPORT (CMakeLists.txt:4420-4430) define the first three.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags open the file the same way. 5.9.2 has only the compile-time path; the optional SSLKEYLOGFILE environment variable lookup is present from 5.9.4.
  • Not fixed on master.
  • A default ./configure build does not include this code. Earlier releases were not checked.

Technical Details

The function is compiled under SHOW_SECRETS && WOLFSSL_SSLKEYLOGFILE (src/tls13.c:18635-18728). It selects and opens the output at src/tls13.c:18649-18668:

    keyLogFile = XGETENV("SSLKEYLOGFILE");
    if (keyLogFile == NULL || keyLogFile[0] == '\0')
        keyLogFile = WOLFSSL_SSLKEYLOGFILE_OUTPUT;
    fp = XFOPEN(keyLogFile, "ab");
#else
    fp = XFOPEN(WOLFSSL_SSLKEYLOGFILE_OUTPUT, "ab");
#endif

The first branch is compiled only with WOLFSSL_SSLKEYLOGFILE_USE_ENV, which --enable-keylog-export does not define. A plain keylog-export build takes the second branch. WOLFSSL_SSLKEYLOGFILE_OUTPUT defaults to "sslkeylog.log" (wolfssl/internal.h:8143-8148). XFOPEN is fopen (wolfssl/wolfcrypt/wc_port.h:1463-1468). An existing file at the path is appended to with whatever owner and mode it already has. When no file system is compiled in, the function writes to stderr instead.

The line is written at src/tls13.c:18712-18720: a label, the client random in hex, and the secret in hex. The label set is CLIENT_EARLY_TRAFFIC_SECRET, CLIENT_HANDSHAKE_TRAFFIC_SECRET, SERVER_HANDSHAKE_TRAFFIC_SECRET, CLIENT_TRAFFIC_SECRET_0, SERVER_TRAFFIC_SECRET_0, EXPORTER_SECRET and, in ECH builds, ECH_SECRET and ECH_CONFIG.

Data flow:

  1. InitSSL() calls wolfSSL_set_tls13_secret_cb(ssl, tls13ShowSecrets, NULL) for every new connection object (src/internal.c:9069-9072).
  2. The TLS 1.3 key schedule calls ssl->tls13SecretCb as each secret is derived (src/tls13.c:733-735, src/tls13.c:791-793, src/tls13.c:848-850, src/tls13.c:905-907, src/tls13.c:962-964, src/tls13.c:1008-1010). ECH does the same at src/tls.c:14449-14454.
  3. Each call opens the file, appends one line and closes it.

The tree has an owner-only open, wc_fopen_owner_only() (wolfcrypt/src/wc_port.c:6158-6182), which creates the file with mode 0600 and applies fchmod. At the tested commit it is used only for the session cache file. The key log writers do not use it.

Reachability and Preconditions

  • The library is built with --enable-keylog-export or the equivalent macros. That switch prints "Keylog export enabled -- Sensitive key data will be stored insecurely." and defines WOLFSSL_KEYLOG_EXPORT_WARNED, which silences the compile-time warning at src/tls.c:195-202.
  • The process completes TLS 1.3 handshakes. No application call is needed to start the export.
  • The attacker has a local account, or other read access to the directory the process runs in, and the umask in effect leaves the file readable. With a restrictive umask such as 077 the new file is owner-only.
  • To decrypt traffic the attacker also needs a capture of the connection.
  • The remote peer has no influence on this beyond opening connections.

Impact

Confirmed from source: an affected build writes the secrets of every TLS 1.3 connection to a file whose permissions come from the umask. Where that leaves the file readable to other accounts, they can decrypt captured TLS 1.3 traffic of the process, in both directions, for as long as the file is kept. The file also persists after the process exits and is picked up by backups.

The exposure exists only in builds where an integrator has chosen an option documented as insecure. ByteRay has no information on how often such builds are deployed outside debugging.

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).

The fix direction is to open the key log with the existing owner-only helper, so that the file is created with mode 0600 regardless of the umask, and to refuse or warn when an existing file at the path is readable by group or others. Requiring an explicit path instead of a default relative to the working directory, and a run-time opt-in, would keep a debug build from exporting secrets by accident.

Until then, do not ship builds with --enable-keylog-export. Where the option is needed for debugging, run the process with umask 077 in a directory only its user can read, and delete the file afterwards. The same applies to the TLS 1.2 writer described in BYTERAY-2026-0414, which appends to the same file.

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