Skip to content

SSLContext#min_version= and #max_version= silently accept prefix strings and empty strings #1158

Closed

Description

@VersaNexusIX

Description

parse_proto_version() in ext/openssl/ossl_ssl.c compares the input protocol version name using strncmp(map[i].name, RSTRING_PTR(str), RSTRING_LEN(str)) without verifying that the string lengths match.

// ext/openssl/ossl_ssl.c:879-882
    for (i = 0; i < numberof(map); i++)
        if (!strncmp(map[i].name, RSTRING_PTR(str), RSTRING_LEN(str)))
            return map[i].version;
    rb_raise(rb_eArgError, "unrecognized version %+"PRIsVALUE, str);

Actual Behavior

Because only RSTRING_LEN(str) bytes are compared:

  • "" (empty string), "S", or "SSL" silently matches "SSL2" (SSL2_VERSION)
  • "T", "TLS", or :TLS silently matches "TLS1" (TLS1_VERSION)
  • Strings with embedded NUL bytes (e.g., "TLS1\0_3") silently match "TLS1" (TLS1_VERSION)

Expected Behavior

Empty strings, partial prefixes, and strings containing embedded NUL bytes should raise ArgumentError (unrecognized version).

Suggested Fix

Verify that the string lengths are equal and compare using memcmp():

    for (i = 0; i < numberof(map); i++)
        if ((size_t)RSTRING_LEN(str) == strlen(map[i].name) &&
            memcmp(map[i].name, RSTRING_PTR(str), RSTRING_LEN(str)) == 0)
            return map[i].version;

(Discussed with @rhenium on security@ruby-lang.org and agreed to track here as a regular bug.)

Activity

  1. rhenium commented on Nov 19, 2026

    @rhenium
    Member

    Thank you for reporting it! I've opened #1160 with the suggested patch and a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions