Repository navigation
Fix ssl_certificate authentication bypass via embedded NUL byte in certificate CN - #117403
Conversation
X509Certificate::subjectName and issuerName read the name entry with X509_NAME_get_text_by_NID, which copies the value into a fixed buffer and NUL-terminates it. Constructing a std::string from that buffer stops at the first embedded NUL byte, so a certificate with a common name such as "john\0.evil.com" was seen as "john" during ssl_certificate authentication and could impersonate the user john. Read the ASN1_STRING bytes directly (X509_NAME_get_index_by_NID plus X509_NAME_ENTRY_get_data) and build the string from its exact length. The full value is preserved, so it compares unequal to any NUL-free configured subject, and long names are no longer silently truncated. This mirrors how the SAN entries are already extracted in extractAllSubjects. Add integration tests over both the native and HTTPS interfaces using a CA-signed certificate whose CN carries an embedded NUL byte. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Workflow [PR], commit [5dafb6f] Summary: ✅
AI ReviewSummaryThe PR fixes the Final Verdict
LLVM Coverage ReportMeasured on commit 5dafb6f.
Changed lines: Changed C/C++ lines covered: 17/24 (70.83%) · Uncovered code |
This comment was marked as low quality.
This comment was marked as low quality.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 7 s compile time in total, 8 of them have a recent master baseline. |
…lity The previous tests used a certificate with CN "john\0.evil.com" presented as user 'john', but 'john' is configured with <common_name>client1</common_name>. Neither a truncating (vulnerable) nor a fixed server extracts "client1" from that certificate, so both reject and the tests passed on either binary without exercising the truncation-to-match path. Give client13 the CN "client1\0.evil.com" instead. A server that truncates at the embedded NUL extracts "client1", which matches john's configured common name and wrongly authenticates the certificate; the fixed server preserves the full CN and correctly rejects. The tests now fail on the vulnerable binary. Reported by @zlareb1 in review of the pull request. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@thevar1able Let's merge? |
…ching Now that CN extraction preserves exact bytes (and `DNS:` SAN extraction already did), a subject like `evil\0.corp.example.com` reached `checkSSLCertificateAuthentication` intact, and a wildcard `*.corp.example.com` accepted `evil\0` as a single label. No valid hostname or URI contains a NUL byte, so skip such subjects in the wildcard branch. Add a regression test with a CA-signed certificate carrying the NUL byte in both the CN and the `DNS:` SAN. Address review: #117403 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dear @evillique, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Backport #117403 to 26.9: Fix ssl_certificate authentication bypass via embedded NUL byte in certificate CN
Backport #117403 to 26.8: Fix ssl_certificate authentication bypass via embedded NUL byte in certificate CN
Backport #117403 to 26.7: Fix ssl_certificate authentication bypass via embedded NUL byte in certificate CN
…n bypass via embedded NUL byte in certificate CN
…n bypass via embedded NUL byte in certificate CN
…n bypass via embedded NUL byte in certificate CN
Backport #117403 to 26.3: Fix ssl_certificate authentication bypass via embedded NUL byte in certificate CN
…n bypass via embedded NUL byte in certificate CN
Fixes an authentication bypass in
ssl_certificateuser identification.X509Certificate::subjectNameandissuerNameextracted the name entry withX509_NAME_get_text_by_NID, which copies the value into a fixed buffer and NUL-terminates it. Building astd::stringfrom that C buffer stops at the first embedded NUL byte, so a certificate whose Common Name isjohn\0.evil.comwas seen by the server asjohn. A holder of a CA-signed certificate for*.evil.comcould therefore embed a NUL byte in the CN and authenticate as thessl_certificateuserjohn.The value is now read directly from the
ASN1_STRING(X509_NAME_get_index_by_NID+X509_NAME_ENTRY_get_data+ASN1_STRING_length) and built from its exact byte length, so the full CN is preserved and compares unequal to any NUL-free configured subject. This also removes a pre-existing silent truncation of names longer than the 256-byte buffer. The approach matches how SAN entries are already extracted inextractAllSubjects, so both the native and HTTPS authentication paths are covered.Added integration tests over both the native and HTTPS interfaces using a CA-signed certificate (
client13) whose CN carries an embedded NUL byte; the certificate generation is added togenerate_certs.sh. This is the sibling of the wildcard matching fix in #108472.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed an
ssl_certificateauthentication bypass where an embedded NUL byte in a certificate's Common Name (for examplejohn\0.evil.com) was truncated server-side tojohn, letting a holder of such a certificate authenticate as a different user.Workflow [PR]
Sync PR [sync-upstream/pr/117403]
Version info
26.10.1.1231-master(included in26.10and later)26.9.9.14,26.8.16.20,26.7.20.11,26.3.39.7