wolfSSL — Time-of-Check to Time-of-Use Race in X509 Hash-Directory Certificate Lookup
The hash-directory fallback in LoadCertByIssuer checks that the issuer-hash file exists and then opens the same path again by name to load it as a trusted signer. A local process that can write to the directory can replace the file between the check and the open.
- Advisory
- BYTERAY-2026-0501
- CWE
- CWE-363
- CVSS
- 3.6 (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:N)
- Vendor
- wolfSSL
- Product
- wolfSSL
- Reported
- 2026-09-28
- Disclosure
- 2026-12-03
- Affected
- wolfSSL 5.9.2 (tested at master commit d95483f), builds with OPENSSL_ALL, WOLFSSL_CERT_GEN and WOLFSSL_CERT_REQ or WOLFSSL_CERT_EXT, with filesystem and directory support, where the application configures a hash-directory lookup on the X509 store
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
When a peer certificate's issuer is not in the trust store, builds with the OpenSSL compatibility layer can fall back to a hash-directory lookup. LoadCertByIssuer() builds a file name from the hash of the issuer name, checks that the file exists, then loads it by name and adds it to the store as a trusted signer.
The existence check and the load resolve the path separately. The check is a stat that follows symlinks. The load is a fresh fopen of the same name. Nothing ties the file that was checked to the file that is read. A local process that can write to the hash directory can replace the file between the two steps, by a rename or by switching a symlink.
The bytes that are read become a trusted CA, and the peer chain is verified again against them. The practical gain is small: a process that can write to that directory can also place a crafted <hash>.0 file there with no race. This is a hardening issue in how the library reads its trust-store files. A default build does not include this code path.
Affected Products and Versions
- Component:
src/internal.c,LoadCertByIssuer(), certificate branch (X509_LU_X509). - Required build:
OPENSSL_ALL,WOLFSSL_CERT_GEN, andWOLFSSL_CERT_REQorWOLFSSL_CERT_EXT, withoutNO_FILESYSTEM,NO_WOLFSSL_DIRorNO_STDIO_FILESYSTEM(src/internal.c:18559-18562). - Required configuration: the application has added a hash-directory lookup to the X509 store.
- Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- A default
./configurebuild does not defineOPENSSL_ALL(configure.ac:3296-3297) and does not reach this code. - Other releases were not checked.
Technical Details
The check and the use sit a few lines apart in the lookup loop (src/internal.c:16732-16738). wc_FileExists() calls XSTAT on the name and accepts a regular file (wolfcrypt/src/wc_port.c:1376). On POSIX builds that is stat(), which follows symlinks. wolfSSL_X509_load_certificate_file() then opens the name again with XFOPEN(fname, "rb") (src/x509.c:6096). The path uses no O_NOFOLLOW, no lstat, and no open followed by fstat.
Data flow:
- A TLS peer sends a chain whose signer is unknown.
ProcessPeerCertParse()returnsASN_NO_SIGNER_EorASN_SELF_SIGNED_E. ProcessPeerCerts()callsLoadCertByIssuer()with the certificate's issuer name (src/internal.c:18566,src/internal.c:19000).LoadCertByIssuer()returns early unless the store has a hash-directory lookup (src/internal.c:16643). It builds<dir>/<hash>.<N>from the issuer-name hash (src/internal.c:16723).wc_FileExists()stats that path (src/internal.c:16732).wolfSSL_X509_load_certificate_file()opens the same name a second time and parses it (src/internal.c:16735,src/x509.c:6096).- The result is added to the store with
wolfSSL_X509_STORE_add_cert()(src/internal.c:16738), and the peer certificate is parsed and verified again (src/internal.c:18573,src/internal.c:19007).
Steps 4 and 5 can resolve to different files when the directory changes between them.
Reachability and Preconditions
- Build flags as listed above, and a hash-directory lookup configured by the application.
- A local process with permission to create, rename or link files in the configured hash directory.
- A TLS peer that presents a chain with an unknown or self-signed issuer starts the lookup. The peer's issuer name selects which file name is probed. The peer does not control the file content.
- The swap has to land between the
statand thefopen.
Impact
Attacker-chosen CA material can enter the trust store, and a chain issued under it then verifies. The effect on confidentiality and integrity is limited, and there is no availability impact. The race grants nothing beyond its own precondition, because write access to the trust-store directory already allows the same injection directly.
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 to open the file once, without following symlinks where the platform supports it, confirm with fstat on the open descriptor that it is a regular file, and read the certificate from that same descriptor. Directory-relative opens anchored at a descriptor for the store directory keep the resolution inside the intended directory. As defense in depth, the loaded certificate's subject can be compared with the requested issuer name before it is added to the store.
Mitigation: make the hash directory writable only by the identity that administers the trust store. The code assumes this and does not enforce 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
LoadCertByIssuerexistence check and load at the tested commit- By-name open in
wolfSSL_X509_load_certificate_fileat the tested commit - BYTERAY-2026-0502, the same race on the CRL branch of the lookup
- BYTERAY-2026-0504, CA directory loading for a context
- BYTERAY-2026-0505, X509_STORE directory loading