curl’s persistence files inherit world-readable/writable perms from umask, leaking and tampering with cookies/HSTS/Alt-Svc caches
curl's persistence files (cookies, HSTS, Alt-Svc) are created with world-readable permissions inherited from the process umask, so any local user can read them. An attacker on the same host could read session cookies and other sensitive data, or tamper with the files.
- Disclosed after 27 hours
Executive Summary
Curl_fopen() clones the permissions of any pre-existing persistence file when creating its temporary file. When the persistence file does not exist, it first creates one with the process umask (typically 022, i.e., 0644). That mode is then copied to the temp file via 0600 | sb.st_mode, so the final cookie/HSTS/Alt-Svc store ends up group/other-readable even though it contains bearer tokens. (lib/curl_fopen.c:101-150)
All stateful persistence features that rely on Curl_fopen()—cookie_output(), Curl_hsts_save(), and Curl_altsvc_save()—inherit this behavior, leaking session cookies, HSTS cache entries, and Alt-Svc metadata to any local user.
Steps To Reproduce
Environment: macOS 26.1 Dev Beta 4, commit a49e4e3d16991465144558f405b2d7972824abb0, built with ./configure --disable-shared --with-openssl=/opt/homebrew/opt/openssl@3 --without-libpsl && make -j8.
- Ensure no leftover file and simulate a normal multi-user umask:
rm -f /tmp/cookie-leak.txt && umask 022 \
&& ./src/curl -s -o /dev/null -c /tmp/cookie-leak.txt https://example.org \
&& ls -l /tmp/cookie-leak.txt
.rw-r--r-- 131 geeknik 26 Oct 22:22 /tmp/cookie-leak.txt

The cookie jar is created even though no cookies were set, which is enough to demonstrate the default mode of 0644.
- As another local user simply
cat /tmp/cookie-leak.txt, read the file contents—full session cookies would be exposed in real traffic. The same reproduction works for--hstsand--alt-svcfiles because they callCurl_fopen()with identical code paths.
Additionally, we were able to reproduce this behavior on Fedora with curl 8.6.0 (x86_64-redhat-linux-gnu).
CVSS v3.0
AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N
Suggested Fix
Replace lines 140-141 with:
fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, 0600);
Impact
Any local user on the same host (shared CI runners, university shells, managed desktops, etc.) can read authentication cookies, session tokens, CSRF nonces, HSTS preload data, or Alt-Svc targets written by another user’s curl/libcurl client. Immediate consequences range from full account takeover (cookie replay) to bypassing HSTS (by rewriting the file before the victim reads it) and intelligence gathering on internal endpoints listed in Alt-Svc caches. Because the files are written automatically whenever CURLOPT_COOKIEJAR, CURLOPT_HSTSWRITEFUNCTION, or CURLOPT_ALTSVC are used, even well-configured automation unintentionally leaks secrets to co-resident users.
Context
curl is a command-line tool and library that, among many other things, can persist state between runs. Three features write files to disk:
- the cookie jar (
-c/CURLOPT_COOKIEJAR), which stores cookies received during a session; - the HSTS cache (
--hsts/CURLOPT_HSTSWRITEFUNCTION), which records hosts that must only be contacted over HTTPS; - the Alt-Svc cache (
--alt-svc/CURLOPT_ALTSVC), which records alternative service endpoints advertised by servers.
All three go through the same helper, Curl_fopen(), in lib/curl_fopen.c. The report focuses on that helper: the permissions of the files it produces, and what those permissions expose to other users on the same machine.
Setup
The researcher reproduced the issue on macOS with the following environment:
macOS 26.1 Dev Beta 4- commit
[redacted] - built with:
./configure --disable-shared --with-openssl=/opt/homebrew/opt/openssl@3 --without-libpsl && make -j8
The behaviour was additionally reproduced on Fedora with curl 8.6.0 (x86_64-redhat-linux-gnu).
The precondition is a multi-user host where another local account can read files created by the victim's process. The default umask on such systems is typically 022, which is the value the reproduction simulates.
Finding it
Curl_fopen() clones the permissions of any pre-existing persistence file when it creates its temporary file. When the persistence file does not exist yet, curl first creates one using the process umask, typically 022, giving mode 0644. That mode is then copied to the temporary file through 0600 | sb.st_mode, so the final cookie, HSTS or Alt-Svc store ends up group- and other-readable even though it holds bearer tokens.
The relevant code is in lib/curl_fopen.c:101-150. Because cookie_output(), Curl_hsts_save() and Curl_altsvc_save() all rely on Curl_fopen(), they all inherit the behaviour: session cookies, HSTS cache entries and Alt-Svc metadata are exposed to any local user.
Exploitation
Step 1: create a cookie jar under a normal umask
The researcher removed any leftover file and simulated a normal multi-user umask before running curl against https://example.org with a cookie jar path:
rm -f /tmp/cookie-leak.txt && umask 022 \
&& ./src/curl -s -o /dev/null -c /tmp/cookie-leak.txt https://example.org \
&& ls -l /tmp/cookie-leak.txt
The rm -f guarantees the persistence file does not exist beforehand, so curl takes the path where it creates the file itself with the process umask. The umask 022 sets that umask explicitly. The -s -o /dev/null discards the response body, and -c /tmp/cookie-leak.txt asks curl to write the cookie jar to that path. The final ls -l shows the resulting permissions.
The output was:
.rw-r--r-- 131 geeknik 26 Oct 22:22 /tmp/cookie-leak.txt

The listing shows the file is group- and other-readable (r-- for both). The cookie jar is created even though no cookies were set, which is enough to demonstrate the default mode of 0644.
Step 2: read the file as another local user
As another local user, a simple cat /tmp/cookie-leak.txt reads the file contents. In real traffic, full session cookies would be exposed this way. The same reproduction works for --hsts and --alt-svc files, because they call Curl_fopen() through identical code paths.
Root cause
The temporary file is created with a mode derived from the existing persistence file's mode: 0600 | sb.st_mode. When the persistence file does not exist, curl first creates it with the process umask, which is typically 022 and therefore yields 0644. That 0644 is then carried into the temporary file, and the final store keeps the group- and other-readable bits.
The suggested fix replaces lines 140-141 with a creation call that forces 0600 and uses O_EXCL:
fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, 0600);
The report proposes this change so the temporary file is created with mode 0600 and O_EXCL.
Impact
Any local user on the same host can read authentication cookies, session tokens, CSRF nonces, HSTS preload data or Alt-Svc targets written by another user's curl/libcurl client. The report lists shared CI runners, university shells and managed desktops as examples of such hosts.
Consequences range from full account takeover through cookie replay, to bypassing HSTS by rewriting the file before the victim reads it, to intelligence gathering on internal endpoints listed in Alt-Svc caches. Because the files are written automatically whenever CURLOPT_COOKIEJAR, CURLOPT_HSTSWRITEFUNCTION or CURLOPT_ALTSVC are used, even well-configured automation leaks secrets to co-resident users without any deliberate action.
The report's CVSS v3.0 vector is:
AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N
That is a local attack requiring low privileges, with high confidentiality impact and no integrity or availability impact. The platform records the severity as medium.
Fix
The report proposes replacing lines 140-141 of lib/curl_fopen.c with the curlx_open() call shown above, so the temporary file is always created with mode 0600 and O_EXCL. The report does not describe a patch that was applied; it only gives this suggested change.
Variants to test
- Run curl with
--hstsand--alt-svcunderumask 022on a multi-user host and inspect the resulting files. A positive result is a cache file that is group- or other-readable. - Pre-create the persistence file with permissive permissions and let curl rewrite it. A positive result is that the rewritten file keeps the permissive mode, since the temporary file inherits it.
- Check other tools and libraries that write cookie jars, HSTS stores or similar state files through a temporary file and a rename. A positive result is a final file readable by users other than the owner.
Hunting notes
This class of bug hides in code that creates temporary files and then renames them over a persistence path. The signal is a mode derived from an existing file's st_mode or from the process umask rather than a fixed 0600. On a shared host, any state file that contains credentials and is group- or other-readable is worth reporting.
The researcher demonstrated the issue with a minimal, reproducible command sequence: a fresh file, an explicit umask 022, and an ls -l showing the resulting mode. Showing that the file is created even when no cookies are set isolates the permission behaviour from the content, and the behaviour was also reproduced on Fedora with curl 8.6.0.
What happened, in plain words
curl is a small program that runs in a terminal and fetches things from the internet. Many people also use it inside other software, where it is called libcurl. It can remember things between runs by writing them into files on your computer. This report is about those files, and about who is allowed to read them.
On a computer that several people share, files have permissions: little rules saying whether the owner, the owner's group, or everyone else can read or change them. curl was creating its memory files in a way that let every other user on the same machine read them. Those files can contain cookies, which are the little passes a website gives your browser so it knows you are logged in. If someone else can read your cookie file, they can often pretend to be you.
The researcher showed this with a few terminal commands, and suggested a change to the code that creates the files. The platform records the severity as medium.
Context
curl is a command-line tool and library that, among many other things, can persist state between runs. "Persist state" means remembering something after the program has finished, by saving it to disk. Three features write files to disk:
- the cookie jar (
-c/CURLOPT_COOKIEJAR), which stores cookies received during a session; - the HSTS cache (
--hsts/CURLOPT_HSTSWRITEFUNCTION), which records hosts that must only be contacted over HTTPS; - the Alt-Svc cache (
--alt-svc/CURLOPT_ALTSVC), which records alternative service endpoints advertised by servers.
A cookie is a small piece of text a website asks your browser to keep and send back on later requests. It is how a site remembers that you logged in, so it works like a wristband at an event: show it at the door and you get back in without proving who you are again. A cookie jar is simply a file where curl saves those wristbands so a later curl run can reuse them.
HSTS (HTTP Strict Transport Security) is a rule a website can send saying "always talk to me over the encrypted HTTPS connection, never the plain one". A browser or curl keeps a list of sites that made this promise, and that list is the HSTS cache. It protects you from being silently downgraded to an unencrypted connection.
*curl stores those advertisements in the Alt-Svc cache so it can try them next time.
All three go through the same helper, Curl_fopen(), in lib/curl_fopen.c. A helper here means a small internal function that other parts of the program call to do a common job, in this case opening a file for writing. The report focuses on that helper: the permissions of the files it produces, and what those permissions expose to other users on the same machine.
Setup
The researcher reproduced the issue on macOS with the following environment:
macOS 26.1 Dev Beta 4- commit
[redacted] - built with:
./configure --disable-shared --with-openssl=/opt/homebrew/opt/openssl@3 --without-libpsl && make -j8
This block is how the researcher compiled curl from its source code rather than using a pre-built copy. ./configure is a setup script that checks the machine and prepares the build; the options after it choose how curl should be built. --disable-shared asks for a self-contained program instead of a shared library. --with-openssl=/opt/homebrew/opt/openssl@3 points the build at a particular installation of OpenSSL, the library that handles encrypted connections. --without-libpsl turns off an optional component called libpsl. && means "and then, only if the previous step succeeded". make -j8 runs the actual compilation, using up to eight parallel jobs to go faster. A commit is one saved change in a code repository, identified by a long string of letters and numbers; the one above pins down the exact version of the code that was tested.
The behaviour was additionally reproduced on Fedora with curl 8.6.0 (x86_64-redhat-linux-gnu). Fedora is a different operating system from macOS, so finding the same result there shows the problem is not a quirk of one machine.
The precondition is a multi-user host where another local account can read files created by the victim's process. A multi-user host is one computer used by several people at once, each with their own login. The default umask on such systems is typically 022, which is the value the reproduction simulates.
A umask is a setting that decides which permissions new files get by default. Think of it as a stencil laid over the full set of permissions: the bits set in the umask are removed. The value 022 removes write permission for the group and for everyone else, leaving new files readable by the owner, the group and everyone else. In the numeric notation used for permissions, that default is written 0644.
Finding it
Curl_fopen() clones the permissions of any pre-existing persistence file when it creates its temporary file. When the persistence file does not exist yet, curl first creates one using the process umask, typically 022, giving mode 0644. That mode is then copied to the temporary file through 0600 | sb.st_mode, so the final cookie, HSTS or Alt-Svc store ends up group- and other-readable even though it holds bearer tokens.
A temporary file is a scratch file a program writes first and then renames over the real file, so that a crash halfway through does not leave a half-written file behind. sb.st_mode is the part of a file's stored information that records its permissions. The vertical bar | is a bitwise OR: it combines two permission values bit by bit. 0600 means "owner can read and write, nobody else can do anything". Combining it with the existing file's mode means the result is at least as open as the existing file, and never narrower.
A bearer token is a secret that grants access to whoever holds it, with no further proof of identity, like a coat-check ticket: whoever has the ticket gets the coat. Session cookies are bearer tokens, which is why their file permissions matter.
The relevant code is in lib/curl_fopen.c:101-150. The notation means lines 101 to 150 of that file. Because cookie_output(), Curl_hsts_save() and Curl_altsvc_save() all rely on Curl_fopen(), they all inherit the behaviour: session cookies, HSTS cache entries and Alt-Svc metadata are exposed to any local user.
Exploitation
Step 1: create a cookie jar under a normal umask
The researcher removed any leftover file and simulated a normal multi-user umask before running curl against https://example.org with a cookie jar path:
rm -f /tmp/cookie-leak.txt && umask 022 \
&& ./src/curl -s -o /dev/null -c /tmp/cookie-leak.txt https://example.org \
&& ls -l /tmp/cookie-leak.txt
Line by line:
rm -f /tmp/cookie-leak.txtdeletes the file if it exists, and does nothing if it does not. The-fmeans "force, do not complain about a missing file". This matters because the bug only shows up on the path where the file does not exist beforehand; a leftover file would send curl down a different route.umask 022sets the default permission stencil for anything created in this terminal session, reproducing what a typical shared machine uses../src/curl -s -o /dev/null -c /tmp/cookie-leak.txt https://example.orgruns the freshly built curl.-ssilences progress output,-o /dev/nullthrows away the downloaded page (sending it to a special device that discards everything),-c /tmp/cookie-leak.txtasks curl to save its cookie jar at that path, andhttps://example.orgis the site being fetched.ls -l /tmp/cookie-leak.txtlists the file with its permissions so they can be inspected.- The backslashes at the end of lines join the commands into one sequence, and
&&means each step runs only if the previous one succeeded.
The output was:
.rw-r--r-- 131 geeknik 26 Oct 22:22 /tmp/cookie-leak.txt
This is a directory listing of one file. The leading . marks it as a regular file. The next nine characters are the permissions in three groups of three: rw- for the owner (read and write), r-- for the group (read only), and r-- for everyone else (read only). 131 is the file size in bytes, followed by the owner name, the date and time, and the path.

The listing shows the file is group- and other-readable (r-- for both). The cookie jar is created even though no cookies were set, which is enough to demonstrate the default mode of 0644.
Step 2: read the file as another local user
As another local user, a simple cat /tmp/cookie-leak.txt reads the file contents. cat is a basic command that prints a file's contents to the screen. In real traffic, full session cookies would be exposed this way. The same reproduction works for --hsts and --alt-svc files, because they call Curl_fopen() through identical code paths.
Root cause
The temporary file is created with a mode derived from the existing persistence file's mode: 0600 | sb.st_mode. When the persistence file does not exist, curl first creates it with the process umask, which is typically 022 and therefore yields 0644. That 0644 is then carried into the temporary file, and the final store keeps the group- and other-readable bits.
In everyday terms: curl looks at the old file to decide how open the new one should be. If there is no old file, it makes one using the machine's default, which on shared systems is open to everyone. Then it copies that openness onto the scratch file, and the scratch file becomes the real one. The safe value 0600 is combined with the open value, and the combination stays open.
The suggested fix replaces lines 140-141 with a creation call that forces 0600 and uses O_EXCL:
fd = curlx_open(tempstore, O_WRONLY | O_CREAT | O_EXCL, 0600);
This is C code. fd is the handle the program gets back for the opened file. curlx_open is curl's internal wrapper around the operating system's file-opening call. tempstore is the path of the temporary file. O_WRONLY means open for writing only. O_CREAT means create the file if it does not exist. O_EXCL means fail if the file already exists, which prevents an attacker from planting a file in advance and having curl write into it. The final 0600 is the permission the file must have: owner read and write, nobody else anything.
The report proposes this change so the temporary file is created with mode 0600 and O_EXCL.
Impact
Any local user on the same host can read authentication cookies, session tokens, CSRF nonces, HSTS preload data or Alt-Svc targets written by another user's curl/libcurl client. A CSRF nonce is a random value a website puts in a form to prove the request really came from its own pages, which stops another site from silently submitting actions on your behalf. The report lists shared CI runners, university shells and managed desktops as examples of such hosts. A CI runner is a machine that automatically builds and tests software, often shared by many projects and people; a shell is a terminal session on a machine, and a university shell is a shared login server students use.
Consequences range from full account takeover through cookie replay, to bypassing HSTS by rewriting the file before the victim reads it, to intelligence gathering on internal endpoints listed in Alt-Svc caches. Cookie replay means taking a stolen cookie and using it to act as the victim. Account takeover means getting into someone else's account. Bypassing HSTS means defeating the protection that forces encrypted connections, here by tampering with the file that records which sites require it. Intelligence gathering means quietly learning about a system, for example which internal addresses exist, from the Alt-Svc cache. Because the files are written automatically whenever CURLOPT_COOKIEJAR, CURLOPT_HSTSWRITEFUNCTION or CURLOPT_ALTSVC are used, even well-configured automation leaks secrets to co-resident users without any deliberate action. Those three names are the settings a program passes to libcurl to turn on the cookie jar, the HSTS writer and the Alt-Svc cache.
The report's CVSS v3.0 vector is:
AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:N/A:N
CVSS is a standard scoring system for rating how serious a security flaw is. Each short code describes one aspect. AV:L means the attacker must be local, on the same machine. AC:L means the attack is easy to carry out. PR:L means the attacker needs only low privileges, such as an ordinary user account. UI:N means no action from the victim is required. S:U means the impact stays within the affected component. C:H means high impact on confidentiality, meaning secrets can be read. I:N and A:N mean no impact on integrity (data cannot be changed) and no impact on availability (the service keeps working).
Fix
The report proposes replacing lines 140-141 of lib/curl_fopen.c with the curlx_open() call shown above, so the temporary file is always created with mode 0600 and O_EXCL. The report does not describe a patch that was applied; it only gives this suggested change.
Variants to test
- Run curl with
--hstsand--alt-svcunderumask 022on a multi-user host and inspect the resulting files. A positive result is a cache file that is group- or other-readable. - Pre-create the persistence file with permissive permissions and let curl rewrite it. A positive result is that the rewritten file keeps the permissive mode, since the temporary file inherits it.
- Check other tools and libraries that write cookie jars, HSTS stores or similar state files through a temporary file and a rename. A positive result is a final file readable by users other than the owner.
Hunting notes
This class of bug hides in code that creates temporary files and then renames them over a persistence path. The signal is a mode derived from an existing file's st_mode or from the process umask rather than a fixed 0600. On a shared host, any state file that contains credentials and is group- or other-readable is worth reporting.
The researcher demonstrated the issue with a minimal, reproducible command sequence: a fresh file, an explicit umask 022, and an ls -l showing the resulting mode. Showing that the file is created even when no cookies are set isolates the permission behaviour from the content, and the behaviour was also reproduced on Fedora with curl 8.6.0.
Glossary
- curl: a command-line program and library for transferring data over the internet.
- libcurl: the library form of curl, used inside other programs.
- Persistence: saving data to disk so it survives after the program exits.
- Cookie: a small piece of text a website asks a client to store and send back later, often used to keep you logged in.
- Cookie jar: a file where curl saves cookies for reuse.
- HSTS: a rule that a site must only be contacted over encrypted HTTPS; the HSTS cache is the stored list of such sites.
- Alt-Svc: a way for a server to advertise alternative addresses or protocols; the Alt-Svc cache stores those advertisements.
- Helper function: a small internal function other code calls to do a common job.
- Permissions: rules saying who may read, write or execute a file.
- umask: a setting that removes permission bits from newly created files, deciding their default openness.
- Mode /
0644/0600: numeric notation for file permissions;0644is readable by everyone,0600only by the owner. st_mode: the stored field that records a file's permissions.- Bitwise OR (
|): an operation that combines two values bit by bit. - Temporary file: a scratch file written first and then renamed over the real file.
- Bearer token: a secret that grants access to whoever holds it, with no other proof of identity.
- Session cookie: a cookie that represents a logged-in session.
- CSRF nonce: a random value in a form that proves the request came from the site's own pages.
- Commit: one saved change in a code repository, identified by a long hash.
- Multi-user host: one computer used by several people, each with their own login.
- CI runner: a shared machine that automatically builds and tests software.
- Shell: a terminal session on a machine.
- Cookie replay: using a stolen cookie to act as the victim.
- Account takeover: gaining control of someone else's account.
- CVSS: a standard scoring system for rating the severity of security flaws.
O_WRONLY,O_CREAT,O_EXCL: flags for opening a file: write only, create if missing, and fail if it already exists.cat: a command that prints a file's contents.ls -l: a command that lists files with their permissions.