CVE-2023-23915: HSTS amnesia with --parallel
When curl ran several transfers in parallel with HSTS enabled, the HSTS cache file was overwritten by whichever transfer finished last, so entries from other hosts were lost. A later plain HTTP request to a host whose entry had been lost would not be upgraded to HTTPS as HSTS should enforce.
- Triaged in 7 days
- Fixed in 9 days
- Paid in 9 days
- Disclosed after 9 days
Summary by the program
CVE-2023-23915: HSTS amnesia with --parallel Project curl Security Advisory, February 15 2023
VULNERABILITY curl's HSTS cache saving behaves wrongly when multiple URLs are requested in parallel.
Using its HSTS support, curl can be instructed to use HTTPS instead of using an insecure clear-text HTTP step even when HTTP is provided in the URL. This HSTS mechanism would however surprisingly fail when multiple transfers are done in parallel as the HSTS cache file gets overwritten by the most recently completed transfer.
A later HTTP-only transfer to the earlier host name would then not get upgraded properly to HSTS.
Reproducible like this:
curl --hsts hsts.txt --parallel https://curl.se https://example.com curl --hsts hsts.txt http://curl.se We are not aware of any exploit of this flaw.
INFO This is a curl command line issue and does not affect libcurl. This flaw was introduced in commit 7385610d0c7, which was shipped enabled by default from commit d71ff2b9db566b3f in curl 7.77.0. The Common Vulnerabilities and Exposures (CVE) project has assigned the name CVE-2023-23915 to this issue. CWE-319: Cleartext Transmission of Sensitive Information Severity: Low
AFFECTED VERSIONS Affected versions: curl 7.77.0 to and including 7.87.0 Not affected versions: curl < 7.77.0 and curl >= 7.88.0 curl is used by many applications, but not always advertised as such!
THE SOLUTION 7.88.0 will share the HSTS state properly between transfers, making each subsequent save store a complete state. A fix for CVE-2023-23914
RECOMMENDATIONS A - Upgrade curl to version 7.88.0 B - Apply the patch to your local version C - Specify all URLs with HTTPS:// and not HTTP://
TIMELINE This issue was reported to the curl project on December 21, 2022. We contacted distros @ openwall on February 7, 2022.
curl 7.88.0 was released on February 15 2023, coordinated with the publication of this advisory.
CREDITS Reported-by: Harry Sintonen Patched-by: Daniel Stenberg Thanks a lot!
Full Security Advisory: https://curl.se/docs/CVE-2023-23915.html
The report
curl's HSTS cache saving behaves wrongly when multiple URLs are requested in parallel.
Using its HSTS support, curl can be instructed to use HTTPS instead of using an insecure clear-text HTTP step even when HTTP is provided in the URL. This HSTS mechanism would however surprisingly fail when multiple transfers are done in parallel as the HSTS cache file gets overwritten by the most recently completed transfer.
A later HTTP-only transfer to the earlier host name would then not get upgraded properly to HSTS.
Impact
Bypass intended security control.
Context
curl is a command-line tool and library for transferring data with URLs. It supports HSTS (HTTP Strict Transport Security), which lets a user tell curl to upgrade http:// URLs to https:// for hosts that have previously been seen over HTTPS. This is done with the --hsts option, which names a file where curl stores the HSTS cache. When curl is asked to fetch a URL over plain HTTP for a host in that cache, it should silently switch to HTTPS instead.
The report concerns the curl command-line tool, not libcurl. The flaw is in how the HSTS cache file is saved when several URLs are requested in parallel with --parallel.
Setup
No special account or role is needed. The researcher used the curl command line with the --hsts option and a cache file, and the --parallel option to request multiple URLs at once. The affected versions are curl 7.77.0 through 7.87.0 inclusive. Versions before 7.77.0 and from 7.88.0 onward are not affected.
The flaw was introduced in commit 7385610d0c7, which was shipped enabled by default from commit d71ff2b9db566b3f in curl 7.77.0.
Finding it
The researcher noticed that curl's HSTS cache saving behaves wrongly when multiple URLs are requested in parallel. The HSTS cache file gets overwritten by the most recently completed transfer, so the saved state reflects only that last transfer rather than the combined state of all transfers. As a result, a later HTTP-only transfer to an earlier host name would not get upgraded properly to HSTS.
This looked wrong because the HSTS mechanism is supposed to persist the knowledge that a host uses HTTPS, so that a later plain HTTP request to that host is upgraded. With parallel transfers, that persistence fails for all but the last completed transfer.
Exploitation
The report gives a two-step reproduction.
Step 1: populate the HSTS cache with parallel transfers
curl --hsts hsts.txt --parallel https://curl.se https://example.com
This command requests two HTTPS URLs in parallel and writes the HSTS cache to hsts.txt. Because the transfers run in parallel, the cache file is overwritten by whichever transfer completes last. The HSTS state for the other host is lost.
Step 2: request the earlier host over plain HTTP
curl --hsts hsts.txt http://curl.se
This command uses the same cache file and requests http://curl.se over plain HTTP. Because the HSTS entry for curl.se was not saved in step 1 (it was overwritten by the other transfer), curl does not upgrade the request to HTTPS. The request goes out over clear-text HTTP.
The report does not show the actual output of these commands; it states that the later HTTP-only transfer to the earlier host name would not get upgraded properly to HSTS.
Root cause
When multiple transfers run in parallel, each transfer saves the HSTS cache independently. The save operation writes the whole cache file, so the last transfer to finish overwrites the file with its own view of the HSTS state. The HSTS state is not shared properly between transfers, so entries learned by other transfers are lost.
The fix in 7.88.0 shares the HSTS state properly between transfers, making each subsequent save store a complete state.
Impact
The report describes the impact as "Bypass intended security control" and states that the authors are not aware of any exploit of this flaw. The report describes the impact as "Bypass intended security control" and assigns CWE-319: Cleartext Transmission of Sensitive Information, with severity Low. The report states that the authors are not aware of any exploit of this flaw.
The flaw is in the curl command line only and does not affect libcurl. It requires the use of --parallel with --hsts and a later HTTP request to a host whose HSTS entry was lost.
Fix
curl 7.88.0 shares the HSTS state properly between transfers, so that each subsequent save stores a complete state. The report also lists recommendations:
- Upgrade curl to version 7.88.0.
- Apply the patch to your local version.
- Specify all URLs with
HTTPS://and notHTTP://.
The report also mentions "A fix for CVE-2023-23914".
Variants to test
- Use
--parallelwith more than two URLs and check whether the HSTS cache file contains entries for all hosts after the command finishes. A positive result is that only the last completed transfer's host is present. - Use
--parallelwith a mix of hosts and then request each host overhttp://with the same cache file. A positive result is that at least one host is not upgraded to HTTPS. - Test with different orderings and timings of the parallel transfers to see whether the last completed transfer varies. A positive result is that the surviving cache entry changes with timing.
Hunting notes
This kind of bug tends to hide in command-line tools that persist state to a file while performing concurrent operations. During recon, look for options that write shared state (cache files, configuration files, logs) and options that enable concurrency (parallel transfers, multiple threads). The signal is a mismatch between the expected persistent state and the state after a concurrent run.
The report gives a two-step reproduction and states that the later HTTP-only transfer would not get upgraded properly to HSTS.
What happened, in plain words
curl is a small program that runs in a terminal (the text window where you type commands instead of clicking) and fetches things from the internet, such as web pages or files. It is also available as a library, libcurl, that other programs use to do the same fetching. This report is about the command-line program only, not the library.
One of curl's features is called HSTS, short for HTTP Strict Transport Security. Normally, when you type a web address starting with http://, your traffic travels unencrypted, so anyone on the network path can read it. When a site uses HTTPS (the https:// version), the traffic is encrypted. HSTS is a way for a site to tell a browser or a tool: from now on, always use HTTPS for me, even if someone writes http://. It is like a doorman who keeps a list of visitors who must always come through the secure entrance, and quietly redirects anyone who tries the ordinary door.
curl keeps that list in a file, called the HSTS cache, and you point it at the file with the --hsts option. When you ask curl for http:// on a host that is on the list, curl should silently switch to https:// instead.
The bug is about what happens when curl fetches several addresses at the same time, using the --parallel option. Instead of combining everything it learned into one list, curl let each transfer save the file on its own, and the last one to finish overwrote whatever the others had written. So the list ended up containing only the knowledge from that final transfer. A later plain http:// request to one of the earlier hosts was then not upgraded to HTTPS, and the traffic went out unencrypted.
Context
curl is a command-line tool and library for transferring data with URLs. It supports HSTS (HTTP Strict Transport Security), which lets a user tell curl to upgrade http:// URLs to https:// for hosts that have previously been seen over HTTPS. This is done with the --hsts option, which names a file where curl stores the HSTS cache. When curl is asked to fetch a URL over plain HTTP for a host in that cache, it should silently switch to HTTPS instead.
The report concerns the curl command-line tool, not libcurl. The flaw is in how the HSTS cache file is saved when several URLs are requested in parallel with --parallel.
A few terms first. A URL is just a web address, the thing you type in a browser's address bar. A host is the part of the address that names the machine, such as curl.se or example.com. A cache is a stored copy of something kept so it can be reused later, like a shopping list you keep in your pocket instead of rewriting it every time. An option (also called a flag) is a word starting with -- that you add to a command to change how it behaves.
Setup
No special account or role is needed. The researcher used the curl command line with the --hsts option and a cache file, and the --parallel option to request multiple URLs at once. The affected versions are curl 7.77.0 through 7.87.0 inclusive. Versions before 7.77.0 and from 7.88.0 onward are not affected.
The flaw was introduced in commit 7385610d0c7, which was shipped enabled by default from commit d71ff2b9db566b3f in curl 7.77.0.
A version number like 7.77.0 identifies a particular release of the software, the way an edition number identifies a printing of a book. A commit is a saved change in the source code of a program, with an identifier made of letters and digits; it is the record of who changed what and when. "Shipped enabled by default" means the behaviour was turned on for everyone using that release, without anyone having to switch it on.
Finding it
The researcher noticed that curl's HSTS cache saving behaves wrongly when multiple URLs are requested in parallel. The HSTS cache file gets overwritten by the most recently completed transfer, so the saved state reflects only that last transfer rather than the combined state of all transfers. As a result, a later HTTP-only transfer to an earlier host name would not get upgraded properly to HSTS.
This looked wrong because the HSTS mechanism is supposed to persist the knowledge that a host uses HTTPS, so that a later plain HTTP request to that host is upgraded. With parallel transfers, that persistence fails for all but the last completed transfer.
To persist something is to make it survive after the current moment, like writing a note on paper rather than trying to remember it. The whole point of the HSTS cache file is persistence: curl learns once that a host uses HTTPS and writes it down, so a later run can act on it. If the note gets replaced by a shorter one, the earlier knowledge is gone.
Exploitation
The report gives a two-step reproduction. A reproduction is a set of exact steps that anyone can follow to see the problem for themselves.
Step 1: populate the HSTS cache with parallel transfers
curl --hsts hsts.txt --parallel https://curl.se https://example.com
Line by line:
curlis the program being run.--hsts hsts.txttells curl to use the file namedhsts.txtas its HSTS cache, both for reading what it already knows and for writing what it learns.--paralleltells curl to fetch the addresses that follow at the same time rather than one after another.https://curl.seandhttps://example.comare the two addresses to fetch, both over HTTPS.
This command requests two HTTPS URLs in parallel and writes the HSTS cache to hsts.txt. Because the transfers run in parallel, the cache file is overwritten by whichever transfer completes last. The HSTS state for the other host is lost.
Why this step: the goal is to teach curl that two hosts use HTTPS, then see whether both facts survive in the file. Running the transfers in parallel is the condition that triggers the bug.
Step 2: request the earlier host over plain HTTP
curl --hsts hsts.txt http://curl.se
Line by line:
curlis the program again.--hsts hsts.txtreuses the same cache file, so curl can consult what step 1 saved.http://curl.seis a plain, unencrypted request to the first host.
This command uses the same cache file and requests http://curl.se over plain HTTP. Because the HSTS entry for curl.se was not saved in step 1 (it was overwritten by the other transfer), curl does not upgrade the request to HTTPS. The request goes out over clear-text HTTP.
Why this step: it checks whether the knowledge from step 1 was kept. If the cache had held both hosts, curl would have quietly turned this into an HTTPS request. Because the entry was lost, it did not.
The report does not show the actual output of these commands; it states that the later HTTP-only transfer to the earlier host name would not get upgraded properly to HSTS.
Root cause
When multiple transfers run in parallel, each transfer saves the HSTS cache independently. The save operation writes the whole cache file, so the last transfer to finish overwrites the file with its own view of the HSTS state. The HSTS state is not shared properly between transfers, so entries learned by other transfers are lost.
A useful comparison is several people each keeping their own copy of a shared shopping list and each writing their full copy back to the same sheet of paper at the end. Whoever writes last decides what the list says, and everything the others added is gone. The correct behaviour would be one shared list that everyone adds to.
The fix in 7.88.0 shares the HSTS state properly between transfers, making each subsequent save store a complete state.
Impact
The report describes the impact as "Bypass intended security control" and states that the authors are not aware of any exploit of this flaw. The report describes the impact as "Bypass intended security control" and assigns CWE-319: Cleartext Transmission of Sensitive Information, with severity Low. The report states that the authors are not aware of any exploit of this flaw.
To bypass a security control means to get around a protection that was supposed to apply, the way someone slips past a locked front door through a side window. CWE-319 is a catalogue label for the class of problem where information travels unencrypted, so anyone positioned on the network can read it. Severity Low means the problem is real but limited in how much harm it can do.
The flaw is in the curl command line only and does not affect libcurl. It requires the use of --parallel with --hsts and a later HTTP request to a host whose HSTS entry was lost.
Fix
curl 7.88.0 shares the HSTS state properly between transfers, so that each subsequent save stores a complete state. The report also lists recommendations:
- Upgrade curl to version 7.88.0.
- Apply the patch to your local version.
- Specify all URLs with
HTTPS://and notHTTP://.
A patch is a small change to source code that repairs a specific problem, like a patch of cloth over a hole. Recommendation 3 is a workaround: if you always write https:// yourself, there is no plain HTTP request left for curl to fail to upgrade.
The report also mentions "A fix for CVE-2023-23914".
Variants to test
- Use
--parallelwith more than two URLs and check whether the HSTS cache file contains entries for all hosts after the command finishes. A positive result is that only the last completed transfer's host is present. - Use
--parallelwith a mix of hosts and then request each host overhttp://with the same cache file. A positive result is that at least one host is not upgraded to HTTPS. - Test with different orderings and timings of the parallel transfers to see whether the last completed transfer varies. A positive result is that the surviving cache entry changes with timing.
These variants are simply ways of checking the same idea from different angles: does the saved file hold everything, or only the last thing written?
Hunting notes
This kind of bug tends to hide in command-line tools that persist state to a file while performing concurrent operations. During recon, look for options that write shared state (cache files, configuration files, logs) and options that enable concurrency (parallel transfers, multiple threads). The signal is a mismatch between the expected persistent state and the state after a concurrent run.
Recon is the early stage of looking around a piece of software to understand what it does and where problems might live. Concurrent means happening at the same time. The signal here is simple: what you expect to be saved and what is actually saved after a parallel run do not match.
The report gives a two-step reproduction and states that the later HTTP-only transfer would not get upgraded properly to HSTS.
Glossary
- curl: a command-line program and library for transferring data with URLs.
- libcurl: the library form of curl, used by other programs; this flaw does not affect it.
- URL: a web address, such as
https://example.com. - Host: the part of a URL that names the machine, such as
curl.se. - HTTPS: the encrypted version of HTTP, where traffic cannot be read by others on the network path.
- HTTP: the unencrypted version of the protocol used to fetch web content.
- HSTS (HTTP Strict Transport Security): a mechanism that tells a tool to always use HTTPS for a host, even when
http://is written. - HSTS cache: the stored list of hosts that must be reached over HTTPS.
--hsts: the curl option that names the file used as the HSTS cache.--parallel: the curl option that fetches several URLs at the same time.- Option (flag): a word starting with
--added to a command to change its behaviour. - Cache: a stored copy of information kept for reuse later.
- Persist: to make something survive beyond the current moment, usually by writing it down.
- Commit: a saved change in a program's source code, identified by a code such as
7385610d0c7. - Version: a numbered release of a piece of software, such as 7.77.0.
- Reproduction: exact steps anyone can follow to observe a problem.
- Clear-text: data sent without encryption, readable by anyone on the network path.
- Bypass: to get around a protection that was supposed to apply.
- Security control: a protection meant to stop something bad from happening.
- CWE-319: a catalogue label for cleartext transmission of sensitive information.
- Severity: a rating of how much harm a problem can cause; here, Low.
- Patch: a small code change that repairs a specific problem.
- Workaround: a way to avoid a problem without fixing the underlying code.
- Recon: the early stage of exploring software to understand it and spot where problems might be.
- Concurrent: happening at the same time.
- Bounty: a payment made to a researcher who reports a valid security problem.