wolfSSL — Time-of-Check to Time-of-Use Race in CA Directory Loading for a WOLFSSL_CTX
When CA certificates are loaded from a directory, wolfssl_ctx_load_path accepts entries that were regular files at listing time and later opens each by name. A local process with write access to the directory can replace an entry between the check and the open, and the substituted content is installed as a trusted CA.
- Advisory
- BYTERAY-2026-0504
- 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 filesystem and directory support, where the application loads CA certificates from a directory with wolfSSL_CTX_load_verify_locations_ex
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
wolfSSL_CTX_load_verify_locations_ex() accepts a directory of CA certificates. The directory branch, wolfssl_ctx_load_path(), lists the directory and loads each entry as a trusted root. The only test that an entry is a regular file is made while the directory is listed. Each entry is then opened by name in a separate step.
The check and the open resolve the name independently. The check is a stat that follows symlinks. The full load of the previous entry, with its parse and install, runs between an entry's check and its open. A local process that can write, rename or create symlinks in the CA directory can replace an entry in that gap. The bytes that are opened are installed as trusted root CAs for the context.
Later TLS verification trusts those roots. Exposure is limited: the load normally runs once at startup, the window is short, and a process with standing write access to the CA directory can place a certificate there directly. The path requires no optional feature. It is compiled unless NO_FILESYSTEM or NO_WOLFSSL_DIR is defined, and it runs only when the application passes a directory.
Affected Products and Versions
- Component:
src/ssl_load.c,wolfssl_ctx_load_path(), the directory branch ofwolfSSL_CTX_load_verify_locations_ex(). - Required build: filesystem support, and directory support (
NO_WOLFSSL_DIRnot defined,src/ssl_load.c:3276-3279). The application must pass a directory path for CA loading. - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- No optional feature flag is needed. Applications that load CA certificates from a single file or from memory do not run this code.
- Other releases were not checked.
Technical Details
The loop in wolfssl_ctx_load_path() lists a name and then loads it (src/ssl_load.c:3138-3148):
ret = wolfssl_ctx_load_path_file(ctx, name, verify, (int)flags,
&failCount, &successCount);
/* Get next filename. */
fileRet = wc_ReadDirNext(readCtx, path, &name);
Data flow:
- The application calls
wolfSSL_CTX_load_verify_locations_ex()with a directory (src/ssl_load.c:3214). The directory branch callswolfssl_ctx_load_path()(src/ssl_load.c:3279). wc_ReadDirFirst()andwc_ReadDirNext()return the names of entries for whichwc_FileExists()succeeds (wolfcrypt/src/wc_port.c:1557). That is anXSTATplus a regular-file test, true at the moment of thestat.wolfssl_ctx_load_path_file()passes the name toProcessFile()as a CA (src/ssl_load.c:3144-3145,src/ssl_load.c:3076-3077).- The file is opened by name with
XFOPEN(fname, "rb")(src/ssl_misc.c:485). This is a new path resolution. - The content is parsed and added to the trust store of the
WOLFSSL_CTX.
Nothing on this path uses O_NOFOLLOW, and the opened file is not checked with fstat against the entry that was listed.
Reachability and Preconditions
- The application loads CA certificates from a directory.
- A local process with permission to write, rename or link in that directory. Weak permissions, or a shared staging or provisioning directory, are the realistic cases.
- The swap has to land during the load, which typically runs once at startup. A long-running application that reloads its verify locations offers the window again. There is no remote trigger.
Impact
Content chosen by the local process is installed as a trusted CA for the context. Certificates issued under that CA then pass verification, which allows impersonation of the servers or clients the application authenticates. The race adds no privilege over write access to the CA directory, because the same access allows a CA file to be placed there 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 make the check and the read refer to the same object. On POSIX platforms, open each entry relative to an open directory descriptor without following symlinks, fstat the result and require a regular file, then read the certificate from that descriptor. An open-then-fstat primitive in the portability layer would let the loaders receive a validated descriptor in place of a name. Windows has an equivalent with handle-based file information.
As a mitigation, CA directories should be owned by an administrative account and not writable by unprivileged users. This reduces exposure and does not replace the descriptor-based fix.
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.