Skip to content
Crypto Disclosed report Intermediate CVE-2016-3739CVE-2013-4545CVE-2013-6422CVE-2014-0139CVE-2014-1263CVE-2014-2522CVE-2014-8151CVE-2024-2466

CVE-2024-2466: TLS certificate check bypass with mbedTLS

When curl built with mbedTLS connects to a host by IP address, the server certificate name check is skipped, so a certificate for any other site is accepted. An attacker with a valid certificate for a different host could impersonate the intended server and intercept or spoof data.

frankyueh Follow

Originally disclosed on HackerOne

Medium 5.3 View original
  • Triaged in 2 hours
  • Fixed in 13 days
  • Disclosed after 13 days

Summary:

Curl library has a security vulnerability where the certificate name check is bypassed when connecting to a host via its IP address. This could potentially introduce spoofing attacks or unauthorized access due to unverified server certificate.

This issue only affects the Curl with MbedTLS.

  • Affected versions: from libcurl 8.5.0 to and including 8.6.0 (current master versions at the time of writing)
  • Not affected versions: libcurl 8.4.0 and earlier

This issue affect all kinds of protocol over TLS session, e.g. HTTPS, FTPS, SMTPS, etc.

Steps To Reproduce:

(Preparation) Download and build the Curl with MbedTLS:

Skip this step if you already have the Curl (>= 8.5.0) with MbedTLS.

Before building the code, make sure you have environment to build the code in Linux, sudo apt install build-essential.

  1. Get and extract the code:
Shell
wget https://curl.se/download/curl-8.6.0.tar.gz -O curl-8.6.0.tar.gz
wget https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.7.tar.gz -O mbedtls-2.28.7.tar.gz
tar zxf curl-8.6.0.tar.gz
tar zxf mbedtls-2.28.7.tar.gz
  1. Build MbedTLS:
Shell
cd mbedtls-2.28.7
make SHARED=1 -j$(nproc)
sudo make install DESTDIR=/usr/local/lib
  1. Build Curl with MbedTLS:
Shell
cd curl-8.6.0
export LD_LIBRARY_PATH=/usr/local/lib
export PATH=/usr/local/lib:$PATH
./configure --with-mbedtls=/usr/local --without-libpsl
make -j$(nproc) CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

Reproduce the issue via Curl CLI:

If you build the Curl with MbedTLS from above, you should export the LD_LIBRARY_PATH and PATH to use the built Curl.

Shell
export LD_LIBRARY_PATH=/usr/local/lib
export PATH=/usr/local/lib:$PATH
  1. Check the version of the Curl:
Shell
$ curl --version
curl 8.6.0 (x86_64-pc-linux-gnu) libcurl/8.6.0 mbedTLS/2.28.7 zlib/1.2.11 libidn2/2.2.0
Release-Date: 2024-01-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IDN IPv6 Largefile libz NTLM SSL threadsafe UnixSockets
  1. Get IP from an example https server and use it to connect:
Shell
$ host -t A www.example.org
www.example.org has address 93.184.216.34
$ curl https://93.184.216.34
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
                <title>404 - Not Found</title>
        </head>
        <body>
                <h1>404 - Not Found</h1>
        </body>
</html>

You could see that the Curl is able to connect to the server via its IP address. This not an expected behavior because the server certificate is not verified against the host name.

The expect result should be an error message like this:

Shell
curl: (60) SSL: no alternative certificate subject name matches target host name '93.184.216.34'
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

I just demonstrated the issue with the Curl CLI, but this issue could be exploited in any application that uses the Curl library with MbedTLS and if the connection is made via IP address.

Supporting Material/References:

Cause of the issue:

This issue is caused by the skipping call of the mbedtls_ssl_set_hostname function in mbed_connect_step1. The mbedtls_ssl_set_hostname function is used to set the server name for the SNI extension and also for the server certificate name check. If the mbedtls_ssl_set_hostname function is not called, the server certificate name check will be bypassed.

The vulnerable of code snippet from mbed_connect_step1 (lib/vtls/mbedtls.c) as following:

C
  if(connssl->peer.sni) {
    if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {
      /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
         the name to set in the SNI extension. So even if curl connects to a
         host specified as an IP address, this function must be used. */
      failf(data, "Failed to set SNI");
      return CURLE_SSL_CONNECT_ERROR;
    }
  }

If connssl->peer.sni is not set, the mbedtls_ssl_set_hostname function will not be called and the server certificate name check will be bypassed.

The connssl->peer object contains the peer information, including the sni, hostname, dispname and type.

C
typedef enum {
  CURL_SSL_PEER_DNS,
  CURL_SSL_PEER_IPV4,
  CURL_SSL_PEER_IPV6
} ssl_peer_type;

struct ssl_peer {
  char *hostname;        /* hostname for verification */
  char *dispname;        /* display version of hostname */
  char *sni;             /* SNI version of hostname or NULL if not usable */
  ssl_peer_type type;    /* type of the peer information */
};

Before the handshake of TLS session, the peer information is created from Curl_ssl_peer_init function. The sni is optional and only set if the peer type is CURL_SSL_PEER_DNS. If peer type is CURL_SSL_PEER_IPV4 or CURL_SSL_PEER_IPV6, the sni will be null. The code snippet from Curl_ssl_peer_init function (lib/vtls/vtls.c):

C
    peer->sni = NULL;
    peer->type = get_peer_type(peer->hostname);
    if(peer->type == CURL_SSL_PEER_DNS && peer->hostname[0]) {
      /* not an IP address, normalize according to RCC 6066 ch. 3,
       * max len of SNI is 2^16-1, no trailing dot */
      size_t len = strlen(peer->hostname);
      if(len && (peer->hostname[len-1] == '.'))
        len--;
      if(len < USHRT_MAX) {
        peer->sni = calloc(1, len + 1);
        if(!peer->sni) {
          Curl_ssl_peer_cleanup(peer);
          return CURLE_OUT_OF_MEMORY;
        }
        Curl_strntolower(peer->sni, peer->hostname, len);
        peer->sni[len] = 0;
      }
    }

Therefore, if the Curl connect to a IP address host, the sni will be null and the mbedtls_ssl_set_hostname function will not be called. The server certificate name check will be bypassed and the connection will be established without the server certificate name verification.

Noticeable, this issue is similar to CVE-2016-3739. Basically, this is the bug from 7.21.0 and reintroduced in 8.5.0 to 8.6.0 with slightly different way.

Detailed code change timeline about this issue:

First, the fix for CVE-2016-3739 is this commit. This fix is make sure that the mbedtls_ssl_set_hostname function will be called always, even the host name is not for SNI extension usage, e.g. IP address or SSLv3. Because the mbedtls_ssl_set_hostname function is not called, MbedTLS will not check the server certificate name against the host name and complete the SSL handshake.

This bug is due to the confusion of documentation about the API. Here is the discussion about it: link.

The code fix for CVE-2016-3739:

Diff
-  if(!Curl_inet_pton(AF_INET, conn->host.name, &addr) &&
-#ifdef ENABLE_IPV6
-     !Curl_inet_pton(AF_INET6, conn->host.name, &addr) &&
-#endif
-     sni && mbedtls_ssl_set_hostname(&connssl->ssl, conn->host.name)) {
-    infof(data, "WARNING: failed to configure "
-          "server name indication (SNI) TLS extension\n");
+  if(mbedtls_ssl_set_hostname(&connssl->ssl, conn->host.name)) {
+    /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks *and*
+       the name to set in the SNI extension. So even if curl connects to a
+       host specified as an IP address, this function must be used. */
+    failf(data, "couldn't set hostname in mbedTLS");
+    return CURLE_SSL_CONNECT_ERROR;

A comment was even be added to avoid the confusion usage for the mbedtls_ssl_set_hostname function.

Later on, this commit brings back the "SNI" usage and only call the mbedtls_ssl_set_hostname function when snihost is set. Fortunately, if snihost is not set, an error will be returned instead of continuing the SSL handshake without the server name check.

Apparently, This commit reintroduced the confusion about the mbedtls_ssl_set_hostname function usage back again, and just avoid the issue by unrelated error handling of SNI host name conversion.

Diff
-  if(mbedtls_ssl_set_hostname(&backend->ssl, hostname)) {
-    /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks *and*
-       the name to set in the SNI extension. So even if curl connects to a
-       host specified as an IP address, this function must be used. */
-    failf(data, "couldn't set hostname in mbedTLS");
-    return CURLE_SSL_CONNECT_ERROR;
+  {
+    char *snihost = Curl_ssl_snihost(data, hostname, NULL);
+    if(!snihost || mbedtls_ssl_set_hostname(&backend->ssl, snihost)) {
+      /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
+         the name to set in the SNI extension. So even if curl connects to a
+         host specified as an IP address, this function must be used. */
+      failf(data, "Failed to set SNI");
+      return CURLE_SSL_CONNECT_ERROR;
+    }

Eventually, this commit "keep peer name information together", it separated the sni and hostname in the peer structure, the peer information is created from another place and sni become optional. So the mbedtls_ssl_set_hostname function now is only called if sni is set, if not set it will continue the handshake and bypass host name verification. Therefore, the bug is reintroduced.

Diff
-  {
-    char *snihost = Curl_ssl_snihost(data, hostname, NULL);
-    if(!snihost || mbedtls_ssl_set_hostname(&backend->ssl, snihost)) {
+
+  if(connssl->peer.sni) {
+    if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {
       /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
          the name to set in the SNI extension. So even if curl connects to a
          host specified as an IP address, this function must be used. */

The possible solution is to always call the mbedtls_ssl_set_hostname function, even if sni is not set. If sni is null, it could use peer.hostname to pass to the mbedtls_ssl_set_hostname function.

Furthermore, we must have to avoid this kind of "for SNI only" confusion in the future again. Apparently, a simple block of comment in the code is not enough to avoid it.

Curl History CVE related to CWE-297:

Just for reference, the following CVEs are related to the weakness of CWE-297:

Impact

The weakness of this issue quote from SWE-297: Improper Validation of Certificate with Host Mismatch:

Even if a certificate is well-formed, signed, and follows the chain of trust, it may simply be a valid certificate for a different site than the site that the product is interacting with. If the certificate's host-specific data is not properly checked - such as the Common Name (CN) in the Subject or the Subject Alternative Name (SAN) extension of an X.509 certificate - it may be possible for a redirection or spoofing attack to allow a malicious host with a valid certificate to provide data, impersonating a trusted host. In order to ensure data integrity, the certificate must be valid and it must pertain to the site that is being accessed.

Apparently, even the certificate is valid, without the server name check the attacker could use a "valid certificate" for a different site to "impersonate" a trusted host.

Common Consequences:

Reference from CWE-297: Improper Validation of Certificate with Host Mismatch:

Scope Impact
Access Control Technical Impact: Gain Privileges or Assume Identity
The data read from the system vouched for by the certificate may not be from the expected system.
Authentication Other Technical Impact: Other
Trust afforded to the system in question - based on the malicious certificate - may allow for spoofing or redirection attacks.

Likelihood Of Exploit: High

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

Context

curl is a command line tool and library (libcurl) for transferring data with URLs. When it connects to a server over TLS, it is expected to verify that the certificate presented by the server actually belongs to the host it asked for. That check is what stops a valid certificate for one site being used to impersonate another.

This report describes a bypass of that check in the mbedTLS backend of libcurl. When curl connects to a host by its IP address rather than by name, the certificate name check is skipped entirely, so the TLS handshake completes even though the certificate does not match the target. The issue affects only curl built with mbedTLS, and it applies to every protocol that runs over a TLS session, for example HTTPS, FTPS and SMTPS.

The affected versions are libcurl 8.5.0 up to and including 8.6.0 (the current master versions at the time of writing). libcurl 8.4.0 and earlier are not affected.

Setup

The researcher built curl 8.6.0 against mbedTLS 2.28.7 on Linux. The build environment needs the usual compiler toolchain:

Shell
sudo apt install build-essential

Step 1: Get and extract the code

Shell
wget https://curl.se/download/curl-8.6.0.tar.gz -O curl-8.6.0.tar.gz
wget https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.7.tar.gz -O mbedtls-2.28.7.tar.gz
tar zxf curl-8.6.0.tar.gz
tar zxf mbedtls-2.28.7.tar.gz

Step 2: Build mbedTLS

Shell
cd mbedtls-2.28.7
make SHARED=1 -j$(nproc)
sudo make install DESTDIR=/usr/local/lib

Step 3: Build curl with mbedTLS

Shell
cd curl-8.6.0
export LD_LIBRARY_PATH=/usr/local/lib
export PATH=/usr/local/lib:$PATH
./configure --with-mbedtls=/usr/local --without-libpsl
make -j$(nproc) CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

After building, the same two environment variables must be exported in any shell where the freshly built curl is used:

Shell
export LD_LIBRARY_PATH=/usr/local/lib
export PATH=/usr/local/lib:$PATH

Finding it

The researcher noticed that curl built with mbedTLS would happily connect to a TLS server when given the server's IP address instead of its hostname. That is not the expected behaviour: the certificate is issued for a name, and connecting by IP should fail the name check, because the certificate contains no matching subject alternative name for the IP address.

Exploitation

Step 1: Confirm the build

Shell
$ curl --version
curl 8.6.0 (x86_64-pc-linux-gnu) libcurl/8.6.0 mbedTLS/2.28.7 zlib/1.2.11 libidn2/2.2.0
Release-Date: 2024-01-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IDN IPv6 Largefile libz NTLM SSL threadsafe UnixSockets

The version line confirms curl 8.6.0 linked against mbedTLS 2.28.7, which is the affected combination.

Step 2: Resolve a host and connect by IP

Shell
$ host -t A www.example.org
www.example.org has address [redacted]
$ curl https://[redacted]
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
                <title>404 - Not Found</title>
        </head>
        <body>
                <h1>404 - Not Found</h1>
        </body>
</html>

The first command resolves the hostname to an address. The second connects to that address directly over HTTPS. The server answers with an HTTP 404 page, which means the TLS handshake succeeded and the request was served. The certificate was never checked against the name the client asked for, because the client asked for an IP address and the check was skipped.

The expected result is an error like this one:

Shell
curl: (60) SSL: no alternative certificate subject name matches target host name '[redacted]'
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

The researcher demonstrated the problem with the curl CLI, but points out that it can be exploited in any application that uses the curl library with mbedTLS whenever the connection is made via an IP address.

Root cause

The bug is a missing call to mbedtls_ssl_set_hostname in mbed_connect_step1. That function does two jobs: it sets the server name used in the SNI extension, and it sets the name used for the server certificate name check. If it is never called, the certificate name check is bypassed.

The vulnerable code in lib/vtls/mbedtls.c is:

C
  if(connssl->peer.sni) {
    if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {
      /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
         the name to set in the SNI extension. So even if curl connects to a
         host specified as an IP address, this function must be used. */
      failf(data, "Failed to set SNI");
      return CURLE_SSL_CONNECT_ERROR;
    }
  }

The call is guarded by connssl->peer.sni. If that field is not set, the function is not called and the name check is skipped.

The connssl->peer object holds the peer information, including sni, hostname, dispname and type:

C
typedef enum {
  CURL_SSL_PEER_DNS,
  CURL_SSL_PEER_IPV4,
  CURL_SSL_PEER_IPV6
} ssl_peer_type;

struct ssl_peer {
  char *hostname;        /* hostname for verification */
  char *dispname;        /* display version of hostname */
  char *sni;             /* SNI version of hostname or NULL if not usable */
  ssl_peer_type type;    /* type of the peer information */
};

Before the TLS handshake, the peer information is built by Curl_ssl_peer_init. The sni field is optional and is only set when the peer type is CURL_SSL_PEER_DNS. For CURL_SSL_PEER_IPV4 or CURL_SSL_PEER_IPV6, sni stays null. The relevant code from lib/vtls/vtls.c:

C
    peer->sni = NULL;
    peer->type = get_peer_type(peer->hostname);
    if(peer->type == CURL_SSL_PEER_DNS && peer->hostname[0]) {
      /* not an IP address, normalize according to RCC 6066 ch. 3,
       * max len of SNI is 2^16-1, no trailing dot */
      size_t len = strlen(peer->hostname);
      if(len && (peer->hostname[len-1] == '.'))
        len--;
      if(len < USHRT_MAX) {
        peer->sni = calloc(1, len + 1);
        if(!peer->sni) {
          Curl_ssl_peer_cleanup(peer);
          return CURLE_OUT_OF_MEMORY;
        }
        Curl_strntolower(peer->sni, peer->hostname, len);
        peer->sni[len] = 0;
      }
    }

So when curl connects to an IP address, sni is null, mbedtls_ssl_set_hostname is not called, the certificate name check is bypassed, and the connection is established without verifying the certificate name.

The researcher notes that this is similar to CVE-2016-3739: essentially the bug from 7.21.0, reintroduced in 8.5.0 to 8.6.0 in a slightly different way.

How the bug came back

The fix for CVE-2016-3739 (commit 6efd2fa529a189bf41736a610f) made sure mbedtls_ssl_set_hostname is always called, even when the host name is not usable for SNI, for example an IP address or SSLv3. Without the call, mbedTLS does not check the certificate name against the host name and completes the handshake anyway. The researcher attributes the original bug to confusion in the API documentation, and links a discussion of it in the mbedTLS issue tracker.

The fix looked like this:

Diff
-  if(!Curl_inet_pton(AF_INET, conn->host.name, &addr) &&
-#ifdef ENABLE_IPV6
-     !Curl_inet_pton(AF_INET6, conn->host.name, &addr) &&
-#endif
-     sni && mbedtls_ssl_set_hostname(&connssl->ssl, conn->host.name)) {
-    infof(data, "WARNING: failed to configure "
-          "server name indication (SNI) TLS extension\n");
+  if(mbedtls_ssl_set_hostname(&connssl->ssl, conn->host.name)) {
+    /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks *and*
+       the name to set in the SNI extension. So even if curl connects to a
+       host specified as an IP address, this function must be used. */
+    failf(data, "couldn't set hostname in mbedTLS");
+    return CURLE_SSL_CONNECT_ERROR;

A comment was added to prevent the same confusion about how the function should be used.

Later, commit [redacted] brought back the "SNI" usage and only called mbedtls_ssl_set_hostname when snihost was set. In that version, if snihost was not set, an error was returned instead of continuing the handshake without the name check, so the issue was avoided, but only through unrelated error handling of the SNI host name conversion:

Diff
-  if(mbedtls_ssl_set_hostname(&backend->ssl, hostname)) {
-    /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks *and*
-       the name to set in the SNI extension. So even if curl connects to a
-       host specified as an IP address, this function must be used. */
-    failf(data, "couldn't set hostname in mbedTLS");
-    return CURLE_SSL_CONNECT_ERROR;
+  {
+    char *snihost = Curl_ssl_snihost(data, hostname, NULL);
+    if(!snihost || mbedtls_ssl_set_hostname(&backend->ssl, snihost)) {
+      /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
+         the name to set in the SNI extension. So even if curl connects to a
+         host specified as an IP address, this function must be used. */
+      failf(data, "Failed to set SNI");
+      return CURLE_SSL_CONNECT_ERROR;
+    }

Finally, commit [redacted] ("keep peer name information together") separated sni and hostname in the peer structure, moved where the peer information is created, and made sni optional. From then on mbedtls_ssl_set_hostname was only called when sni was set; when it was not, the handshake continued and host name verification was bypassed. That reintroduced the bug:

Diff
-  {
-    char *snihost = Curl_ssl_snihost(data, hostname, NULL);
-    if(!snihost || mbedtls_ssl_set_hostname(&backend->ssl, snihost)) {
+
+  if(connssl->peer.sni) {
+    if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {
       /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
          the name to set in the SNI extension. So even if curl connects to a
          host specified as an IP address, this function must be used. */

The researcher's suggested solution is to always call mbedtls_ssl_set_hostname, even when sni is not set, falling back to peer.hostname when sni is null. He also argues that the "for SNI only" confusion has to be prevented in future, since a comment block in the code was evidently not enough.

Related history

For reference, the report lists earlier curl CVEs related to CWE-297:

Impact

The weakness is CWE-297, Improper Validation of Certificate with Host Mismatch. The report quotes the CWE description:

Even if a certificate is well-formed, signed, and follows the chain of trust, it may simply be a valid certificate for a different site than the site that the product is interacting with. If the certificate's host-specific data is not properly checked - such as the Common Name (CN) in the Subject or the Subject Alternative Name (SAN) extension of an X.509 certificate - it may be possible for a redirection or spoofing attack to allow a malicious host with a valid certificate to provide data, impersonating a trusted host. In order to ensure data integrity, the certificate must be valid and it must pertain to the site that is being accessed.

In other words, even a valid certificate can be used by an attacker for a different site to impersonate a trusted host, because the name is never compared.

The common consequences, again from CWE-297:

Scope Impact
Access Control Technical Impact: Gain Privileges or Assume Identity
The data read from the system vouched for by the certificate may not be from the expected system.
Authentication Other Technical Impact: Other
Trust afforded to the system in question - based on the malicious certificate - may allow for spoofing or redirection attacks.

The report rates the likelihood of exploit as high. The report rates the likelihood of exploit as high, and notes the issue affects all kinds of protocol over TLS sessions.

Fix

The report proposes always calling mbedtls_ssl_set_hostname, even when sni is not set, using peer.hostname as the value when sni is null. It also calls for removing the "for SNI only" confusion around the function so the same regression is not introduced again, since a code comment alone did not prevent it.

Variants to test

  1. Connect to a TLS server by IPv4 address with a curl build using mbedTLS and check whether the request succeeds. A positive result is an HTTP response instead of a certificate name mismatch error.
  2. Repeat with an IPv6 literal. The peer type becomes CURL_SSL_PEER_IPV6 and sni is null, which follows the same code path.
  3. Try other TLS-based protocols such as FTPS or SMTPS against an IP address, since the report says all TLS-based protocols are affected.
  4. Test applications that embed libcurl with mbedTLS and connect by IP, not just the CLI, since the report notes the library is exploitable in any such application.
  5. Check builds from 8.5.0 through 8.6.0; 8.4.0 and earlier are not affected, so a failure there is the expected behaviour and not a finding.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 25 min read.

What happened, in plain words

curl is a small program, and a library called libcurl, that fetches things from the internet. You have probably used it without knowing: many apps and scripts use libcurl behind the scenes to download a web page, send an email, or upload a file. When curl talks to a server over a secure connection, it is supposed to check the server's identity document, called a certificate, and confirm that the document really belongs to the site it asked for. That check is the whole point of the padlock in your browser: it stops someone who owns a valid certificate for one site from pretending to be a different site.

This report describes a case where that check is skipped. When curl is built with a particular TLS library called mbedTLS, and it is told to connect to a server by its numeric IP address instead of by its name, the certificate name check never happens. The secure connection is set up anyway, even though the certificate does not match what was asked for. The problem only affects curl built with mbedTLS, and it applies to every protocol that runs over a TLS session, for example HTTPS, FTPS and SMTPS.

The affected versions are libcurl 8.5.0 up to and including 8.6.0 (the current master versions at the time of writing). libcurl 8.4.0 and earlier are not affected.

A quick word on the terms used above, since they come up constantly:

  • TLS is the technology that turns a normal connection into a private, tamper-proof one. Think of it as a sealed, tamper-evident envelope instead of a postcard.
  • A certificate is like a passport for a website. It is issued by an authority others trust, and it states which names the site is allowed to use.
  • mbedTLS is one particular implementation of TLS, a piece of software that does the envelope work. curl can be built to use several different TLS implementations, and this bug lives in the mbedTLS one.
  • An IP address is the numeric address of a machine on the internet, like a street address. A hostname is the friendly name, like www.example.org, that gets translated into an IP address.

Context

curl is a command line tool and library (libcurl) for transferring data with URLs. When it connects to a server over TLS, it is expected to verify that the certificate presented by the server actually belongs to the host it asked for. That check is what stops a valid certificate for one site being used to impersonate another.

This report describes a bypass of that check in the mbedTLS backend of libcurl. When curl connects to a host by its IP address rather than by name, the certificate name check is skipped entirely, so the TLS handshake completes even though the certificate does not match the target. The issue affects only curl built with mbedTLS, and it applies to every protocol that runs over a TLS session, for example HTTPS, FTPS and SMTPS.

A few more terms worth pinning down before we go further:

  • A backend here means the specific TLS implementation curl was compiled against. curl supports several, and the code paths differ per backend.
  • A handshake is the opening conversation between client and server where they agree on encryption and exchange certificates. If the handshake completes, the connection is up.
  • A protocol is an agreed way of talking, for example HTTPS for web pages, FTPS for secure file transfer, SMTPS for secure mail sending.

Setup

The researcher built curl 8.6.0 against mbedTLS 2.28.7 on Linux. The build environment needs the usual compiler toolchain:

Shell
sudo apt install build-essential

This installs the basic tools needed to turn source code into a working program: a compiler, a linker and the standard build utilities. Without them, the next steps would fail immediately. sudo runs the command with administrator rights, because installing software system-wide requires them.

Step 1: Get and extract the code

Shell
wget https://curl.se/download/curl-8.6.0.tar.gz -O curl-8.6.0.tar.gz
wget https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.7.tar.gz -O mbedtls-2.28.7.tar.gz
tar zxf curl-8.6.0.tar.gz
tar zxf mbedtls-2.28.7.tar.gz

Line by line:

  1. wget ... -O curl-8.6.0.tar.gz downloads the curl source code archive and saves it under that filename. -O means "write the output to this file".
  2. The second wget does the same for the mbedTLS source code, version 2.28.7.
  3. tar zxf curl-8.6.0.tar.gz unpacks the curl archive. tar is the standard archiving tool; z means the file is compressed, x means extract, f means read from the named file.
  4. The last line unpacks the mbedTLS archive the same way.

Why this step: to reproduce a bug in a specific version, you need that exact version's source code on your machine. Downloading the released archives guarantees you are testing the same code the researcher tested, not some newer or older copy.

Step 2: Build mbedTLS

Shell
cd mbedtls-2.28.7
make SHARED=1 -j$(nproc)
sudo make install DESTDIR=/usr/local/lib

Line by line:

  1. cd mbedtls-2.28.7 moves into the unpacked mbedTLS directory.
  2. make SHARED=1 -j$(nproc) compiles the library. SHARED=1 asks for a shared library, the kind that other programs load at runtime rather than copy into themselves. -j$(nproc) tells make to run as many compile jobs in parallel as the machine has processor cores, which speeds things up.
  3. sudo make install DESTDIR=/usr/local/lib installs the freshly built library into /usr/local/lib, using administrator rights.

Why this step: curl needs a TLS implementation to link against. Building mbedTLS first gives us a known version in a known place, so the next step can find it.

Step 3: Build curl with mbedTLS

Shell
cd curl-8.6.0
export LD_LIBRARY_PATH=/usr/local/lib
export PATH=/usr/local/lib:$PATH
./configure --with-mbedtls=/usr/local --without-libpsl
make -j$(nproc) CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

Line by line:

  1. cd curl-8.6.0 moves into the unpacked curl directory.
  2. export LD_LIBRARY_PATH=/usr/local/lib tells the system where to look for shared libraries at runtime. This is how the newly built curl will find the newly built mbedTLS instead of some other copy.
  3. export PATH=/usr/local/lib:$PATH puts that directory at the front of the list of places the shell looks for programs, so the freshly built curl is the one that runs.
  4. ./configure --with-mbedtls=/usr/local --without-libpsl inspects the machine and prepares the build. --with-mbedtls=/usr/local says "use the mbedTLS found under /usr/local", and --without-libpsl disables an optional dependency so the build is simpler.
  5. make -j$(nproc) CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" compiles curl. CFLAGS and LDFLAGS point the compiler and linker at the mbedTLS headers and libraries in /usr/local.

Why this step: this is the combination that contains the bug. Building curl against mbedTLS is what puts the vulnerable code path in play.

After building, the same two environment variables must be exported in any shell where the freshly built curl is used:

Shell
export LD_LIBRARY_PATH=/usr/local/lib
export PATH=/usr/local/lib:$PATH

These two lines repeat the earlier exports. They matter because environment variables only last for the current shell session. Open a new terminal and the shell would go back to using whatever curl was already installed, which might be a different version without the bug.

Finding it

The researcher noticed that curl built with mbedTLS would happily connect to a TLS server when given the server's IP address instead of its hostname. That is not the expected behaviour: the certificate is issued for a name, and connecting by IP should fail the name check, because the certificate contains no matching subject alternative name for the IP address.

Two terms here:

  • Subject alternative name (SAN) is a field inside a certificate listing the names the certificate is valid for. If you connect to something not on that list, the check should fail.
  • A bypass means getting past a security check without satisfying it. Here, the check is simply never run.

Exploitation

Step 1: Confirm the build

Shell
$ curl --version
curl 8.6.0 (x86_64-pc-linux-gnu) libcurl/8.6.0 mbedTLS/2.28.7 zlib/1.2.11 libidn2/2.2.0
Release-Date: 2024-01-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IDN IPv6 Largefile libz NTLM SSL threadsafe UnixSockets

Line by line:

  1. $ curl --version runs curl with the flag that prints version information. The $ is just the shell prompt, not something you type.
  2. The first output line names the curl version (8.6.0), the platform it was built for, and the libraries it was linked against, including mbedTLS/2.28.7.
  3. The Release-Date line gives the release date of that curl version.
  4. The Protocols line lists every protocol this build supports.
  5. The Features line lists optional capabilities compiled in.

The version line confirms curl 8.6.0 linked against mbedTLS 2.28.7, which is the affected combination. Why this step: before testing anything, you confirm you are running the build you think you are. If the output showed a different TLS library, any result would be meaningless.

Step 2: Resolve a host and connect by IP

Shell
$ host -t A www.example.org
www.example.org has address [redacted]
$ curl https://[redacted]
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
                <title>404 - Not Found</title>
        </head>
        <body>
                <h1>404 - Not Found</h1>
        </body>
</html>

Line by line:

  1. host -t A www.example.org asks the domain name system for the IPv4 address of www.example.org. -t A means "give me the A record", which is the record type that maps a name to an IPv4 address.
  2. The answer, www.example.org has address [redacted], is the numeric address behind that name.
  3. curl https://[redacted] then asks curl to fetch that address over HTTPS, using the number directly instead of the name.
  4. Everything from <?xml ... to </html> is the server's reply: an ordinary web page saying 404 Not Found.

The first command resolves the hostname to an address. The second connects to that address directly over HTTPS. The server answers with an HTTP 404 page, which means the TLS handshake succeeded and the request was served. The certificate was never checked against the name the client asked for, because the client asked for an IP address and the check was skipped.

A 404 is a normal "page not found" answer from the web server. It is not an error from curl. The important part is that the request reached the server at all: the secure connection was established, and the server's reply came back readable. If the certificate check had run, curl would have stopped before sending anything.

The expected result is an error like this one:

Shell
curl: (60) SSL: no alternative certificate subject name matches target host name '[redacted]'
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

Line by line:

  1. curl: (60) is curl reporting error number 60, which is its code for a certificate problem.
  2. SSL: no alternative certificate subject name matches target host name '[redacted]' says the certificate has no entry for the address that was requested, so the name check failed.
  3. The next line points to curl's documentation page about certificates.
  4. The remaining lines explain in plain words that curl refused to continue because it could not verify the server's identity.

This is what a correct build does: it refuses to set up the secure connection when the certificate does not cover the name you asked for. The vulnerable build instead produced the 404 page above.

The researcher demonstrated the problem with the curl CLI, but points out that it can be exploited in any application that uses the curl library with mbedTLS whenever the connection is made via an IP address.

That last point matters. The command line tool is just one way to reach the library. Any program that embeds libcurl and connects by IP inherits the same behaviour, whether or not a person is typing commands.

Root cause

The bug is a missing call to mbedtls_ssl_set_hostname in mbed_connect_step1. That function does two jobs: it sets the server name used in the SNI extension, and it sets the name used for the server certificate name check. If it is never called, the certificate name check is bypassed.

Two terms to unpack:

  • SNI, Server Name Indication, is a field the client sends at the start of the handshake to say which site it wants. It exists because one server machine can host many sites on one address, and the server needs to know which certificate to present.
  • A function call is simply asking a piece of code to do its job. If the call never happens, the job never gets done.

The vulnerable code in lib/vtls/mbedtls.c is:

C
  if(connssl->peer.sni) {
    if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {
      /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
         the name to set in the SNI extension. So even if curl connects to a
         host specified as an IP address, this function must be used. */
      failf(data, "Failed to set SNI");
      return CURLE_SSL_CONNECT_ERROR;
    }
  }

Line by line:

  1. if(connssl->peer.sni) { opens a block that only runs when the sni field holds a value. In programming, an empty or missing value counts as false, so the block is skipped entirely when sni is empty.
  2. if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) { calls the function that sets the name for both the SNI field and the certificate check, passing the sni value. The call is inside the outer if, so it only happens when sni is set.
  3. The comment between /* and */ is a note to future readers. It says the function sets the name for CN/SAN checks and for SNI, and that it must be used even when curl connects to an IP address.
  4. failf(data, "Failed to set SNI"); reports an error if the call fails.
  5. return CURLE_SSL_CONNECT_ERROR; stops the connection attempt with curl's error code for a TLS connection problem.
  6. The closing braces end the two if blocks.

The call is guarded by connssl->peer.sni. If that field is not set, the function is not called and the name check is skipped. Notice the irony: the comment says the function must always be used, but the code around it only uses it sometimes.

The connssl->peer object holds the peer information, including sni, hostname, dispname and type:

C
typedef enum {
  CURL_SSL_PEER_DNS,
  CURL_SSL_PEER_IPV4,
  CURL_SSL_PEER_IPV6
} ssl_peer_type;

struct ssl_peer {
  char *hostname;        /* hostname for verification */
  char *dispname;        /* display version of hostname */
  char *sni;             /* SNI version of hostname or NULL if not usable */
  ssl_peer_type type;    /* type of the peer information */
};

Line by line:

  1. typedef enum { ... } ssl_peer_type; defines a set of named values that describe what kind of peer we are talking to. Think of it as a label with three possible stickers.
  2. CURL_SSL_PEER_DNS means the peer was given as a name, like www.example.org.
  3. CURL_SSL_PEER_IPV4 means the peer was given as an IPv4 address, like [redacted].
  4. CURL_SSL_PEER_IPV6 means the peer was given as an IPv6 address, the longer newer style of numeric address.
  5. struct ssl_peer { ... }; defines a bundle of related fields kept together, like a small form with four boxes.
  6. char *hostname; holds the name to verify the certificate against.
  7. char *dispname; holds the version of the name meant for display, for example in messages.
  8. char *sni; holds the name to send in SNI, or NULL if it is not usable.
  9. ssl_peer_type type; holds which of the three labels applies.

Before the TLS handshake, the peer information is built by Curl_ssl_peer_init. The sni field is optional and is only set when the peer type is CURL_SSL_PEER_DNS. For CURL_SSL_PEER_IPV4 or CURL_SSL_PEER_IPV6, sni stays null. The relevant code from lib/vtls/vtls.c:

C
    peer->sni = NULL;
    peer->type = get_peer_type(peer->hostname);
    if(peer->type == CURL_SSL_PEER_DNS && peer->hostname[0]) {
      /* not an IP address, normalize according to RCC 6066 ch. 3,
       * max len of SNI is 2^16-1, no trailing dot */
      size_t len = strlen(peer->hostname);
      if(len && (peer->hostname[len-1] == '.'))
        len--;
      if(len < USHRT_MAX) {
        peer->sni = calloc(1, len + 1);
        if(!peer->sni) {
          Curl_ssl_peer_cleanup(peer);
          return CURLE_OUT_OF_MEMORY;
        }
        Curl_strntolower(peer->sni, peer->hostname, len);
        peer->sni[len] = 0;
      }
    }

Line by line:

  1. peer->sni = NULL; starts with the SNI field empty. NULL means "no value".
  2. peer->type = get_peer_type(peer->hostname); works out whether the hostname is a name, an IPv4 address or an IPv6 address, and stores that label.
  3. if(peer->type == CURL_SSL_PEER_DNS && peer->hostname[0]) { only continues when the peer is a name and the name is not empty. This is the gate that excludes IP addresses.
  4. The comment explains the normalisation rules: SNI has a maximum length and should not end with a trailing dot.
  5. size_t len = strlen(peer->hostname); measures the length of the name.
  6. if(len && (peer->hostname[len-1] == '.')) len--; drops a trailing dot from the length if there is one.
  7. if(len < USHRT_MAX) { checks the name fits within the maximum allowed size.
  8. peer->sni = calloc(1, len + 1); allocates memory for the SNI value, one byte more than the length for the terminating zero.
  9. if(!peer->sni) { ... } handles the case where memory allocation failed, cleaning up and returning an out-of-memory error.
  10. Curl_strntolower(peer->sni, peer->hostname, len); copies the name into the SNI field in lowercase.
  11. peer->sni[len] = 0; marks the end of the string.

So when curl connects to an IP address, sni is null, mbedtls_ssl_set_hostname is not called, the certificate name check is bypassed, and the connection is established without verifying the certificate name.

The researcher notes that this is similar to CVE-2016-3739: essentially the bug from 7.21.0, reintroduced in 8.5.0 to 8.6.0 in a slightly different way.

A CVE is a public identifier for a known security flaw, so people can refer to the same issue unambiguously. The same mistake coming back years later is a useful reminder that fixes can be undone by later changes.

How the bug came back

The fix for CVE-2016-3739 (commit 6efd2fa529a189bf41736a610f) made sure mbedtls_ssl_set_hostname is always called, even when the host name is not usable for SNI, for example an IP address or SSLv3. Without the call, mbedTLS does not check the certificate name against the host name and completes the handshake anyway. The researcher attributes the original bug to confusion in the API documentation, and links a discussion of it in the mbedTLS issue tracker.

A commit is a recorded change to a codebase, with an identifier, so you can look up exactly what changed and when. An API is the set of functions a library offers to programs that use it; the documentation explains what each function does, and if that explanation is unclear, programmers can use a function wrongly.

The fix looked like this:

Diff
-  if(!Curl_inet_pton(AF_INET, conn->host.name, &addr) &&
-#ifdef ENABLE_IPV6
-     !Curl_inet_pton(AF_INET6, conn->host.name, &addr) &&
-#endif
-     sni && mbedtls_ssl_set_hostname(&connssl->ssl, conn->host.name)) {
-    infof(data, "WARNING: failed to configure "
-          "server name indication (SNI) TLS extension\n");
+  if(mbedtls_ssl_set_hostname(&connssl->ssl, conn->host.name)) {
+    /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks *and*
+       the name to set in the SNI extension. So even if curl connects to a
+       host specified as an IP address, this function must be used. */
+    failf(data, "couldn't set hostname in mbedTLS");
+    return CURLE_SSL_CONNECT_ERROR;

Line by line:

  1. Lines starting with - are the old code being removed. Lines starting with + are the new code being added. This is the standard format for showing a change.
  2. The removed lines show the old condition: it checked whether the host was not an IPv4 address, not an IPv6 address, and had an SNI value, and only then called the function. In other words, the call was skipped for IP addresses.
  3. The removed infof line only printed a warning when setting SNI failed, and then carried on.
  4. The added if(mbedtls_ssl_set_hostname(&connssl->ssl, conn->host.name)) { calls the function unconditionally, with the host name.
  5. The added comment explains that the function sets the name for CN/SAN checks and for SNI, so it must be used even for IP addresses.
  6. The added failf and return lines report an error and stop the connection if the call fails.

A comment was added to prevent the same confusion about how the function should be used.

Later, commit [redacted] brought back the "SNI" usage and only called mbedtls_ssl_set_hostname when snihost was set. In that version, if snihost was not set, an error was returned instead of continuing the handshake without the name check, so the issue was avoided, but only through unrelated error handling of the SNI host name conversion:

Diff
-  if(mbedtls_ssl_set_hostname(&backend->ssl, hostname)) {
-    /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks *and*
-       the name to set in the SNI extension. So even if curl connects to a
-       host specified as an IP address, this function must be used. */
-    failf(data, "couldn't set hostname in mbedTLS");
-    return CURLE_SSL_CONNECT_ERROR;
+  {
+    char *snihost = Curl_ssl_snihost(data, hostname, NULL);
+    if(!snihost || mbedtls_ssl_set_hostname(&backend->ssl, snihost)) {
+      /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
+         the name to set in the SNI extension. So even if curl connects to a
+         host specified as an IP address, this function must be used. */
+      failf(data, "Failed to set SNI");
+      return CURLE_SSL_CONNECT_ERROR;
+    }

Line by line:

  1. The removed lines are the previous unconditional call and its error handling.
  2. The added { opens a new block.
  3. char *snihost = Curl_ssl_snihost(data, hostname, NULL); asks a helper function to produce an SNI-usable version of the hostname. For an IP address, this helper returns nothing usable.
  4. if(!snihost || mbedtls_ssl_set_hostname(&backend->ssl, snihost)) { runs the error branch if either there is no usable SNI name, or the call to set the hostname fails.
  5. The comment repeats the warning about the function's dual role.
  6. failf and return report the error and stop the connection.

So in this version, an IP address led to an error, not a silent bypass. The researcher's point is that this was accidental: the protection came from error handling written for a different reason, not from a deliberate decision to always check the name.

Finally, commit [redacted] ("keep peer name information together") separated sni and hostname in the peer structure, moved where the peer information is created, and made sni optional. From then on mbedtls_ssl_set_hostname was only called when sni was set; when it was not, the handshake continued and host name verification was bypassed. That reintroduced the bug:

Diff
-  {
-    char *snihost = Curl_ssl_snihost(data, hostname, NULL);
-    if(!snihost || mbedtls_ssl_set_hostname(&backend->ssl, snihost)) {
+
+  if(connssl->peer.sni) {
+    if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) {
       /* mbedtls_ssl_set_hostname() sets the name to use in CN/SAN checks and
          the name to set in the SNI extension. So even if curl connects to a
          host specified as an IP address, this function must be used. */

Line by line:

  1. The removed lines are the block that produced an error when no SNI name was available.
  2. The added if(connssl->peer.sni) { wraps the call in a condition again, so it only runs when an SNI value exists.
  3. The added if(mbedtls_ssl_set_hostname(&backend->ssl, connssl->peer.sni)) { calls the function with the SNI value, inside that condition.
  4. The unchanged comment still says the function must be used even for IP addresses, which is exactly what the surrounding code no longer does.

The researcher's suggested solution is to always call mbedtls_ssl_set_hostname, even when sni is not set, falling back to peer.hostname when sni is null. He also argues that the "for SNI only" confusion has to be prevented in future, since a comment block in the code was evidently not enough.

Related history

For reference, the report lists earlier curl CVEs related to CWE-297:

CWE-297 is a category label for a class of weakness: improper validation of a certificate with host mismatch. Listing earlier CVEs in the same category shows this is a recurring kind of mistake in the same project, not a one-off.

Impact

The weakness is CWE-297, Improper Validation of Certificate with Host Mismatch. The report quotes the CWE description:

Even if a certificate is well-formed, signed, and follows the chain of trust, it may simply be a valid certificate for a different site than the site that the product is interacting with. If the certificate's host-specific data is not properly checked - such as the Common Name (CN) in the Subject or the Subject Alternative Name (SAN) extension of an X.509 certificate - it may be possible for a redirection or spoofing attack to allow a malicious host with a valid certificate to provide data, impersonating a trusted host. In order to ensure data integrity, the certificate must be valid and it must pertain to the site that is being accessed.

In other words, even a valid certificate can be used by an attacker for a different site to impersonate a trusted host, because the name is never compared.

A few terms in that quote:

  • Chain of trust means the certificate was issued by an authority that is itself trusted, possibly through a series of intermediate authorities. It proves the certificate is genuine, not that it belongs to the site you wanted.
  • Common Name (CN) is an older field in a certificate holding a name. Subject Alternative Name (SAN) is the modern field listing all the names a certificate covers.
  • Spoofing means pretending to be someone else. Redirection means sending you somewhere you did not intend to go.

The common consequences, again from CWE-297:

Scope Impact
Access Control Technical Impact: Gain Privileges or Assume Identity
The data read from the system vouched for by the certificate may not be from the expected system.
Authentication Other Technical Impact: Other
Trust afforded to the system in question - based on the malicious certificate - may allow for spoofing or redirection attacks.

Reading the table: the first row says that access control, the rules about who may do what, can be affected, because an attacker can take on another identity. The second row says authentication, the process of proving who you are, can be affected, because trust placed in the wrong system enables spoofing or redirection.

The report rates the likelihood of exploit as high. The report rates the likelihood of exploit as high, and notes the issue affects all kinds of protocol over TLS sessions.

Fix

The report proposes always calling mbedtls_ssl_set_hostname, even when sni is not set, using peer.hostname as the value when sni is null. It also calls for removing the "for SNI only" confusion around the function so the same regression is not introduced again, since a code comment alone did not prevent it.

A regression is when a fix is undone by a later change, so an old bug returns. The history above is a clear example: the same mistake was fixed, avoided by accident, and then brought back.

Variants to test

  1. Connect to a TLS server by IPv4 address with a curl build using mbedTLS and check whether the request succeeds. A positive result is an HTTP response instead of a certificate name mismatch error.
  2. Repeat with an IPv6 literal. The peer type becomes CURL_SSL_PEER_IPV6 and sni is null, which follows the same code path.
  3. Try other TLS-based protocols such as FTPS or SMTPS against an IP address, since the report says all TLS-based protocols are affected.
  4. Test applications that embed libcurl with mbedTLS and connect by IP, not just the CLI, since the report notes the library is exploitable in any such application.
  5. Check builds from 8.5.0 through 8.6.0; 8.4.0 and earlier are not affected, so a failure there is the expected behaviour and not a finding.

An IPv6 literal is an IPv6 address written directly in a URL, in square brackets. IMAPS and POP3S are the secure versions of the protocols used to read mail. The CLI is the command line interface, the curl program you type commands into, as opposed to the library used inside other programs.

Glossary

  • API: the set of functions a library offers to programs that use it, together with the documentation describing how to call them.
  • Backend: in curl, the particular TLS implementation the program was compiled against, such as mbedTLS or another library.
  • Bypass: getting past a security check without satisfying it, for example by never running the check at all.
  • Certificate: a digital document, issued by a trusted authority, that states which names a site is allowed to use and carries the keys used to secure the connection.
  • Chain of trust: the series of signatures linking a certificate back to an authority that is already trusted.
  • CLI (command line interface): a program you operate by typing commands, as opposed to clicking in a window.
  • Commit: a recorded change to a codebase, identified by a hash, so the exact change can be looked up.
  • Common Name (CN): an older field in a certificate holding a name the certificate is for.
  • CVE: a public identifier for a known security flaw, so the same issue can be referred to unambiguously.
  • CWE-297: a category label for the weakness "Improper Validation of Certificate with Host Mismatch".
  • Handshake: the opening exchange between client and server in which they agree on encryption and exchange certificates.
  • Hostname: the friendly name of a machine, like www.example.org, which gets translated into an IP address.
  • IMAPS: the secure version of the protocol used to read mail from a server.
  • IP address: the numeric address of a machine on the internet, like a street address.
  • IPv6 literal: an IPv6 address written directly in a URL, in square brackets.
  • libcurl: the library form of curl, used inside other programs to transfer data.
  • mbedTLS: one particular implementation of TLS, a piece of software that performs the encryption and certificate work.
  • NULL: a programming value meaning "no value" or "nothing here".
  • POP3S: the secure version of the protocol used to download mail from a server.
  • Protocol: an agreed way of talking between computers, for example HTTPS for web pages or FTPS for secure file transfer.
  • Regression: when a fix is undone by a later change, so an old bug returns.
  • SAN (Subject Alternative Name): the field in a certificate listing all the names the certificate is valid for.
  • SNI (Server Name Indication): a field the client sends at the start of the handshake to say which site it wants, so a server hosting many sites can pick the right certificate.
  • Spoofing: pretending to be someone else, for example a server pretending to be a site you trust.
  • TLS: the technology that turns a normal connection into a private, tamper-proof one.
  • URL: the address of something on the internet, like https://www.example.org.

More by frankyueh

View all

1 more disclosed report, 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.