wolfSSL — CR/LF Injection in subjectAltName directoryName Entries Printed by wolfSSL_X509_print
When the certificate text dump in wolfSSL's OpenSSL compatibility layer prints a directoryName subject alternative name, it copies the country, organization, unit and common name values into the output byte for byte. A value that contains CR or LF adds lines of the certificate author's choosing to the printed text. The whole entry is limited to under 80 bytes.
- Advisory
- BYTERAY-2026-0350
- CWE
- CWE-144
- CVSS
- 5.3 (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/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 OPENSSL_EXTRA (--enable-opensslextra) and name-constraint support whose application prints untrusted certificates with wolfSSL_X509_print
- Fixed in
- Master commit ca5806224df0b36af17f869948a07bf759b61bc3 (PR 11682, merged 2026-10-15). Not in a wolfSSL stable release as of 2026-12-03.
- Credit
- Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.
Executive Summary
A subject alternative name can be a directoryName, which is a full X.500 name nested inside the extension. wolfSSL_X509_print prints such an entry with a small dedicated routine that looks for the C, O, OU and CN attributes and writes them as C=..., O=..., OU=..., CN=....
That routine copies each attribute value with a memory copy. It checks the string type but never the characters. A value that contains CR or LF is written unchanged, and the dump gains a line break followed by text the certificate author chose.
The injected text is short, since the whole entry must fit in an 80-byte buffer, but a short forged line is enough to mislead a log reader or a parser. The code is in the OpenSSL compatibility layer, which is not in a default build, and the application has to call the print function on a certificate it did not create.
Affected Products and Versions
- Component:
src/x509.c,X509PrintDirType(), called byX509_print_name_entry()fromwolfSSL_X509_print_ex(),wolfSSL_X509_print()andwolfSSL_X509_print_fp(). - Required build:
OPENSSL_EXTRAwith BIO support (src/x509.c:6847-6848), andIGNORE_NAME_CONSTRAINTSnot defined, because directoryName entries are decoded and attached only then (wolfcrypt/src/asn.c:20548-20569,src/internal.c:15709-15715).--enable-opensslextrais off by default (configure.ac:3314-3318). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same copy. - Fixed on master. No wolfSSL release contains the fix.
- A default
./configurebuild does not include this code. Earlier releases were not checked.
Technical Details
X509PrintDirType() scans the stored directoryName encoding for the three-byte attribute identifiers of C, O, OU and CN (src/x509.c:6863-6869, src/x509.c:6906-6907). For each match it requires a PrintableString, IA5String or UTF8String (src/x509.c:6930-6936), reads the length, writes the label and then copies the value (src/x509.c:6960-6964):
XMEMCPY(dst, &src[i], fld_len);
i += fld_len;
dst += fld_len;
total_len += fld_len;
bytes_left -= fld_len;
The caller writes the buffer to the BIO (src/x509.c:7024-7032, src/x509.c:7064-7065). No step looks at the bytes of the value.
How the bytes arrive:
- The extension decoder stores the content of the directoryName as an entry, with its encoded length (
wolfcrypt/src/asn.c:20550-20568). - The entry is merged into the alternative name list of the
WOLFSSL_X509object (src/internal.c:15709-15715). - The extension printer calls
X509PrintSubjAltName()(src/x509.c:7450), which callsX509_print_name_entry()(src/x509.c:7357-7363). - For an entry of this type,
X509_print_name_entry()callsX509PrintDirType()and writes the result.
Three limits apply. The routine stops when a value does not fit in what is left of the 80-byte buffer (src/x509.c:6955-6958). If the formatted entry reaches 80 bytes, the whole print fails (src/x509.c:7060-7063). The write uses the string length of the buffer, so a NUL byte ends the output (src/x509.c:7064). Within those limits a value of a few dozen bytes is printed in full. The printed entry has no DirName: label. That text appears only as a placeholder when nothing in the entry was printable (src/x509.c:7030).
Reachability and Preconditions
- The application calls one of the print functions on a certificate from an untrusted source, and sends the output to a log, an audit record, a terminal or a parser. The library does not print peer certificates by itself.
- The certificate does not need to be trusted. A peer certificate is handed to the application's verify callback as a
WOLFSSL_X509whether or not verification succeeded (src/internal.c:16320-16343). - A TLS peer, client or server, can supply such a certificate with no credentials, because it chooses its own subject alternative names.
- The same routine prints holder and issuer directory names of attribute certificates in
WOLFSSL_ACERTbuilds (src/x509.c:8262,src/x509.c:8275,src/x509.c:8293).
Impact
Confirmed from source: CR, LF and other control bytes in the C, O, OU or CN value of a directoryName entry reach the output BIO unchanged. The certificate author controls a few dozen bytes after the injected line break. The effect is limited to the printed text: forged or split lines in a log or report, and control bytes such as ESC passed to a terminal. Name constraint checking and certificate verification are separate code and are not changed by this issue.
ByteRay did not build a proof of concept for this issue. The analysis is from source review.
Remediation and Mitigation
Fixed on master by commit ca5806224df0b36af17f869948a07bf759b61bc3, part of PR 11682, merged 2026-10-15. The commit escapes control characters in the attribute values this routine prints. A later commit in the same pull request, 944d175297fd03dc8963cd7059e03eb6dcf7f234, changes the routine to write to the BIO directly through the shared escaping helper. On master a control byte is printed as a backslash followed by two hex digits. The fix is on master only. No wolfSSL release contains it as of 2026-12-03; the newest release tag, v5.9.4-stable, does not. The tag rust/wolfssl-wolfcrypt/v3.0.0, which marks a version of the Rust wrapper, points at a master snapshot that includes it.
Until a release is available: print untrusted certificates into a memory BIO and escape or reject control characters before the text reaches a log or terminal.
The DNS, email and URI entries printed by the calling function are covered in BYTERAY-2026-0349. Subject and issuer names are covered in BYTERAY-2026-0351.
Timeline
- 2026-09-28 — Reported to wolfSSL.
- 2026-10-07 — Pull request 11682 opened upstream.
- 2026-10-15 — Pull request 11682 merged to master.
- 2026-12-03 — Public disclosure.
Credits
Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.