← ALL ADVISORIES

LOW BYTERAY-2026-0505Disclosed

wolfSSL — Time-of-Check to Time-of-Use Race in X509_STORE Directory Loading

wolfSSL_X509_STORE_load_locations accepts directory 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 in between. wolfSSL_X509_STORE_set_default_paths also takes the directory from SSL_CERT_DIR.

Advisory
BYTERAY-2026-0505
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 that provide the X509_STORE API with filesystem and directory support, where the application calls wolfSSL_X509_STORE_load_locations with a directory or wolfSSL_X509_STORE_set_default_paths
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL_X509_STORE_load_locations() loads trusted certificates and CRLs from a directory into an X509_STORE. It lists the directory, relies on a regular-file test made during the listing, and then opens each entry by name to parse it. wolfSSL_X509_STORE_set_default_paths() calls the same loader with locations read from the SSL_CERT_FILE and SSL_CERT_DIR environment variables.

The test and the open are two independent file-system operations. Between them the name can be replaced or pointed at another file, for example with a symlink. The library parses whatever it reads and installs it as a trusted certificate or as a CRL. A local process that can write to the certificate directory can use this to put its own content into the trust anchors of the process.

The pass over the directory happens once, when the store is set up, so the window is brief. A process with write access to that directory can also place a CA or CRL file there directly. The race grants nothing beyond its own precondition. Applications that do not call either function with a directory are not affected.

Affected Products and Versions

  • Component: src/x509_str.c, wolfSSL_X509_STORE_load_locations() and its caller wolfSSL_X509_STORE_set_default_paths().
  • Required build: the X509_STORE compatibility API, without NO_FILESYSTEM or NO_WOLFSSL_DIR (src/x509_str.c:2320). wolfSSL_X509_STORE_set_default_paths() also needs XGETENV (src/x509_str.c:2485).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The code runs only when the application loads a store from a directory through one of these two functions.
  • Other releases were not checked.

Technical Details

The directory loop hands each listed name to a separate loader (src/x509_str.c:2453-2464):

        ret = wc_ReadDirFirst(readCtx, dir, &name);
        while (ret == 0 && name) {
            WOLFSSL_MSG(name);

            ret = X509StoreLoadFile(str, name);

Data flow:

  1. The directory comes from the application, or from the environment through wolfSSL_X509_STORE_set_default_paths() (src/x509_str.c:2494-2497).
  2. wc_ReadDirFirst() and wc_ReadDirNext() return the names of entries for which wc_FileExists() succeeds (wolfcrypt/src/wc_port.c:1557). This is an XSTAT that follows symlinks, plus a regular-file test. Its result describes the entry at listing time only.
  3. X509StoreLoadFile() receives the name (src/x509_str.c:2457) and calls X509StoreReadFile() (src/x509_str.c:2369).
  4. X509StoreReadFile() calls wolfssl_read_file_static() (src/x509_str.c:2332), which opens the name again with XFOPEN(fname, "rb") (src/ssl_misc.c:485).
  5. The content is classified as a certificate or a CRL by looking for the CRL PEM header (src/x509_str.c:2338-2343).
  6. It is installed in the store as a trusted certificate or as a CRL (src/x509_str.c:2375-2383). On this path the CRL is loaded with the verify argument set to 0 (src/x509_str.c:2381-2382).

No step uses O_NOFOLLOW, and nothing compares the opened file with the entry that was listed. The content classification only labels the bytes that were read. It cannot tell that the object changed.

Reachability and Preconditions

  • The application calls wolfSSL_X509_STORE_load_locations() with a directory, or wolfSSL_X509_STORE_set_default_paths().
  • A local process that can write, rename or link in the certificate directory. With wolfSSL_X509_STORE_set_default_paths(), a party that can set SSL_CERT_DIR or SSL_CERT_FILE for the process chooses the location itself.
  • The swap has to land between the listing and the open of an entry, during the single load pass. There is no remote trigger.

Impact

The trust store of the process can be made to hold a CA or a CRL chosen by the local party. A planted CA lets certificates issued under it verify. A planted CRL can affect revocation decisions. The realism is low: the window exists once at initialization, the same directory access allows direct placement of a file, and a party able to set a service's environment usually controls the service already. The case that matters is a shared host where control of the environment or the directory comes with narrower privileges.

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 use the same file-system object. Open each entry during enumeration, without following symlinks where supported, fstat the descriptor and require a regular file, then parse from that descriptor. Where a path-based open has to remain, compare device and inode after the open with the values seen at listing time. The environment-supplied default paths should be treated as untrusted input, or the risk documented. As a mitigation, keep certificate directories writable only by the administering identity, and do not call wolfSSL_X509_STORE_set_default_paths() in processes whose environment is set by a less trusted party.

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