Skip to content
Access control Disclosed report Advanced

HackerOne Vulnerability Report: libcurl SSL/TLS Identity Leakage via Insecure Connection Reuse

libcurl's connection reuse matching for TLS connections ignored the SSL context callback, so a connection set up with a client certificate could be reused by a later transfer that specified no certificate. An attacker-controlled or anonymous request in the same process could then be treated by the server as authenticated under the first identity.

ankitsingh131225 Follow with yogi-76

Originally disclosed on HackerOne

  • Disclosed after 38 hours

Summary

libcurl contains a critical logic flaw in its connection reuse mechanism where transfers using the CURLOPT_SSL_CTX_FUNCTION (SSL context callback) to establish a specific identity (e.g., via client certificates) can have their connections incorrectly reused by subsequent, unauthenticated transfers to the same host. This leads to identity leakage and authentication bypass between independent easy handles within the same application process.


Technical Description

The Flaw

When a connection is established, libcurl caches it in a connection pool for potential reuse. To ensure safety, libcurl performs a "matching" check to verify that the new request requires the same security-sensitive configuration as the cached connection.

However, the matching logic for SSL/TLS connections in lib/vtls/vtls.c (and the connection data structure itself) only tracks and compares the "primary" SSL configuration (e.g., verify flags, CA paths). It entirely omits the fsslctx field (the callback set via CURLOPT_SSL_CTX_FUNCTION).

Affected Code References

  1. Inadequate Data Storage: In lib/urldata.h, the connectdata structure only stores struct ssl_primary_config ssl_config.
  2. Incomplete Cloning: In Curl_ssl_conn_config_init, only the primary configuration is cloned from the easy handle to the connection. The fsslctx callback is lost at the connection level.
  3. Flawed Matching: In match_ssl_primary_config, the comparison loop only checks fields within the primary config. It has no way to detect if a connection was established using a custom SSL context callback.

Steps to Reproduce (Conceptual PoC)

  1. Set up an HTTPS server that requires client certificate authentication.
  2. Perform a transfer with Handle 1, using CURLOPT_SSL_CTX_FUNCTION to load a valid client certificate.
  3. Perform a second transfer with Handle 2 to the same host/port, but do not specify any client certificate or callback.
  4. Observe that libcurl reuses the connection from Handle 1 (verified via CURLINFO_NUM_CONNECTS returning 0 for the second transfer).
  5. Observe that the server accepts the second request as authenticated under Handle 1's identity.

Recommended Mitigation

  1. Extend struct ssl_primary_config to include the fsslctx callback pointer (or a hash of its identity if the pointer is not sufficient).
  2. Update match_ssl_primary_config to include a strict comparison of the fsslctx (and fsslctxp) fields.
  3. Ensure that any connection established with a custom SSL_CTX callback is marked as non-reusable by any request that does not share the exact same callback configuration.

Related Observations

During this audit, verified similar matching gaps were found in:

  • IMAP/SMTP/POP3/LDAP: conn->options (login options) are ignored in url_match_auth.
  • SSH: known_hosts file paths and policies are ignored in ssh_config_matches. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Impact

Summary:

Scenario: Identity Theft / Authentication Bypass

  1. Request A: An application uses CURLOPT_SSL_CTX_FUNCTION to load a specific user's client certificate into the SSL context. The connection is established and the user is authenticated by the server.
  2. Request B: A second, unauthenticated request (possibly for a different user or an anonymous action) is made to the same host.
  3. Vulnerability: libcurl matches Request B to the existing connection of Request A because their "primary" SSL settings (like verifypeer) are identical. Request B reuses the already-authenticated TLS session of Request A.
  4. Result: Request B is performed under Request A's identity, bypassing authentication and potentially accessing private data.

This is a High Severity issue in multi-identity applications or services using libcurl as a shared backend.

The original report as published on HackerOne, by ankitsingh131225. 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. 5 min read.

Context

libcurl keeps a pool of established connections so that later transfers can reuse them instead of paying for a new TCP and TLS handshake. Before a cached connection is handed to a new request, libcurl runs a matching check: the new request must require the same security-sensitive configuration as the connection that was cached. For SSL/TLS connections this check lives in lib/vtls/vtls.c and compares the "primary" SSL configuration, things like verify flags and CA paths.

The report describes a logic flaw in that reuse mechanism. A transfer that uses CURLOPT_SSL_CTX_FUNCTION, the SSL context callback, to establish a particular identity (for example by loading a client certificate into the SSL context) can have its connection reused by a later, unauthenticated transfer to the same host. The result is identity leakage and authentication bypass between independent easy handles inside the same application process. The affected asset is the curl source repository, and the weakness is classified as authentication bypass by primary weakness.

Setup

The report does not describe a specific build, version, operating system or test harness. The reproduction is presented as a conceptual proof of concept, so the preconditions are the ones named in the steps themselves:

  1. An HTTPS server that requires client certificate authentication.
  2. An application that uses libcurl as a shared backend and creates more than one easy handle in the same process.
  3. At least one transfer that supplies a client certificate through CURLOPT_SSL_CTX_FUNCTION.
  4. A second transfer to the same host and port that does not supply a certificate or callback.

Finding it

The researcher audited how libcurl decides whether a cached connection may be reused. The matching logic for SSL/TLS connections, together with the connection data structure itself, only tracks and compares the primary SSL configuration. It entirely omits the fsslctx field, which is the callback set via CURLOPT_SSL_CTX_FUNCTION. Because that callback is what establishes the identity of a connection in the client-certificate case, two requests with identical primary settings but completely different identities look interchangeable to the matcher.

The report points to three places in the code where this shows up:

  1. Inadequate data storage. In lib/urldata.h, the connectdata structure only stores struct ssl_primary_config ssl_config.
  2. Incomplete cloning. In Curl_ssl_conn_config_init in lib/vtls/vtls.c, only the primary configuration is cloned from the easy handle to the connection. The fsslctx callback is lost at the connection level.
  3. Flawed matching. In match_ssl_primary_config in lib/vtls/vtls.c, the comparison loop only checks fields within the primary config. It has no way to detect whether a connection was established using a custom SSL context callback.

Exploitation

Step 1: stand up an HTTPS server that requires client certificates

The server must demand client certificate authentication, so that a connection established with a valid certificate is meaningfully different from one established without it.

Step 2: make an authenticated transfer with Handle 1

Handle 1 performs a transfer using CURLOPT_SSL_CTX_FUNCTION to load a valid client certificate. The server authenticates the connection under that identity, and libcurl caches the connection in its pool.

Step 3: make an unauthenticated transfer with Handle 2

Handle 2 performs a second transfer to the same host and port, but does not specify any client certificate or callback. Because the primary SSL settings of the two requests match, libcurl considers the cached connection suitable for reuse.

Step 4: confirm the reuse

The researcher verifies that libcurl reused the connection from Handle 1 by checking that CURLINFO_NUM_CONNECTS returns 0 for the second transfer. A value of 0 means no new connection was made.

Step 5: observe the server's view

The server accepts the second request as authenticated under Handle 1's identity. The unauthenticated handle has inherited the authenticated TLS session.

Root cause

The connection pool's safety check is only as good as the data it compares. connectdata stores just the primary SSL configuration, Curl_ssl_conn_config_init clones just that primary configuration from the easy handle, and match_ssl_primary_config compares just those fields. The fsslctx callback, and with it the identity the callback installs, never enters the comparison. Two requests whose primary settings such as verifypeer are identical therefore match, even when one of them was authenticated with a client certificate and the other was not.

The existing defence, the matching check itself, did not stop this because the check was never designed to look at the callback. The report does not describe any additional layer that would have caught the mismatch.

Impact

The report frames the issue as identity theft and authentication bypass, rated High Severity for multi-identity applications or services that use libcurl as a shared backend. The scenario runs as follows:

  1. Request A: the application uses CURLOPT_SSL_CTX_FUNCTION to load a specific user's client certificate into the SSL context. The connection is established and the user is authenticated by the server.
  2. Request B: a second, unauthenticated request, possibly for a different user or an anonymous action, is made to the same host.
  3. Vulnerability: libcurl matches Request B to Request A's connection because their primary SSL settings, such as verifypeer, are identical. Request B reuses the already-authenticated TLS session of Request A.
  4. Result: Request B is performed under Request A's identity, bypassing authentication and potentially accessing private data.

The exposure depends on the application sharing a connection pool across identities within one process. The report does not quantify how many applications meet that condition.

Fix

The report recommends three changes:

  1. Extend struct ssl_primary_config to include the fsslctx callback pointer, or a hash of its identity if the pointer alone is not sufficient.
  2. Update match_ssl_primary_config to include a strict comparison of the fsslctx and fsslctxp fields.
  3. Ensure that any connection established with a custom SSL_CTX callback is marked as non-reusable by any request that does not share the exact same callback configuration.

Variants to test

During the same audit the researcher found similar matching gaps elsewhere, which suggest concrete directions for testing other protocols and options:

  1. IMAP, SMTP, POP3 and LDAP login options. conn->options are ignored in url_match_auth in lib/url.c.
  2. SSH host verification policy. known_hosts file paths and policies are ignored in ssh_config_matches in lib/url.c.
  3. Any option that changes identity but is not part of the compared configuration.

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. 11 min read.

What happened, in plain words

A library called libcurl is used by many programs to talk to web servers and other internet services. To save time, it keeps a small collection of already-open connections and reuses them for later requests instead of starting from scratch every time. Before it hands an old connection to a new request, it checks that the new request is safe to send over that connection.

The report says that check has a gap. If one request proved who it was by presenting a client certificate (a kind of digital ID card), and a later request to the same server did not present any ID at all, libcurl can still decide the old connection is fine to reuse. The second request then travels over a connection that the server already treats as logged in. The second request gets the first request's identity for free. The report calls this identity leakage and authentication bypass.

The report is a bug report filed on a bug bounty platform against the curl project, which is where libcurl is developed. It is written as a conceptual proof of concept: it explains the flaw and the steps that would show it, rather than shipping a ready-made program. The report does not give a version number, an operating system or a test setup.

Background you need first

What libcurl is

libcurl is a piece of software that other programs embed to make network requests. Think of it as the engine under the bonnet: your program says "fetch this URL" or "log in to this mail server", and libcurl handles the conversations with the other machine. It is the library form of the curl command-line tool, which many people use directly in a terminal.

Connections, handshakes and the connection pool

When two computers talk over the internet, they first open a connection. For a secure website (one whose address starts with https://), they also perform a TLS handshake. TLS is the encryption layer that protects the conversation, and the handshake is the opening exchange where the two sides agree on encryption and, optionally, prove who they are. A handshake costs time and computing effort.

Because of that cost, libcurl keeps a pool of connections that are already open. When a new request goes to a host it has talked to recently, libcurl can reuse an existing connection instead of doing a fresh handshake. This is normal and desirable behaviour, the same way a browser keeps a connection open to a site you are browsing.

The matching check

Reuse is only safe if the old connection suits the new request. So before reusing, libcurl runs a matching check: it compares the security-sensitive settings of the new request with those recorded for the cached connection. If they match, reuse is allowed. If not, a new connection is made.

For secure connections, this check lives in a source file called lib/vtls/vtls.c. It compares what the report calls the "primary" SSL configuration: settings such as verify flags (whether the server's certificate must be checked) and CA paths (where the trusted certificate authorities are stored).

Easy handles

An easy handle is libcurl's name for one unit of work inside a program: one transfer, with its own settings. A program can create several easy handles in the same process, for example one per user or one per task. They share the same connection pool.

The SSL context callback

CURLOPT_SSL_CTX_FUNCTION is a libcurl option that lets the program supply its own function to configure the TLS layer for a connection. The report focuses on one use of it: loading a client certificate into the SSL context. A client certificate is a digital ID card that the client presents to the server so the server can tell which client it is talking to. The callback set through this option is stored in a field called fsslctx.

The vulnerability class

The report classifies the weakness as authentication bypass by primary weakness. Authentication is the process of proving who you are. A bypass means getting past that check without proving anything. "By primary weakness" means the bypass happens because of a more basic flaw elsewhere, here the connection-reuse logic, rather than because the login mechanism itself was broken.

The flaw in detail

When a connection is established, libcurl caches it in the pool. The matching check is supposed to make sure a new request needs the same security-sensitive configuration as the cached connection. The report says that for SSL/TLS connections, both the matching logic and the data structure that describes a connection only track and compare the primary SSL configuration. They leave out the fsslctx field entirely.

That omission matters because in the client-certificate case, the callback is exactly what establishes the identity. Two requests can have identical primary settings and completely different identities, and the matcher will see them as interchangeable.

The report points to three places in the code where this shows up.

1. Inadequate data storage

In lib/urldata.h, the structure that describes a connection, called connectdata, only stores the primary SSL configuration:

Text
struct ssl_primary_config ssl_config

A structure (or struct) is a way of grouping related pieces of data under one name. Here, connectdata is the record libcurl keeps about a connection. The line says that the only SSL-related thing recorded in that record is ssl_config, of type ssl_primary_config. There is no place in the record for the callback, so the callback cannot be compared later.

2. Incomplete cloning

In a function called Curl_ssl_conn_config_init in lib/vtls/vtls.c, only the primary configuration is copied (cloned) from the easy handle to the connection. The fsslctx callback is lost at the connection level. In everyday terms: the request knows which ID card to use, but the record of the connection does not note it down, so nobody can check it afterwards.

3. Flawed matching

In a function called match_ssl_primary_config in lib/vtls/vtls.c, the comparison loop only checks fields inside the primary configuration. It has no way to detect whether a connection was established using a custom SSL context callback. The check is thorough about the settings it knows, but blind to the one that decides identity here.

How the flaw would be shown

The report presents the reproduction as a conceptual proof of concept. That means it describes the steps and the expected observations, not a complete program you can run as-is. The preconditions are the ones named in the steps themselves:

  1. An HTTPS server that requires client certificate authentication.
  2. An application that uses libcurl as a shared backend and creates more than one easy handle in the same process.
  3. At least one transfer that supplies a client certificate through CURLOPT_SSL_CTX_FUNCTION.
  4. A second transfer to the same host and port that does not supply a certificate or callback.

Step 1: stand up an HTTPS server that requires client certificates

The server must demand client certificate authentication. Why: the whole point is that a connection made with a valid certificate is meaningfully different from one made without it. If the server accepted anyone, there would be nothing to bypass.

Step 2: make an authenticated transfer with Handle 1

Handle 1 performs a transfer using CURLOPT_SSL_CTX_FUNCTION to load a valid client certificate. The server authenticates the connection under that identity, and libcurl caches the connection in its pool. Why this step: it creates the authenticated connection that the flaw will later let another request borrow.

Step 3: make an unauthenticated transfer with Handle 2

Handle 2 performs a second transfer to the same host and port, but does not specify any client certificate or callback. Because the primary SSL settings of the two requests match, libcurl considers the cached connection suitable for reuse. Why this step: it tests whether the matcher notices the missing identity. According to the report, it does not.

Step 4: confirm the reuse

The researcher verifies that libcurl reused the connection from Handle 1 by checking that CURLINFO_NUM_CONNECTS returns 0 for the second transfer. CURLINFO_NUM_CONNECTS is a libcurl query that reports how many new connections a transfer had to make. A value of 0 means no new connection was made, so the old one was reused.

Step 5: observe the server's view

The server accepts the second request as authenticated under Handle 1's identity. The unauthenticated handle has inherited the authenticated TLS session. Why this matters: from the server's side, the second request looks like the first user. Data or actions that user is allowed to reach may now be reachable by a request that never proved anything.

Why it happens

The connection pool's safety check is only as good as the data it compares. connectdata stores just the primary SSL configuration, Curl_ssl_conn_config_init clones just that primary configuration from the easy handle, and match_ssl_primary_config compares just those fields. The fsslctx callback, and with it the identity the callback installs, never enters the comparison. Two requests whose primary settings such as verifypeer are identical therefore match, even when one of them was authenticated with a client certificate and the other was not.

verifypeer is one of those primary settings: it controls whether the client checks the server's certificate. It says nothing about which client certificate the client presents.

The existing defence, the matching check itself, did not stop this because the check was never designed to look at the callback. The report does not describe any additional layer that would have caught the mismatch.

Impact

The report frames the issue as identity theft and authentication bypass, rated High Severity for multi-identity applications or services that use libcurl as a shared backend. The scenario runs as follows:

  1. Request A: the application uses CURLOPT_SSL_CTX_FUNCTION to load a specific user's client certificate into the SSL context. The connection is established and the user is authenticated by the server.
  2. Request B: a second, unauthenticated request, possibly for a different user or an anonymous action, is made to the same host.
  3. Vulnerability: libcurl matches Request B to Request A's connection because their primary SSL settings, such as verifypeer, are identical. Request B reuses the already-authenticated TLS session of Request A.
  4. Result: Request B is performed under Request A's identity, bypassing authentication and potentially accessing private data.

The exposure depends on the application sharing a connection pool across identities within one process. The report does not quantify how many applications meet that condition.

The recommended fix

The report recommends three changes:

  1. Extend struct ssl_primary_config to include the fsslctx callback pointer, or a hash of its identity if the pointer alone is not sufficient. A pointer is the internal address of a piece of code or data; a hash is a short fingerprint computed from something, used here to tell one callback apart from another.
  2. Update match_ssl_primary_config to include a strict comparison of the fsslctx and fsslctxp fields. In plain terms: make the matching check actually look at the callback, not just the settings around it.
  3. Ensure that any connection established with a custom SSL_CTX callback is marked as non-reusable by any request that does not share the exact same callback configuration. In plain terms: if a connection was opened with a particular ID card, only a request with that same ID card may borrow it.

Similar gaps elsewhere

During the same audit the researcher found similar matching gaps in other parts of libcurl, which suggest concrete directions for testing other protocols and options:

  1. IMAP, SMTP, POP3 and LDAP login options. These are protocols for mail and directory services. The report says conn->options (login options) are ignored in url_match_auth in lib/url.c.
  2. SSH host verification policy. SSH is the protocol used for secure remote shells. The report says known_hosts file paths and policies are ignored in ssh_config_matches in lib/url.c. A known_hosts file records which servers you trust.
  3. Any option that changes identity but is not part of the compared configuration.

Glossary

  • Authentication: the process of proving who you are to another system.
  • Authentication bypass: getting past a login or identity check without proving who you are.
  • Authentication bypass by primary weakness: a bypass that happens because of a more basic flaw elsewhere, rather than a broken login mechanism itself.
  • CA path: the location where trusted certificate authorities are stored, used to check certificates.
  • Client certificate: a digital ID card a client presents to a server so the server can identify it.
  • Connection pool: a collection of already-open connections kept for reuse.
  • connectdata: the libcurl structure that records the details of a connection.
  • CURLINFO_NUM_CONNECTS: a libcurl query reporting how many new connections a transfer had to make; 0 means none.
  • CURLOPT_SSL_CTX_FUNCTION: a libcurl option that lets the program supply its own function to configure the TLS layer.
  • Easy handle: libcurl's name for one unit of work, one transfer with its own settings.
  • fsslctx: the field holding the callback set through CURLOPT_SSL_CTX_FUNCTION.
  • fsslctxp: a related field the report says should also be compared when matching connections.
  • Hash: a short fingerprint computed from something, used to tell two things apart.
  • HTTPS: the secure version of the web protocol, protected by TLS.
  • Identity leakage: one request's identity becoming available to another request that did not prove it.
  • IMAP, SMTP, POP3: protocols for reading and sending mail.
  • LDAP: a protocol for directory services.
  • libcurl: a library that programs embed to make network requests.
  • Matching check: the comparison libcurl runs before reusing a cached connection, to confirm the new request's settings suit it.
  • Pointer: the internal address of a piece of code or data in a program.
  • Primary SSL configuration: the set of SSL settings libcurl records and compares, such as verify flags and CA paths.
  • ssl_primary_config: the structure holding that primary SSL configuration.
  • SSH: a protocol for secure remote access to another machine.
  • known_hosts: a file recording which servers you trust for SSH.
  • Struct (structure): a way of grouping related pieces of data under one name.
  • TLS: the encryption layer that protects connections such as HTTPS.
  • TLS handshake: the opening exchange where two sides agree on encryption and optionally prove who they are.
  • verifypeer: a setting controlling whether the client checks the server's certificate.
  • Vulnerability: a flaw that can be used to make a system behave in a way its designers did not intend.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.