Skip to content
Memory corruption Disclosed report Advanced CVE-2023-27537

Shared HSTS cache accessed without lock

When the HSTS cache is shared between threads, several code paths read and modify the shared list without taking the share lock. Two threads hitting the same expired entry could cause a double-free, or one thread appending while another frees the tail could cause a use-after-free.

Daniel Stenberg Follow

Originally disclosed on HackerOne

  • Disclosed after 29 days

This is finding F5 in Andrew's report

https://github.com/curl/curl/blob/455bebc2c7/lib/hsts.c#L160-L168 https://github.com/curl/curl/blob/455bebc2c7/lib/http.c#L3571 https://github.com/curl/curl/blob/455bebc2c7/lib/url.c#L1441 https://github.com/curl/curl/blob/455bebc2c7/lib/url.c#L265 https://github.com/curl/curl/blob/455bebc2c7/lib/transfer.c#L613 https://github.com/curl/curl/blob/455bebc2c7/lib/curl_share.c#L459 https://github.com/curl/curl/blob/455bebc2c7/lib/hsts.c#L605-L613

When CURL_LOCK_DATA_HSTS is shared, data->hsts aliases share->hsts (curl_share.c:459). The CVE-2023-27537 fix added locking only to Curl_hsts_loadfiles (hsts.c:605-613). All other paths access the shared list without locking:

Curl_hsts_parse (http.c:3571) on incoming Strict-Transport-Security header → appends/removes entries
Curl_hsts_applies → hsts_check (url.c:1441) on every http:// URL → walks the list AND frees expired entries (hsts.c:166-167: Curl_node_remove(&sts->node); hsts_free(sts);)
Curl_hsts_save (url.c:265) in Curl_close → walks the list
Curl_hsts_loadcb (transfer.c:613) → appends entries

Race A (double-free): two threads each call hsts_check on the same expired entry; both reach line 166-167 with the same sts pointer; double-free + llist corruption.

Race B (UAF): thread 1 in Curl_hsts_parse appending (writes list->tail->next); thread 2 in hsts_check frees that tail node as expired.

Note hsts_check is not read-only despite the name — it mutates during lookup, so even "read" paths need exclusive locking.

Same bug class as CVE-2023-27537 (HSTS double-free), in code paths that fix did not cover. Contrast with cookies in the same function: http.c:3550-3553 wraps Curl_cookie_add in Curl_share_lock(CURL_LOCK_DATA_COOKIE); the HSTS call 18 lines later has no equivalent.

Suggested fix: wrap all four call sites in Curl_share_lock/unlock(data, CURL_LOCK_DATA_HSTS, CURL_LOCK_ACCESS_SINGLE). Note CURL_LOCK_ACCESS_SINGLE (exclusive), not shared, on every path including the lookup at url.c:1441 — hsts_check mutates the list during what looks like a read, so a reader/writer split would still race.

Verified by grep for CURL_LOCK_DATA_HSTS (only 4 hits: 2 in share.c registration, 2 in the loadfiles lock/unlock pair) and reading each unlocked call site.

Impact

double-free or UAF?

The original report as published on HackerOne, by bagder. 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

The CVE-2023-27537 fix added locking only to the file-loading path, leaving the parse, lookup, save and load-callback paths to touch the shared HSTS list without the share lock.

What the attacker needed

Shared HSTS cache across threads; two threads race on the same entry

The fix

All four call sites should take the exclusive share lock for HSTS, including the lookup, because it mutates the list during what looks like a read.

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.

A program can share one cache of security settings between several threads. A lock is meant to stop two threads touching the same entry at once, but here most code paths skip the lock. If two threads change or delete the same entry together, memory can be freed twice or used after it is gone, which can crash the program or corrupt it.

What is Memory corruption?

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.

More by Daniel Stenberg

View all

6 more disclosed reports, 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.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.