Skip to content
Crypto Disclosed report Advanced

setopt(VERIFYPEER) from callback bypasses TLS verify on connection reuse

A curl bug lets a program that first connects with certificate verification disabled then enable verification from a write callback, and a later request reuses the already-established unverified TLS connection. An attacker in the middle with a rogue certificate could then capture credentials sent on that reused connection while the application sees a successful verification result.

a6b30108 Follow

Originally disclosed on HackerOne

  • Disclosed after 22 hours

Summary:

Curl_ssl_conn_config_update overwrites conn->ssl_config.verifypeer when curl_easy_setopt(CURLOPT_SSL_VERIFYPEER, ...) is called, with no handshake-state guard — only if(data->conn). Since setopt is documented as callable from callbacks (setopt.c:2930), an application can connect with verifypeer=0 (accepting a rogue cert), then flip to verifypeer=1 inside a write callback. The mutation rewrites the pooled connection's ssl_config.verifypeer from 0 to 1, so a subsequent verifypeer=1 request reuses the unverified TLS connection via match_ssl_primary_config (sees 1==1) without a new handshake. The application reads CURLINFO_SSL_VERIFYRESULT=0 (X509_V_OK, calloc default — never updated on reuse) and believes verification passed. A MITM with a rogue-signed cert captures the 2nd request's credentials.

Affected version

curl 8.21.1-DEV (x86_64-pc-linux-gnu) libcurl/8.21.1-DEV OpenSSL/3.5.6 zlib/1.3.1

Bug is in shared lib/vtls/vtls_config.c:406-423, not backend-specific. Reproduced on current master commit cfc7922377.

Steps To Reproduce:

C
#include <curl/curl.h>
#include <stdio.h>

static CURL *g;
static int up;

static size_t cb(char *p, size_t s, size_t n, void *u) {
    if(!up++) curl_easy_setopt(g, CURLOPT_SSL_VERIFYPEER, 1L);
    return s * n;
}

int main(void) {
    curl_global_init(0);
    CURLSH *sh = curl_share_init();
    curl_share_setopt(sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);

    /* 1st: verifypeer=0, accept rogue cert, upgrade to 1 in callback */
    CURL *a = curl_easy_init();
    g = a;
    curl_easy_setopt(a, CURLOPT_URL, "https://127.0.0.1:9443/1");
    curl_easy_setopt(a, CURLOPT_CAINFO, "real_ca.crt");
    curl_easy_setopt(a, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(a, CURLOPT_SSL_VERIFYHOST, 0L);
    curl_easy_setopt(a, CURLOPT_WRITEFUNCTION, cb);
    curl_easy_setopt(a, CURLOPT_SHARE, sh);
    curl_easy_setopt(a, CURLOPT_NOSIGNAL, 1L);
    curl_easy_perform(a);
    curl_easy_cleanup(a);

    /* 2nd: verifypeer=1, should reject but reuses a's unverified conn */
    CURL *b = curl_easy_init();
    curl_easy_setopt(b, CURLOPT_URL, "https://127.0.0.1:9443/2");
    curl_easy_setopt(b, CURLOPT_CAINFO, "real_ca.crt");
    curl_easy_setopt(b, CURLOPT_SSL_VERIFYPEER, 1L);
    curl_easy_setopt(b, CURLOPT_SSL_VERIFYHOST, 0L);
    curl_easy_setopt(b, CURLOPT_SHARE, sh);
    curl_easy_setopt(b, CURLOPT_NOSIGNAL, 1L);
    CURLcode rc = curl_easy_perform(b);

    long vr = -1, nc = -1;
    curl_easy_getinfo(b, CURLINFO_SSL_VERIFYRESULT, &vr);
    curl_easy_getinfo(b, CURLINFO_NUM_CONNECTS, &nc);
    printf("result=%d verify=%ld connects=%ld %s\n", rc, vr, nc,
           (rc == 0 && nc == 0 && vr == 0) ? "BYPASS" : "no-bypass");

    curl_easy_cleanup(b);
    curl_share_cleanup(sh);
    curl_global_cleanup();
    return 0;
}

Self-contained Docker reproduction:

Bash
docker build -t f5-setopt .
docker run --rm f5-setopt

Expected output:

result=0 verify=0 connects=0 BYPASS
  • result=0 — 2nd request succeeded over rogue-signed TLS
  • verify=0 — false X509_V_OK (calloc default, never updated on reuse)
  • connects=0 — connection reused, no new handshake

The 0→1 upgrade is the only exploitable direction. Session cache is unaffected (ssl_peer_key_add_vrfy encodes :NO-VRFY-PEER at handshake time). CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYSTATUS have the same bug (same Curl_ssl_conn_config_update call, same missing guard).

Impact

Summary:

A verifypeer=1 request silently reuses a TLS connection that was established without certificate chain verification. The application cannot detect this — CURLINFO_SSL_VERIFYRESULT returns X509_V_OK (calloc default, never updated on connection reuse), so it believes verification passed. If the reused connection was established to an attacker-controlled server (with verifypeer=0), subsequent requests' credentials and cookies flow over that connection while the application believes TLS is strictly verified.

The original report as published on HackerOne, by a6b30108. 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 connection-config update function overwrites the pooled connection's verifypeer setting without checking whether a handshake has already happened, so a later request matches the reused connection and skips a fresh handshake.

Impact

A request that expects strict certificate verification could silently reuse an unverified connection, letting a man-in-the-middle with a rogue certificate capture credentials and cookies while the application believes verification passed.

What the attacker needed

Application calls setopt from a callback; first connection made with verifypeer=0; shared connection pool between requests; attacker can intercept the connection

How it was found

  1. Initialise curl and a share handle that shares connection data.
  2. Make a first request with certificate verification disabled, accepting a rogue certificate, and enable verification inside the write callback.
  3. Make a second request with verification enabled, which reuses the pooled connection instead of doing a new handshake.
  4. Read the verification result and connection count to confirm the bypass.

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 a program makes an HTTPS connection, it normally checks the server's certificate to confirm it is talking to the right server. This report shows that if a program turns that check off for one connection and later turns it on, curl can quietly reuse the unchecked connection for the next request. The program is told the check passed, but it never actually happened, so someone intercepting the traffic could read the data.

What is Crypto?

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

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.