OpenSSL 4.1 and curl: Name Constraints Bypass Explained

The CyberSec Guru

OpenSSL 4.1 and curl

If you like this post, then please share it:

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Why your support matters: Zero paywalls: Keep the main content 100% free for learners worldwide.

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

curl’s code for verifying TLS server certificates did not change this autumn. The library underneath it did, and curl started accepting a certificate it had rejected for as long as anyone can remember. Daniel Stenberg, curl’s creator, described the situation on Mastodon on November 20, and he was angry: “OpenSSL subtly changed an API function behavior so that curl now accepts a certificate that it shouldn’t, using code that has worked with OpenSSL for decades. OpenSSL’s response? It’s your fault.” A few lines later he added, “I’m so furious I better not write anything more on this topic tonight.”

Bob Beck, who came to OpenSSL from OpenBSD and now works for the project, argued the other side in OpenSSL issue 33890. He says the new behavior is intended, documented in CHANGES.md, and consistent with the relevant RFCs, and that an application that does its own hostname matching owns the consequences of that choice. “This is not a security issue,” he wrote. “The answer is correct.”

Both positions hold up, which is why this is more than a maintainer spat. OpenSSL 4.1 did move closer to the letter of RFC 5280 and RFC 9525. curl did end up trusting a certificate whose Common Name sits outside the namespace its issuing CA was allowed to certify. The failure is in the seam between two components that each behave reasonably on their own. To see it, you need to know what curl asks OpenSSL to verify, what RFC 5280 says about name constraints and the subject Distinguished Name, and why a heuristic OpenSSL carried for years was quietly holding up a lot of application code.

How to reproduce the curl certificate bypass with OpenSSL 4.1

The concrete test came from Mounir Idrassi, an OpenSSL member who was investigating an earlier report, OpenSSL issue 33420, filed on October 27. That report was narrower. A developer noticed that X509_check_host(cert, expected_hostname, 0, 0, NULL) had started returning 0 for certificates that carry their hostname only in the subject Common Name, with no subjectAltName extension. Every previous release returned 1. The command-line equivalent, openssl verify -CAfile ca.crt -verify_hostname srv.test.tld, went from OK to error 62 at 0 depth lookup: hostname mismatch. Idrassi reproduced it and traced it to the deliberate change in OpenSSL pull request 31982. Then he spotted a more dangerous implication for applications that match names themselves. Beck copied that finding into the dedicated tracking issue, 33890, on November 20.

Idrassi built curl 8.23.0 (commit 3163ec065643, from the curl-8_23_0 tag) against OpenSSL 4.0.2 and then against 4.1.0. Only a root certificate went into the trust store. The server presented a chain beneath it: an intermediate with a critical nameConstraints extension permitting a single DNS subtree, allowed.test, and a leaf whose subject Common Name was victim.test with no subjectAltName extension at all. He requested https://victim.test over loopback, using curl’s --resolve option to pin the name to the local address, with peer-certificate and hostname verification both enabled.

Against OpenSSL 4.0.2, curl exited with error 60, CURLE_PEER_FAILED_VERIFICATION, and the underlying OpenSSL error was 47, X509_V_ERR_PERMITTED_VIOLATION, a permitted-subtree violation. Against 4.1.0, curl exited 0 and received the HTTP response. Reverting the x509_vfy.c portion of commit e7f3a42 restored the rejection without bringing back CN matching by default, which pins the cause down precisely.

Idrassi was careful about the precondition. The leaf still has to chain up to a trusted CA that imposed the constraint, so an arbitrary self-signed or untrusted certificate does not get through. The realistic threat is a constrained subordinate CA, the kind used for technically constrained intermediates in enterprise and public PKIs, issuing a certificate for a name outside its permitted namespace. If a client trusts the root and the intermediate is limited to allowed.test, a leaf for victim.test should be rejected whatever its Common Name says. Under 4.1.0, curl accepted it.

How curl verifies certificates: X509_verify_cert versus its own hostname matcher

curl’s OpenSSL backend splits certificate verification into two stages that are easy to confuse. First it calls X509_verify_cert() to validate the chain: signatures, validity periods, basic constraints, key usage, and name constraints. It passes no reference identifier to that call. In Beck’s words, “Curl is calling the openssl verifier with no reference name at all,” and the X509_verify_cert(3) documentation says that when no hostname is set on the X509_VERIFY_PARAM, no name checks are performed. The library answers one question, whether the path is cryptographically and structurally valid, and nothing more.

Then curl takes the leaf and runs its own matcher over it. It compares the requested hostname against the SAN dNSName entries and, when the certificate has no DNS SAN, falls back to the subject Common Name. Stenberg confirmed in the curl discussion that curl never calls X509_check_host(). The matching is entirely curl’s own code.

OpenSSL has long offered an integrated alternative. An application can call X509_VERIFY_PARAM_set1_host() to install the expected hostname, tune behavior with X509_VERIFY_PARAM_set_hostflags(), and let X509_verify_cert() do path validation and hostname matching together. In that mode the library knows which name the application intends to use and can apply name constraints accordingly. The X509_check_host() family, added in OpenSSL 1.0.2, is for applications that want to match a name against an already validated certificate, and its man page has long recommended the integrated path instead. In 4.1 that recommendation became a deprecation. OpenSSL pull request 30403, “Deprecate the X509_check family of functions,” landed in the 4.1 cycle, and the current man page says these functions “were deprecated in OpenSSL 4.1.0.” Beck pointed this out to David Benjamin during the discussion. Benjamin, who maintains BoringSSL’s certificate code, replied that he had not known.

📬 Stay Ahead of Cyber Threats

Get the latest cybersecurity news, critical vulnerabilities, threat intelligence, tutorials, and exclusive giveaways delivered straight to your inbox. No spam. Unsubscribe anytime.

curl’s split is not a coding mistake. The design predates the integrated verifier, and many TLS clients share it. It works as long as the application’s matcher and the library’s constraint enforcement agree on which certificate fields can serve as a DNS identity. For years they agreed, because OpenSSL applied DNS name constraints to the leaf’s Common Name whenever the leaf had no DNS SAN, and curl’s fallback uses the CN in exactly that situation. The two behaviors meshed, and OpenSSL 4.1 removed its half.

Why RFC 5280 says the certificate path is valid

Beck can call the 4.1 answer correct because RFC 5280 defines name constraints differently from how TLS practitioners tend to assume. Section 4.2.1.10 defines permitted and excluded subtrees over GeneralName types: dNSName, rfc822Name, uniformResourceIdentifier, iPAddress, directoryName, and others. A constraint of one type applies only to names of that same type. A dNSName constraint governs dNSName entries in the subjectAltName extension. The certificate’s subject field is a Distinguished Name, and it is checked against directoryName subtrees, never dNSName subtrees. The Common Name attribute inside that DN is a free-form directory string that, by long convention, often contains something that looks like a hostname. The specification draws a clean line between the two, and convention does not move it.

The same section covers a certificate with no SAN: “If no name of the type is in the certificate, the certificate is acceptable.” Idrassi’s test leaf has no dNSName SAN, so the intermediate’s permitted DNS subtree of allowed.test has nothing to constrain. The subject DN would be checked against directoryName subtrees, but the intermediate declares none. Path validation succeeds, and CN=victim.test is never compared with DNS:allowed.test anywhere in the RFC 5280 algorithm. Beck’s summary in the issue follows this exactly, citing the path-processing rules and the 4.2.1.10 sentence. OpenSSL’s own NAME_CONSTRAINTS_check() documentation says the same: the function matches the subject DN as directoryName, matches SAN entries by their declared type, and does not match the Common Name against dNSName constraints. That job belongs to a separate function, NAME_CONSTRAINTS_check_CN(), which the man page describes as a legacy concern for older certificates that express a DNS identity through the CN.

So when curl hands OpenSSL a chain with no reference identifier and asks whether the path is valid, “yes” is the correct answer under 4.1. The hostname question was never put to the library. curl then asks its own matcher, which finds victim.test in the CN and accepts. Neither component has malfunctioned on its own terms. The acceptance comes from the combination, and the pre-4.1 library only blocked it because it did something the RFC does not require: treating a CN as a DNS name for constraint purposes when no DNS SAN was present.

What OpenSSL 4.1 changed in x509_vfy.c

The change is visible in commit e7f3a42, which touched crypto/x509/x509_vfy.c, the hostflags man page, CHANGES.md, and the verification test suite. Inside check_name_constraints(), the old code applied NAME_CONSTRAINTS_check_CN() to the leaf when the NEVER_CHECK_SUBJECT flag was clear and either ALWAYS_CHECK_SUBJECT was set or the leaf had no DNS SAN:

if (rv == X509_V_OK && i == 0
&& (ctx->param->hostflags & X509_CHECK_FLAG_NEVER_CHECK_SUBJECT) == 0
&& ((ctx->param->hostflags & X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT) != 0
|| (ret = has_san_id(x, GEN_DNS)) == 0))
rv = NAME_CONSTRAINTS_check_CN(x, nc);

The new code drops the has_san_id() branch entirely, so the CN is constraint-checked only when the application opts in with ALWAYS_CHECK_SUBJECT. The helper that detected whether a DNS SAN existed was deleted. The CHANGES.md entry, credited to Beck, reads: “X509 certificate verification no longer consults the subject distinguished name by default. Previously, when a certificate contained no subject alternative name of the type being checked, the subject commonName (for host name checks) or emailAddress (for email checks) was matched instead. The subject dn is now checked only when the X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT flag is set. Correspondingly, during chain verification DNS name constraints are applied to the subject commonName of the leaf certificate only when that flag is set, rather than whenever the leaf had no DNS subject alternative name.”

The same commit updated the test suite. Certificates named badcn1, badalt6, and badalt7, previously expected to fail constraint checks, were flipped to expected-pass with descriptions like “Name Constraints DNS-like CN not checked by default.” The change was deliberate and tested.

A companion change, OpenSSL pull request 31982, merged on August 26, 2026, had already stopped do_x509_check() from falling back to the CN in the name matcher itself. Together the two changes mean that in 4.1, neither integrated hostname matching nor chain-level constraint enforcement touches the Common Name unless the caller sets the flag.

OpenSSL 4.1.0 shipped on October 23, 2026. This bears on Stenberg’s complaint about surprise: the release announcement’s list of “potentially significant or incompatible changes” mentions build targets, assembly optimizations, the tsget utility, and dropped platforms, but not this change. It is in CHANGES.md and the man pages, and absent from the announcement’s highlights.

The flag that restores the old constraint behavior is an imperfect replacement, and Idrassi spelled out why. Setting ALWAYS_CHECK_SUBJECT during chain verification does make OpenSSL check the CN against DNS constraints, and it rejects the victim.test example. In OpenSSL’s integrated matcher, though, the same flag also lets a matching CN override a DNS SAN mismatch, because it forces CN consultation even when SANs are present. An application with its own matcher keeps its own SAN precedence, but the flag can reject an otherwise acceptable certificate whose unused, human-readable CN fails the extra constraint check. Adding the flag to a later X509_check_host() call does nothing for constraints, because that function runs outside the path-validation context where constraints are enforced. The fix has to happen at verification time, on the X509_VERIFY_PARAM, and it changes the set of possible failures instead of restoring the old behavior symmetrically.

Why the Common Name has been deprecated since RFC 2818

None of this is a sudden policy shift. The Common Name has been on its way out of TLS identity for a quarter century. RFC 2818, “HTTP Over TLS,” published in May 2000, already said in section 3.1 that a subjectAltName of type dNSName, if present, MUST be used as the identity. It called the Common Name fallback existing practice but said “it is deprecated and Certification Authorities are encouraged to use the dNSName instead.” RFC 6125 in 2011 tightened this, forbidding CN matching when supported SAN identifiers are present. RFC 9525, “Service Identity in TLS,” published in 2023 and obsoleting 6125, removed the fallback altogether. Section 2 gives the reason: “The Common Name RDN MUST NOT be used to identify a service because it is not strongly typed (it is essentially free-form text) and therefore suffers from ambiguities in interpretation.” Section 1.3 says to avoid including or checking strings that look like domain names in the subject’s Common Name.

Browsers got there first. Chrome 58, in 2017, removed commonName matching for publicly trusted certificates, and publicly trusted CAs have had to include SANs since the CA/Browser Forum Baseline Requirements took effect in 2012. A CN-only certificate for a public website has been non-conformant and rejected by browsers for years. David Benjamin, who wrote the original curl patch to remove the fallback, summed up the trajectory in his pull request: deprecated since RFC 2818, downgraded in RFC 6125, removed in RFC 9525.

From OpenSSL’s side, the pre-4.1 habit of treating a CN as a DNS name for constraint purposes was a compatibility accommodation the standards never required, and removing it is conformance. The accommodation was also a safety net, though, and a great deal of application code had come to depend on it without knowing it was there.

Why name constraints have no clean fix: the CN heuristic problem

Benjamin’s contribution to the issue is the most technically candid part of the thread, because he explains why a library has no clean option. OpenSSL cannot check every CN against DNS name constraints unconditionally, because it cannot tell a human-readable CN from one meant as a DNS name. “There’s no escape from having some kind of ad-hoc ‘might be used as a DNS name’ heuristics,” he wrote. If the library’s heuristic is tighter than the application’s, a CN the application happily uses escapes constraint checking and you have a bypass. If it is looser, the library rejects certificates whose human-readable CNs were never meant as DNS names, and legitimate deployments break.

That tension is real. When OpenSSL introduced CN constraint checking in the 1.1.0 era, it drew OpenSSL issue 5521 in 2018, titled “DNS Nameconstrains rejecting all certificates with a CN name,” where the reporter warned that updating OpenSSL would invalidate hundreds of certificates. The heuristic that protected curl in 2026 is the one that broke other people’s certificates in 2018.

BoringSSL chose differently, as Benjamin described. Instead of keying on hostflags, it applies CN constraints based on the absence of SANs, which makes the “looks like a DNS name” test much less likely to misfire on certificates with proper SANs. That choice assumes the application never consults the CN when a SAN extension exists, and Benjamin admits he cannot guarantee every application honors it. He also noted that nginx calls X509_check_host() from outside X509_verify_cert(), linking to the relevant line in ngx_event_openssl.c, which is a concrete argument against inferring application intent from hostflags alone. The one legitimate reason he acknowledged for separating name checking from chain checking is HTTP/2 connection coalescing across names, though doing that implicitly assumes no name-specific trust anchors are configured.

Beck does not defend name constraints as a mechanism. “I know name constraints suck and have properties that do not match what you expect,” he wrote. “I don’t like it either.” He linked to the BUGS section of OpenSSL’s NAME_CONSTRAINTS_check() documentation, which warns that RFC 5280’s fallback matching treats a * in a dNSName as a literal label component rather than a wildcard, since RFC 9525’s wildcard semantics are defined only for TLS presented-identifier matching and not for constraint matching. In practice, excluded-name constraints should not be relied on to constrain signing certificates in a security-dependent way, unless the consumers are known to use implementations with different semantics or issuance is otherwise constrained to never produce wildcards. Beck suggests the IETF’s LAMPS working group as the place to fix the underlying model, though he says his own efforts to get these problems addressed there have found no appetite. In his framing, the curl dispute is a symptom of a standards problem and not a library bug.

How curl, Node.js and POCO are responding to the OpenSSL 4.1 change

The projects that have responded took two strategies: stop using the CN, or keep using it and force the constraint check at verification time.

curl chose the first. Benjamin wrote the removal patch on September 5, 2026, as curl pull request 22845, weeks before the public argument. It stalled because, as Stenberg explained on November 16, the project had been “under siege” with vulnerability reports and had not managed to merge it. After the OpenSSL issue went public, Stenberg rebased it as pull request 23986 on November 20 and wrote that “since OpenSSL is going to stab us and our users in the back, we probably need to consider to fast track and merge this PR already for the next release to avoid possible security problems.” As of November 21 the pull request is open, labeled feature-window, with a plan to merge when the feature window reopens. The change removes the CN fallback from the OpenSSL backend only. Its regression test skips mbedTLS, GnuTLS, and wolfSSL builds, which still fall back to the CN, so curl’s behavior after the merge will differ by TLS backend.

Node.js took the second route, early. Filip Skokan opened Node.js pull request 65957 on September 10, 2026, after reading the OpenSSL 4.1 alpha release notes. It merged on September 19 and landed in Node.js 26.11.0 in October. Its commit message explains the mechanism: OpenSSL no longer applies DNS name constraints to the subject CN by default, but tls.checkServerIdentity() still uses the CN when no DNS SAN exists, so the fix enables subject checking during chain verification only when no DNS SAN is present. That keeps the existing hostname verification policy intact. The conditional matters. When a DNS SAN exists, Node’s matcher uses it and never reads the CN, so forcing a CN constraint check would risk rejecting valid certificates for no benefit. Reviewer Tim Perry approved it as the right short-term fix while arguing that Node should eventually deprecate CN matching entirely. Idrassi pointed to Node’s approach in the curl discussion as the model for applications that want to keep the fallback safely.

The POCO C++ libraries show the transition for a project that had leaned on the deprecated API. POCO issue 5646, opened November 5 by Matej Kenda, reported that NetSSL failed eight tests against OpenSSL 4.1.0. Its test certificate carried CN=www.appinf.com with no SAN, and X509Certificate::verify() relied on the CN fallback of X509_check_host(), which has now both changed behavior and been deprecated out of no-deprecated builds. The fix, merged November 11 for the 2.0 release and labeled a breaking change, drops CN consideration entirely. It moves hostname checking to X509_VERIFY_PARAM_set1_host() and X509_verify_cert(), as OpenSSL’s own applications have done since 4.1, and reissues the test certificate with a DNS SAN.

Three projects took three positions on the same fault line, all because of one library change.

How to fix OpenSSL 4.1 hostname verification in your own code

Conformance in a library does not guarantee security in an application, and the gap between the two is part of the attack surface. OpenSSL 4.1 answers the question it was asked correctly. curl’s matcher implements its own rules correctly. The acceptance of victim.test comes from the composition, which neither component’s specification describes, and it sat latent for years behind a heuristic that happened to cover it. When the heuristic was removed in the name of conformance, the gap became an observable bypass.

Beck is right that an application that skips the library’s name checks takes responsibility for its own. Stenberg is right that a library change that silently weakens the validation done by decades-old application code is a security-relevant event whatever the RFCs say, and that putting it in CHANGES.md is not the same as telling people. His November 16 comment in the original issue left no room for hedging: “This is a regression and a security flaw introduced in 4.1 that weakens certificate checks by applications using OpenSSL. You can’t fix this with documentation.”

For developers maintaining OpenSSL-dependent code, the practical steps are these:

  • If you perform hostname verification yourself, check whether your matcher can reach the Common Name.
  • If it can, set X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT on the X509_VERIFY_PARAM before calling X509_verify_cert(), with X509_CHECK_FLAG_NEVER_CHECK_SUBJECT clear. Ideally set it only when the leaf has no DNS SAN, so you do not reject certificates whose unused CNs fail constraints.
  • Setting the flag on a later X509_check_host() call will not help.
  • Better still, move to integrated verification with X509_VERIFY_PARAM_set1_host() and let the library do both jobs. That is the direction OpenSSL is pushing with the deprecation of the X509_check family.
  • Test the edge cases the standards leave ambiguous: a constrained intermediate, a CN-only leaf, and a leaf with a valid SAN and a misleading CN.

The curl regression can be reproduced with a few lines of certificate generation, and it went unnoticed through an alpha and a final release until someone built the chain and asked for victim.test.

The long-term fix is the one the standards have pointed to since 2000: stop treating the Common Name as a service identity. curl is doing that, Node.js is considering it, POCO has done it, and browsers did it years ago. Until the long tail of OpenSSL-dependent software follows, any application that still reads the CN is assuming something about what the library underneath will check, and OpenSSL 4.1 has shown that a commit can break that assumption while being correct by its own standards. Reading the changelog will not tell you whether your code is affected. Build the constrained chain, present the CN-only leaf, and see whether your client rejects it.

Buy me A Coffee!

Support The CyberSec Guru’s Mission

🔐 Fuel the cybersecurity crusade by buying me a coffee! Your contribution powers free tutorials, hands-on labs, and security resources.

Why your support matters:
  • Writeup Access: Get complete writeup access within 12 hours
  • Zero paywalls: Keep the main content 100% free for learners worldwide

Perks for one-time supporters:
☕️ $5: Shoutout in Buy Me a Coffee
🛡️ $8: Fast-track Access to Live Webinars
💻 $10: Vote on future tutorial topics + exclusive AMA access

“Your coffee keeps the servers running and the knowledge flowing in our fight against cybercrime.”☕ Support My Work

Buy Me a Coffee Button

If you like this post, then please share it:

News

Discover more from The CyberSec Guru

Subscribe to get the latest posts sent to your email!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.