# CVE-2021-22924: Bad connection reuse due to flawed path name checks

curl's Curl_ssl_config_matches compared SSL configs case-insensitively and ignored BLOB/issuercert options, letting a poisoned connection cache reuse a weaker TLS connection and enable MITM.

- Payout: hidden
- Severity: high
- Program: curl
- Found by: nyymi
- Disclosed: 2021-07-21
- CVE: CVE-2021-22924
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1223565
- Library page: https://bugbountylibrary.com/r/h1%3A1223565
- Tags: area:oss domain:oss impact:data-leak impact:integrity kind:bounty platform:hackerone sev:high tech:curl technique:source-review vuln:auth-bypass vuln:misconfiguration

**Target:** libcurl connection cache / TLS config equivalence check
**Root cause:** Curl_ssl_config_matches compared capath/cainfo/pinnedpubkey paths and sha256// fingerprints case-insensitively, and omitted CURLOPT_CAINFO_BLOB, CURLOPT_ISSUERCERT_BLOB and CURLOPT_ISSUERCERT from the equivalence check, so connections with different security settings were treated as identical.
**Steps:**
1. `cp /etc/ssl/certs/ca-certificates.crt ca.crt`
2. `touch CA.crt`
3. `curl --capath /dev/null --cacert $PWD/ca.crt https://curl.se --next --capath /dev/null --cacert $PWD/CA.crt https://curl.se`
4. Second connection should fail but instead reuses the first cached connection because paths differ only by case
**How found:** Code review of Curl_ssl_config_matches: noticed it used case-insensitive path comparison and never compared BLOB-type cert options or CURLOPT_ISSUERCERT, hypothesizing that a prior connection with different security options could poison the cache.
**Exploitation:** Attacker first coaxes the app into opening a TLS connection to the same host:port using weaker/attacker-controlled cainfo, capath, issuer cert or pinned key (e.g. via a user-supplied URL or a writable /tmp path with different capitalization). When the app later opens the intended high-security connection to that host:port, libcurl's cache match returns the poisoned connection, so the attacker's MITM certificate is accepted and confidentiality/integrity are lost.
**Escalation:** Crosses a privilege barrier between the user controlling connection targets and the app performing privileged backend connections; also usable for lateral MITM against other users of the same service.
**Insight:** When auditing connection/session caches, enumerate every security-relevant option and check each is compared with the correct semantics (binary blobs byte-wise, paths and fingerprints case-sensitively); any option omitted from the equivalence predicate is a cache-poisoning primitive.

