ExportXMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Security
    • ALL
    • Hide

      The exact payload and the observed crash output are in SECBUG-6434 (security_signals preauth-long-oid-terminate); they are not repeated here.

      Show
      The exact payload and the observed crash output are in SECBUG-6434 (security_signals preauth-long-oid-terminate); they are not repeated here.
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Overview

      See SECBUG-6434 for the finding, the pre-auth call path, reproduction, CVSS scoring and the Minios fix contract (code anchors, invariants and three named tests). This ticket covers the engineering fix and the gaps found while triaging it. 

      Additional Findings Not In the SECBUG Ticket

      Off-by-one in the same function, so the contract's "preservation" test is red on master. x509ShortNameToOid (src/mongo/util/net/ssl_manager.cpp) resizes the buffer to the length OBJ_obj2txt returns. That length excludes the terminating NUL. The second OBJ_obj2txt call is then given a buffer with no room for the NUL, so it writes one character fewer. The function returns a string of the full length whose last byte is NUL. This is confirmed with a standalone copy of the logic against the system OpenSSL. Results:

      • 103-char OID: wrong (last digit replaced by 0x00)
      • 583-char OID: wrong (same)
      • 1203-char OID: OBJ_obj2txt returns -1 (the SECBUG crash)

      So every numeric OID longer than 79 characters converts incorrectly today. The contract's unit-long-valid-oid-roundtrip test treats exact round-tripping as an existing invariant. It is not: it fails on master and passes only once this off-by-one is fixed. The contract's control run did not show this because it only observed that authentication failed without a crash, not that the OID text was correct. The bug fails closed: the corrupted OID never matches a certificate-derived OID, so it causes a mismatch rather than an impersonation. It still needs fixing in the same change.

      Exposure is wider than the SECBUG's CVE text. SaslX509ServerMechanism::stepImpl stores the client-supplied name in _principalName (sasl_x509_server_conversation.cpp, around line 190). It does this before getUserName rejects the request (around line 195). getUserName rejects both a missing certificate and a name that does not match the certificate. So under requireTLS with mandatory client certificates, a client holding any certificate from a trusted CA can still trigger the crash by sending a non-matching over-long user. Ask the SECBUG owner to update the CVE text. The jstest below covers this case.

      Cluster membership is evaluated on an unverified string. On the failure path, AuthenticationSession::_finish calls _mech->isClusterMember(). SaslX509ServerMechanism::isClusterMember passes getPrincipalName() to SSLConfiguration::isClusterMember(std::string_view, ...), which re-parses it with parseDN. On success that name equals the verified certificate subject. On failure it is whatever the client sent, so attacker input reaches parseDN before authentication. That is the root of this SECBUG's reachability, and of any future parseDN bug.

      Scope of Work

      • Fix x509ShortNameToOid (required). File: src/mongo/util/net/ssl_manager.cpp, OpenSSL branch.
        • Store the OBJ_obj2txt result in an int. If it is negative, return boost::none. parseDN already turns boost::none into BadValue ("DN contained an unknown OID"), which is the outcome the contract requires.
        • When the result is 80 or more, allocate result + 1 bytes and call OBJ_obj2txt again. Check that the second call returns the same length; if not, return boost::none. Build the std::string from exactly that length.
        • Never convert an OpenSSL int length to size_t before checking its sign.
        • The Apple/Windows branch uses a static table and is not affected. Leave it unchanged.
      • Stop parsing unverified principal names for cluster membership (required, defense in depth) in src/mongo/db/auth/sasl_x509_server_conversation.cpp, SaslX509ServerMechanism::isClusterMember.
        • Decide membership from the verified peer certificate: use SSLPeerInfo's subjectName() (an already-parsed SSLX509Name) together with getClusterMembership(), and call the SSLX509Name overload of SSLConfiguration::isClusterMember instead of the string overload.
        • Return false when there is no peer certificate, or when the certificate subject is empty.
        • Behavior on success is unchanged, because getUserName guarantees the principal name equals the certificate subject. On failure, a cert-less or mismatched client can no longer have cluster membership evaluated on a string it supplied. That also stops _finish from incrementing the cluster-authentication counters (incClusterAuthenticateReceived) for those failed attempts.
        • Check the other caller of SSLConfiguration::isClusterMember(std::string_view, ...) to confirm it only receives server-side configuration or verified data.
      • Keep exceptions from escaping the failure path (required). AuthenticationSession::_finish runs on failure, abandon and onDestroyClient->markFailed paths, where any exception that escapes is fatal. After the first two items, no non-DBException can come out of isClusterMember. Add a comment or invariant at the call site in _finish stating that isClusterMember must not throw. Do not add a broad catch (const std::exception&) in parseDN; that would hide future bugs of this kind.

      Tests 

      Red/green: write them first and confirm they fail on master

      Implement the contract's three tests as specified in SECBUG-6434 (unit-parsedn-overlong-oid-rejected, unit-long-valid-oid-roundtrip, jstest-preauth-x509-long-oid-survives), with these changes:

      • unit-long-valid-oid-roundtrip is a regression test, not an invariant, because it fails on master (finding 1). Also cover the boundary: OIDs of 79, 80 and 81 characters, plus one of about 100 characters, each round-trip exactly.
      • Add a fourth step to the jstest: under requireTLS with mandatory client certificates, a client presenting a valid certificate from jstests/libs sends the over-long user on $external. The step must fail with AuthenticationFailed and the server must survive (finding 2).
      • Add a test for item 2. A cert-less MONGODB-X509 attempt with a user DN whose O/OU match the server's subject must not be counted as a cluster member: check the cluster authentication counters in serverStatus. A valid cluster-member certificate must still authenticate as __system.

      Acceptance Criteria

      • No client-supplied DN string can make parseDN or x509ShortNameToOid throw a non-DBException error. An OID that OBJ_obj2txt cannot render gives BadValue.
      • Every numeric OID that OpenSSL can render converts to exactly its input text, at any length (including just above the 80-byte initial buffer).
      • SaslX509ServerMechanism::isClusterMember uses only the verified peer certificate, never the client-supplied principal name.
      • mongod survives every step of the jstest, including the valid-certificate and mismatched-user step. Its log has no "terminate() called" entry, and the fixture shuts down with exit code 0.
      • Existing parseDN, BadDNParsing, filtering and cluster-member unit tests pass unchanged, as do jstests/ssl/speculative-authenticate.js and the X.509 jstests in jstests/ssl.

            Assignee:
            Unassigned
            Reporter:
            Chye Lin Chee
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: