OpenSSL backend: X509 peer certificate not freed in ossl_get_channel_binding causes per-request memory leak (DoS risk for long-lived clients)
The OpenSSL backend of curl does not free the X509 peer certificate obtained during channel binding retrieval for Negotiate authentication, leaking one reference per trigger. A malicious HTTPS server advertising Negotiate can cause a long-lived libcurl client to grow memory without bound, leading to denial of service.
Originally disclosed on HackerOne
- Disclosed after 33 hours
Summary:
In curl’s OpenSSL backend, ossl_get_channel_binding retains a new reference to the server’s X509 certificate via SSL_get1_peer_certificate and never releases it. When Negotiate (SPNEGO) over TLS is in use, this path is invoked and leaks one X509 object per trigger. Over many requests in a long‑running libcurl client, this leads to unbounded memory growth and potential denial‑of‑service.
This occurs only with the OpenSSL backend (>= 1.1.0 gate present), when curl/libcurl is built with GSSAPI (HAVE_GSSAPI), over HTTPS when a Negotiate challenge is processed.
Notes:
- The Negotiate challenge over HTTPS is sufficient to trigger channel binding retrieval; a functional Kerberos setup is not required for this leak to manifest.
- Each trigger leaks one X509 reference.
Supporting Material/References:
- Code location showing missing X509_free on all paths:
cert = SSL_get1_peer_certificate(octx->ssl);
if(!cert) {
/* No server certificate, don't do channel binding */
return CURLE_OK;
}
if(!OBJ_find_sigid_algs(X509_get_signature_nid(cert), &algo_nid, NULL)) {
failf(data,
"Unable to find digest NID for certificate signature algorithm");
return CURLE_SSL_INVALIDCERTSTATUS;
}
/* https://datatracker.ietf.org/doc/html/rfc5929#section-4.1 */
if(algo_nid == NID_md5 || algo_nid == NID_sha1) {
algo_type = EVP_sha256();
}
else {
algo_type = EVP_get_digestbynid(algo_nid);
if(!algo_type) {
algo_name = OBJ_nid2sn(algo_nid);
failf(data, "Could not find digest algorithm %s (NID %d)",
algo_name ? algo_name : "(null)", algo_nid);
return CURLE_SSL_INVALIDCERTSTATUS;
}
}
if(!X509_digest(cert, algo_type, buf, &length)) {
failf(data, "X509_digest() failed");
return CURLE_SSL_INVALIDCERTSTATUS;
}
/* Append "tls-server-end-point:" */
if(curlx_dyn_addn(binding, prefix, sizeof(prefix) - 1) != CURLE_OK)
return CURLE_OUT_OF_MEMORY;
/* Append digest */
if(curlx_dyn_addn(binding, buf, length))
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
Statement on AI usage: AI was used in parts of detection, triage, fix generation and reporting writing in combination with classical tooling and manual human input.
## Impact
## Impact
A remote HTTPS server that advertises `WWW-Authenticate: Negotiate` can cause a libcurl client (built with OpenSSL and GSSAPI) to leak one X509 certificate reference per authentication attempt when TLS channel binding is retrieved.
Over many requests in a long-lived process, this leads to unbounded memory growth and a denial-of-service condition due to resource exhaustion.
The leak occurs because `ossl_get_channel_binding` calls `SSL_get1_peer_certificate` (which increments the X509 reference count) but never calls `X509_free` on any return path—success or error.
### Constraints:
- Requires libcurl built with OpenSSL (>=1.1.0) and GSSAPI support
- Only affects clients using Negotiate authentication over HTTPS
- Linear leak rate (not amplified), but unbounded over time
Severity: **Low** (limited scope, requires specific build configuration and authentication method, but genuine DoS risk for affected deployments)
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 function ossl_get_channel_binding calls SSL_get1_peer_certificate, which increments the certificate's reference count, but never calls X509_free on any return path.
Impact
A remote HTTPS server advertising Negotiate can cause a libcurl client built with OpenSSL and GSSAPI to leak one X509 reference per authentication attempt, leading to unbounded memory growth and denial of service over time.
What the attacker needed
Libcurl built with OpenSSL >=1.1.0; libcurl built with GSSAPI support; client uses Negotiate over HTTPS; server advertises Negotiate
The fix
The function should release the certificate reference with X509_free on every return path, both success and error.
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 curl talks to a server that asks for a special kind of login called Negotiate, it looks at the server's certificate to compute a security value. The code asks for a copy of that certificate but forgets to give it back, so a little memory is lost each time. A malicious server can keep asking for this login, making a long-running program slowly run out of memory.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.