Skip to content
Crypto Disclosed report Advanced CVE-2023-28321

CVE-2023-28321: IDN wildcard match

curl's hostname check for TLS certificates compared the wildcard pattern against the IDN prefix instead of the hostname, so a wildcard certificate could match an internationalised domain name it should not. An attacker with a certificate containing a wildcard could therefore have a connection accepted for an IDN host that the certificate does not legitimately cover.

kurohiro Follow

Originally disclosed on HackerOne

  • Triaged in 7 days
  • Fixed in 30 days
  • Disclosed after 31 days

Summary:

curl /libcurl uses wildcards for validation during TLS communication, even if the hostname is an IDN. Even if wildcards are present in the CN/SAN of the certificate, they must not be used to match if the hostname is an IDN. This is described in [RFC-6125, section 6.4.3.][RFC] [RFC]: https://datatracker.ietf.org/doc/html/rfc6125#section-6.4.3 You probably know that. However, there was a problem with the implementation. lib/vtls/hostcheck.c in the function 'hostmatch' on lines 100-106.

  /* We require at least 2 dots in the pattern to avoid too wide wildcard
     match. */
  pattern_label_end = memchr(pattern, '.', patternlen);
  if(!pattern_label_end ||
     (memrchr(pattern, '.', patternlen) == pattern_label_end) ||
     strncasecompare(pattern, "xn--", 4))
    return pmatch(hostname, hostlen, pattern, patternlen);

I think strncasecompare(pattern, "xn--", 4)) is strncasecompare(hostname, "xn--", 4)). pattern is a value that contains wildcards because it is CN/SAN. In other words, it will not match "xn--" because it will be a string containing wildcards.

Steps To Reproduce:

  1. Create a wildcard certificate.As an example, attach a certificate and private key with CN value of x*.example.local. (Attachment on the original report: server.crt) (Attachment on the original report: server.key)
  2. openssl s_server -accept 443 -cert server.crt -key server.key -www
  3. Modify hosts so that the name resolution result of `xn--l8j.example.local‘ is the IP of your machine in order to perform the test in the local environment.
  4. curl https://%E3%81%82.example.local --cacert server.crt

When the above is executed, the communication succeeds even though it should result in a validation error.

Impact

Improper Validation of Certificate with Host Mismatch.

The original report as published on HackerOne, by kurohiro. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the IDN prefix check in the wildcard matching function tested the certificate pattern rather than the hostname, so the guard against wildcards matching IDN names never triggered.

Impact

A wildcard certificate could be accepted for an IDN hostname it should not cover, bypassing certificate validation.

What the attacker needed

Attacker holds a wildcard certificate; victim connects to an IDN hostname

The fix

The hostname check should test the hostname, not the certificate pattern, for the IDN prefix so wildcards are never used to match IDN names.

How it was found

  1. Create a wildcard certificate whose common name is a wildcard over a local domain.
  2. Start a test TLS server with that certificate and key.
  3. Point the encoded IDN hostname at the local machine in the hosts file.
  4. Run curl against the encoded IDN hostname trusting only that certificate.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When your browser or curl connects to a secure site, it checks that the site's certificate really belongs to the name you asked for. Names with non-English characters are written in a special encoded form starting with 'xn--'. The check here looked at the wrong string, so a certificate meant for a wildcard name was wrongly accepted for such a name.

What is Crypto?

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.

More by kurohiro

View all

9 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.