← ALL ADVISORIES

LOW BYTERAY-2026-0423Disclosed

wolfSSL — Control-Character Escaping Flags Ignored by wolfSSL_ASN1_STRING_print_ex

wolfSSL_ASN1_STRING_print_ex accepts the ASN1_STRFLGS_ESC_CTRL and ASN1_STRFLGS_ESC_MSB flags but never tests them. With any flag combination other than a hex dump, CR, LF and other control bytes of the string are written to the output unchanged, so an application that relies on these flags to print certificate strings safely gets no escaping.

Advisory
BYTERAY-2026-0423
CWE
CWE-144
CVSS
3.7 (CVSS:3.1/AV:N/AC:H/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 and master, builds with OPENSSL_EXTRA whose application prints certificate strings with wolfSSL_ASN1_STRING_print_ex
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

wolfSSL_ASN1_STRING_print_ex() is wolfSSL's version of the OpenSSL function ASN1_STRING_print_ex(). The caller passes flags that say how the string is to be escaped. Two of them, ASN1_STRFLGS_ESC_CTRL and ASN1_STRFLGS_ESC_MSB, ask for control characters and bytes with the top bit set to be escaped. Both are also part of the commonly used ASN1_STRFLGS_RFC2253 set.

wolfSSL defines these flags and accepts them, but the function contains no code for them. It either dumps the string as hex, or writes it with a backslash before five punctuation characters, or writes it raw. A carriage return or line feed in the string reaches the output in the last two cases. When the string comes from a certificate, for example a subject attribute value, the certificate's author can break the output line and add text after it. The function is in the OpenSSL compatibility layer, which a default build does not include, and the library itself never calls it.

Affected Products and Versions

  • Component: src/ssl_asn1.c, wolfSSL_ASN1_STRING_print_ex() and its helper wolfssl_asn1_string_print_esc_2253().
  • Required build: OPENSSL_EXTRA with BIO support (src/ssl_asn1.c:3428-3431). --enable-opensslextra is off by default (configure.ac:3314-3318); many application-compatibility options turn it on (configure.ac:12708-12714).
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • The v5.9.2-stable and v5.9.4-stable tags contain the same three branches and the same escape set.
  • Not fixed on master as of 2026-12-03.
  • A default ./configure build does not include this code. Earlier releases were not checked.

Technical Details

After an optional type prefix, the function chooses one of three ways to print (src/ssl_asn1.c:3706-3717):

        else if (flags & WOLFSSL_ASN1_STRFLGS_ESC_2253) {
            /* Print out string with escaping. */
            str_len = wolfssl_asn1_string_print_esc_2253(bio, str);
        }
        else {
            /* Get number of characters to write. */
            str_len = str->length;
            /* Print out string as is. */
            if (wolfSSL_BIO_write(bio, str->data, str_len) != str_len) {
                err = 1;
            }
        }

The branch before these is the hex dump for ASN1_STRFLGS_DUMP_ALL (src/ssl_asn1.c:3701-3705). The helper for the first branch shown writes the string one byte at a time and puts a backslash before a byte only if it is one of +, ;, <, > or \ (src/ssl_asn1.c:3614-3630, src/ssl_asn1.c:3646-3664). The flags that would cover control bytes are defined at wolfssl/ssl.h:370-371 and included in the RFC 2253 set at wolfssl/ssl.h:379-384. Neither is tested anywhere in the function or its helpers.

The result for the flag values an application is likely to pass:

  1. No escape flag, or ASN1_STRFLGS_ESC_CTRL or ASN1_STRFLGS_ESC_MSB without ASN1_STRFLGS_ESC_2253: the whole string, str->length bytes, goes to the BIO in one write (src/ssl_asn1.c:3714).
  2. ASN1_STRFLGS_RFC2253 or any other value with ASN1_STRFLGS_ESC_2253: each byte up to the first NUL is written, with only the five characters above escaped (src/ssl_asn1.c:3660).
  3. ASN1_STRFLGS_DUMP_ALL: hex output; not affected.

Reachability and Preconditions

  • The application calls wolfSSL_ASN1_STRING_print_ex() (or ASN1_STRING_print_ex() through the compatibility header, wolfssl/openssl/ssl.h:1086). No library code calls it.
  • The string holds bytes an attacker controls. Certificate strings qualify: wolfSSL_X509_NAME_ENTRY_get_data() returns the stored value of a subject or issuer attribute (src/x509.c:6835-6843), and a peer certificate that fails verification is still handed to the application's verify callback (src/internal.c:16320-16343).
  • The output goes to a log, terminal, audit record or other place where line structure carries meaning.
  • The flags passed do not include ASN1_STRFLGS_DUMP_ALL.

Impact

Confirmed from source: CR, LF and other control bytes, and bytes of 0x80 and above, are written to the BIO unchanged whether or not the caller sets ASN1_STRFLGS_ESC_CTRL or ASN1_STRFLGS_ESC_MSB. An application that passes ASN1_STRFLGS_RFC2253 or ASN1_STRFLGS_ESC_CTRL and expects control characters to be escaped does not get that protection. With attacker-chosen string content this allows forged or split lines in line-based output and terminal control sequences on a terminal. Certificate parsing and verification 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

Not fixed on wolfSSL master as of commit e4b0841b32e7 (2026-12-03). The function there has the same three branches and still does not test the two flags. A change merged in November 2026 bounds the helper's loop by the string length, which is the separate issue in BYTERAY-2026-0371.

A fix would honour ASN1_STRFLGS_ESC_CTRL by writing bytes below 0x20 and 0x7F as a backslash and two hex digits, and ASN1_STRFLGS_ESC_MSB likewise for bytes of 0x80 and above, in both the RFC 2253 branch and the plain branch. The name printing code in src/x509.c already does this for control bytes when given the flag (src/x509.c:15642-15645).

Until then: do not rely on the escape flags of this function. Print to a memory BIO and escape or reject control characters before the text is written to a log or terminal, or pass ASN1_STRFLGS_DUMP_ALL where hex output is acceptable.

The simpler wolfSSL_ASN1_STRING_print() has related behaviour, described in BYTERAY-2026-0344 and BYTERAY-2026-0422.

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