wolfSSL — CR/LF Injection in directoryName Output of wolfSSL_GENERAL_NAME_print
wolfSSL_GENERAL_NAME_print prints a directoryName alternative name with the XN_FLAG_ONELINE flag set, which in wolfSSL did not include control-character escaping. Attribute values of the directory name are written to the output byte for byte, so a value containing CR or LF adds lines chosen by the certificate author to the printed text.
- Advisory
- BYTERAY-2026-0345
- 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_ALL (--enable-opensslall) whose application prints certificate alternative names with wolfSSL_GENERAL_NAME_print
- Fixed in
- Master commit 3eb95db74bcb8980c32bb806c2916fc16ee069bd (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 full X.500 directory name. wolfSSL_GENERAL_NAME_print() prints such an entry by calling the X.509 name printer with the XN_FLAG_ONELINE flag set. wolfSSL's name printer can escape control characters, but only when the caller asks for it with ASN1_STRFLGS_ESC_CTRL. wolfSSL's definition of XN_FLAG_ONELINE selected the separators and the short attribute names and nothing else.
Every attribute value in the directory name is therefore written as it appears in the certificate. A common name with an embedded line feed is printed across two lines, and the second line is text the certificate author wrote. In a log or audit record that text is indistinguishable from an entry written by the application. The function is part of the full OpenSSL compatibility layer, which a default build does not include. wolfSSL does not call it; an application has to.
Affected Products and Versions
- Component:
src/x509.c,wolfSSL_GENERAL_NAME_print(),GEN_DIRNAMEbranch;wolfssl/openssl/x509.h, definition ofWOLFSSL_XN_FLAG_ONELINE. - Required build:
OPENSSL_ALLwith BIO support (src/x509.c:5847).--enable-opensslallis off by default (configure.ac:3294-3298); several application-compatibility options turn it on (configure.ac:3299-3311). Directory names from a certificate are kept only when name constraints are compiled in, that is,IGNORE_NAME_CONSTRAINTSis not defined (src/internal.c:15709-15715). - Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
- The
v5.9.2-stableandv5.9.4-stabletags contain the same call and the same flag definition. Inv5.9.2-stablethe name printer has no control-character escaping under any flag. - Fixed on master. No wolfSSL release contains the fix.
- A default
./configurebuild does not include this code. Earlier releases were not checked.
Technical Details
The branch that prints a directory name (src/x509.c:5911-5918):
case GEN_DIRNAME:
ret = wolfSSL_BIO_printf(out, "DirName:");
ret = (ret > 0) ? WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
if (ret == WOLFSSL_SUCCESS) {
ret = wolfSSL_X509_NAME_print_ex(out, gen->d.directoryName, 0,
XN_FLAG_ONELINE);
}
break;
XN_FLAG_ONELINE is defined as WOLFSSL_XN_FLAG_SEP_CPLUS_SPC | WOLFSSL_XN_FLAG_SPC_EQ | WOLFSSL_XN_FLAG_FN_SN (wolfssl/openssl/x509.h:80). The name printer hands its flag word to the value escaping routine, where a byte below 0x20 or equal to 0x7F is replaced by a hex escape only if WOLFSSL_ASN1_STRFLGS_ESC_CTRL is set (src/x509.c:15642-15645). Without it the byte is copied (src/x509.c:15659-15668) and the value is written to the BIO (src/x509.c:15834).
How a certificate value reaches the branch:
- The certificate parser stores the contents of a directoryName alternative name without interpreting them (
wolfcrypt/src/asn.c:20550-20568), and they are copied to theWOLFSSL_X509object (src/internal.c:15709-15715). - The application calls
wolfSSL_X509_get_ext_d2i()for the subject alternative name extension. For a directory entry the function parses the stored bytes into anX509_NAME(src/x509.c:2573-2595). Each attribute value is kept with its encoded length and no character check (wolfcrypt/src/asn.c:15727-15732). - The application calls
wolfSSL_GENERAL_NAME_print()on the entry. - The name is printed with
XN_FLAG_ONELINE, and CR and LF in a value go to the BIO unchanged.
Reachability and Preconditions
- The application obtains alternative names with
wolfSSL_X509_get_ext_d2i()and prints them withwolfSSL_GENERAL_NAME_print(). No library code callswolfSSL_GENERAL_NAME_print(); the certificate text dump uses different code for alternative names. - The output goes to a log, terminal, audit record or other place where line structure carries meaning.
- The certificate comes from an untrusted source and does not have to be trusted. A peer certificate that fails verification is still handed to the application's verify callback as an object it can inspect (
src/internal.c:16320-16343). A TLS peer, client or server, can supply it with no credentials. - An application that passes
XN_FLAG_ONELINEtowolfSSL_X509_NAME_print_ex()itself, for a subject or issuer name, gets the same unescaped output.
Impact
Confirmed from source: CR, LF and other control bytes in an attribute value of a directoryName alternative name reach the output BIO unchanged. The certificate author controls the text after the injected line break, up to the length of the value. In a line-based log this allows forged or split entries; on a terminal, bytes such as ESC are passed through as well. Certificate parsing, verification and name matching are not affected.
Not verified: the effect on any particular application or log consumer.
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 3eb95db74bcb8980c32bb806c2916fc16ee069bd, part of PR 11682, merged 2026-10-15. The commit adds WOLFSSL_ASN1_STRFLGS_ESC_CTRL to WOLFSSL_XN_FLAG_ONELINE, so every user of that flag set, including this branch, prints a control byte as a backslash followed by two hex digits. The fix is on master only. No wolfSSL release contains it as of 2026-12-03.
Until a release is available: print alternative names to a memory BIO and escape or reject control characters before the text is written to a log or terminal. Applications that call wolfSSL_X509_NAME_print_ex() directly can add ASN1_STRFLGS_ESC_CTRL to the flags they pass; in 5.9.4 the name printer honours it.
The email, DNS and URI branches of the same function are described in BYTERAY-2026-0344. The same escaping routine called with no flags from the certificate text dump is 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.
References
GEN_DIRNAMEbranch ofwolfSSL_GENERAL_NAME_printat the tested commitWOLFSSL_XN_FLAG_ONELINEat the tested commit- Control-character branch of the name escaping routine at the tested commit
- wolfSSL pull request 11682
- Fix commit 3eb95db74bcb
- BYTERAY-2026-0344, email, DNS and URI output of the same function
- BYTERAY-2026-0351, subject and issuer names in the certificate text dump
- CWE-144: Improper Neutralization of Line Delimiters