Skip to content
Business logic Disclosed report Intermediate CVE-2023-46218

CVE-2023-46218: cookie mixed case PSL bypass

libcurl did not normalise the hostname and cookie domain before checking them against the Public Suffix List, so a mixed-case domain such as a .co.uk host slipped past the check. An attacker could then set a cookie that curl would send to every other host under that public suffix.

nyymi Follow

Originally disclosed on HackerOne

  • Triaged in 12 hours
  • Fixed in 51 days
  • Disclosed after 51 days

Summary:

libcurl fails to normalize the hostname and cookie_domain parameters passed to psl_is_cookie_domain_acceptable function. As a result a malicious site can set a super cookie if the victim requests the url with hostname with any upper case characters in the domain part of the hostname.

libpsl psl_is_cookie_domain_acceptable documentation https://rockdaboot.github.io/libpsl/libpsl-Public-Suffix-List-functions.html#psl-is-cookie-domain-acceptable says the following:

Use helper function psl_str_to_utf8lower() for normalization of hostname and cookie_domain .

This is not done correctly and hence domains with uppercase characters will bypass the PSL check. Note that curl itself will later ignore the cookie domain capitalization and will match even lowercase hostname with the stored supercookie's mixed case domain.

It's also worth noting that the request Host header will reveal the mixed case used, which will allow the attacker to prepare the correct Set-Cookie domain for the attack.

Steps To Reproduce:

  1. echo -ne "HTTP/1.1 200 OK\r\nSet-Cookie: super=oops; domain=co.UK\r\nContent-Length: 0\r\n" | nc -v -l -q 1 -p 8888
  2. curl -v -c c.txt --resolve test.co.uk:8888:testserverip http://test.co.UK:8888
  3. nc -v -l -p 7777
  4. curl -v -b c.txt --resolve other.co.uk:7777:testserverip http://other.co.uk:7777

Note that the super cookie is sent to the other.com.uk site. In fact it will be sent to any .co.uk hosts now.

The generated cookie file:

# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

.co.UK	TRUE	/	FALSE	0	super	oops

Impact

Bypassing supercookie protection.

The original report as published on HackerOne, by nyymi. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Context

curl is a command line tool and libcurl is the library underneath it. Among other things, libcurl implements an HTTP cookie engine: it parses Set-Cookie headers, stores cookies in a cookie jar, and later decides which stored cookies to send with a request to a given host. Part of that decision is the Public Suffix List (PSL) check, which is meant to stop a site from setting a cookie for a domain it does not own, such as a whole public suffix like co.uk.

The check is delegated to libpsl, through the function psl_is_cookie_domain_acceptable. The report is about libcurl failing to normalise the hostname and cookie_domain arguments it passes to that function, which lets a malicious site set a super cookie when the victim requests a URL whose hostname contains upper case characters in the domain part.

Setup

The researcher works locally, with no accounts or special roles. The setup is a loopback HTTP server that returns a Set-Cookie header, a curl binary linked against libcurl and libpsl, and a second listener to observe which cookies curl sends to a different host. The report does not give curl or libpsl version numbers. The hostnames test.co.uk and other.co.uk are resolved to a test server address with --resolve, so no DNS changes are needed.

Finding it

The starting point is the libpsl documentation for psl_is_cookie_domain_acceptable, which states:

Text
Use helper function psl_str_to_utf8lower() for normalization of hostname and cookie_domain .

libcurl does not do this correctly, so a domain containing upper case characters bypasses the PSL check. Two further details make the bug exploitable rather than theoretical:

  • curl itself later ignores the capitalisation of the cookie domain when matching, so a stored super cookie with a mixed case domain is still matched against a lowercase hostname.
  • the request Host header reveals the mixed case the client used, which lets the attacker prepare the correct Set-Cookie domain for the attack.

Exploitation

Step 1: serve a cookie for a mixed case public suffix

Bash
echo -ne "HTTP/1.1 200 OK\r\nSet-Cookie: super=oops; domain=co.UK\r\nContent-Length: 0\r\n" | nc -v -l -q 1 -p 8888

This starts a one-shot listener on port 8888 that answers any request with a 200 OK, an empty body and a Set-Cookie header setting super=oops for domain=co.UK. The domain is a public suffix (co.uk) written with upper case letters, which is exactly the form the PSL check fails to normalise.

Step 2: make curl fetch the site with a mixed case hostname

Bash
curl -v -c c.txt --resolve test.co.uk:8888:testserverip http://test.co.UK:8888

--resolve maps test.co.uk to the test server address for port 8888, -c c.txt writes the cookie jar to c.txt, and the URL uses test.co.UK, with upper case UK in the domain part. Because the hostname is mixed case, the PSL check on the incoming cookie domain is bypassed and the cookie is accepted and stored.

The resulting cookie file shows the stored domain in its mixed case form:

Text
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

.co.UK	TRUE	/	FALSE	0	super	oops

Step 3: start a listener for a different site

Bash
nc -v -l -p 7777

This listener stands in for an unrelated site under the same public suffix.

Step 4: request the other site with the stored cookie jar

Bash
curl -v -b c.txt --resolve other.co.uk:7777:testserverip http://other.co.uk:7777

-b c.txt loads the cookie jar written in step 2, and the request goes to other.co.uk, a different host from the one that set the cookie. The super cookie is sent to that site. In fact, as the researcher notes, it will now be sent to any .co.uk host.

Root cause

libcurl passes the hostname and cookie_domain to psl_is_cookie_domain_acceptable without normalising them, although libpsl's documentation requires psl_str_to_utf8lower() for both. A domain with upper case characters therefore does not match the public suffix entry as expected and the PSL check is bypassed. The defence fails because the arguments are not normalised before the check, and because curl's own cookie matching later treats the stored mixed case domain as matching a lowercase hostname, so the wrongly accepted cookie is actually used. and because curl's own cookie matching later treats the stored mixed case domain as matching a lowercase hostname, so the wrongly accepted cookie is actually used.

Impact

Bypassing super cookie protection. A malicious site can set a cookie for a public suffix, and that cookie is then sent to other hosts under the same suffix. The attack requires that the victim requests the URL with a hostname containing upper case characters in the domain part; the Host header reveals that capitalisation to the attacker, who can then craft the matching Set-Cookie domain. The report describes the impact only in these terms and does not go further.

Fix

The report does not describe a fix.

Variants to test

  • A positive result is a cookie jar entry for the suffix that is later sent to an unrelated host under it.
  • A positive result is the same cross-host cookie delivery.

Hunting notes

Timeline

The report was disclosed on 6 December 2023 and is tracked as CVE-2023-46218, with medium severity.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

curl is a small program you run in a terminal to fetch things from the internet. Underneath it sits a library called libcurl, which does the actual talking to web servers. One of the jobs libcurl does is handle cookies.

A cookie is a small piece of text that a website asks your browser (or curl) to keep and send back on later visits. It is how a site remembers you are logged in, for example. Cookies are tied to a domain, so a cookie set by example.com should only go back to example.com.

There is a rule that stops a site from setting a cookie for a whole public suffix. A public suffix is the part of a domain name that is shared by many unrelated sites, like co.uk or com. If any single site could set a cookie for co.uk, that cookie would be sent to every other .co.uk site, which is why such a cookie is called a super cookie. The Public Suffix List (PSL) is the list of these shared endings, and libcurl asks a helper library called libpsl to check whether a cookie's domain is allowed.

The bug: libcurl hands the hostname and the cookie domain to that check without first making the letters consistent. Computers treat an upper case A and a lower case a as different characters. So a domain written as co.UK does not match the list entry co.uk, the check is fooled, and the cookie is accepted. Later, when curl decides which cookies to send, it ignores the capitalisation, so the wrongly accepted cookie really is sent to other sites under the same suffix.

Context

curl is a command line tool, and libcurl is the library underneath it. Among other things, libcurl implements an HTTP cookie engine: it reads Set-Cookie headers from responses, stores cookies in a cookie jar (a file on disk), and later decides which stored cookies to send with a request to a given host. Part of that decision is the Public Suffix List (PSL) check, which is meant to stop a site from setting a cookie for a domain it does not own, such as a whole public suffix like co.uk.

The check is delegated to libpsl, through the function psl_is_cookie_domain_acceptable. The report is about libcurl failing to normalise the hostname and cookie_domain arguments it passes to that function. Normalising here means converting both strings to one consistent form, in this case lower case, before comparing them. Because that is not done, a malicious site can set a super cookie when the victim requests a URL whose hostname contains upper case characters in the domain part.

Setup

The researcher works locally, with no accounts or special roles. The setup is a loopback HTTP server that returns a Set-Cookie header, a curl binary linked against libcurl and libpsl, and a second listener to observe which cookies curl sends to a different host. The report does not give curl or libpsl version numbers. The hostnames test.co.uk and other.co.uk are resolved to a test server address with --resolve, so no DNS changes are needed. DNS is the system that turns a name like test.co.uk into the address of a machine; --resolve lets you supply that answer yourself for one request.

Finding it

The starting point is the libpsl documentation for psl_is_cookie_domain_acceptable, which states:

Text
Use helper function psl_str_to_utf8lower() for normalization of hostname and cookie_domain .

In plain words: the library that performs the check tells callers to run a helper, psl_str_to_utf8lower(), on both the hostname and the cookie domain first. That helper turns the text into a single standard lower case form. libcurl does not do this correctly, so a domain containing upper case characters bypasses the PSL check.

Two further details make the bug exploitable rather than theoretical:

  • curl itself later ignores the capitalisation of the cookie domain when matching, so a stored super cookie with a mixed case domain is still matched against a lowercase hostname.
  • the request Host header reveals the mixed case the client used, which lets the attacker prepare the correct Set-Cookie domain for the attack. The Host header is the line in an HTTP request that tells the server which site name the client asked for.

Exploitation

Step 1: serve a cookie for a mixed case public suffix

Bash
echo -ne "HTTP/1.1 200 OK\r\nSet-Cookie: super=oops; domain=co.UK\r\nContent-Length: 0\r\n" | nc -v -l -q 1 -p 8888

Line by line:

  • echo -ne prints a piece of text without adding a newline at the end. The -n means no trailing newline, and -e means interpret the escape sequences such as \r\n.
  • The text is a raw HTTP response: a status line HTTP/1.1 200 OK, then a Set-Cookie header setting a cookie named super with value oops for domain=co.UK, then Content-Length: 0 saying the body is empty. \r\n is the carriage return plus line feed pair that HTTP uses to end each line.
  • The | pipe sends that text into the next command.
  • nc -v -l -q 1 -p 8888 is netcat, a simple tool that can listen on a network port. -l means listen, -p 8888 picks port 8888, -v prints extra detail, and -q 1 makes it quit one second after the input ends.

Why this step: it starts a one-shot listener on port 8888 that answers any request with a 200 OK, an empty body and a Set-Cookie header setting super=oops for domain=co.UK. The domain is a public suffix (co.uk) written with upper case letters, which is exactly the form the PSL check fails to normalise.

Step 2: make curl fetch the site with a mixed case hostname

Bash
curl -v -c c.txt --resolve test.co.uk:8888:testserverip http://test.co.UK:8888

Line by line:

  • curl is the program making the request.
  • -v means verbose: curl prints the request and response details so you can see what happened.
  • -c c.txt tells curl to write the cookies it receives into a file called c.txt, the cookie jar.
  • --resolve test.co.uk:8888:testserverip tells curl to connect to the address testserverip whenever it wants test.co.uk on port 8888, skipping normal DNS lookup.
  • http://test.co.UK:8888 is the URL being fetched, with upper case UK in the domain part.

Why this step: --resolve maps test.co.uk to the test server address for port 8888, -c c.txt writes the cookie jar to c.txt, and the URL uses test.co.UK, with upper case UK in the domain part. Because the hostname is mixed case, the PSL check on the incoming cookie domain is bypassed and the cookie is accepted and stored.

The resulting cookie file shows the stored domain in its mixed case form:

Text
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

.co.UK	TRUE	/	FALSE	0	super	oops

Line by line: the first three lines are comments written by curl. The last line is the cookie itself, with fields separated by tab characters. .co.UK is the domain the cookie belongs to, with a leading dot meaning it applies to subdomains too. TRUE means the cookie applies to subdomains. / is the path it applies to. FALSE means it is not restricted to secure (HTTPS) connections. 0 is the expiry, meaning a session cookie. super is the cookie name and oops is its value.

Step 3: start a listener for a different site

Bash
nc -v -l -p 7777

Line by line: nc is netcat again, -v prints detail, -l means listen, and -p 7777 picks port 7777. This listener stands in for an unrelated site under the same public suffix. It is there so you can see, from the other side, whether curl sends the stored cookie to a host that never set it.

Step 4: request the other site with the stored cookie jar

Bash
curl -v -b c.txt --resolve other.co.uk:7777:testserverip http://other.co.uk:7777

Line by line:

  • curl -v again makes a verbose request.
  • -b c.txt loads the cookie jar written in step 2, so curl can send cookies from it.
  • --resolve other.co.uk:7777:testserverip points other.co.uk on port 7777 at the test server address.
  • http://other.co.uk:7777 is the URL, a different host from the one that set the cookie.

Why this step: -b c.txt loads the cookie jar written in step 2, and the request goes to other.co.uk, a different host from the one that set the cookie. The super cookie is sent to that site. In fact, as the researcher notes, it will now be sent to any .co.uk host. That is the proof: a cookie meant for one site is delivered to an unrelated one.

Root cause

libcurl passes the hostname and cookie_domain to psl_is_cookie_domain_acceptable without normalising them, although libpsl's documentation requires psl_str_to_utf8lower() for both. A domain with upper case characters therefore does not match the public suffix entry as expected and the PSL check is bypassed. The defence fails because the arguments are not normalised before the check, and because curl's own cookie matching later treats the stored mixed case domain as matching a lowercase hostname, so the wrongly accepted cookie is actually used. and because curl's own cookie matching later treats the stored mixed case domain as matching a lowercase hostname, so the wrongly accepted cookie is actually used.

Impact

Bypassing super cookie protection. A malicious site can set a cookie for a public suffix, and that cookie is then sent to other hosts under the same suffix. The attack requires that the victim requests the URL with a hostname containing upper case characters in the domain part; the Host header reveals that capitalisation to the attacker, who can then craft the matching Set-Cookie domain. The report describes the impact only in these terms and does not go further.

Fix

The report does not describe a fix.

Variants to test

  • A positive result is a cookie jar entry for the suffix that is later sent to an unrelated host under it.
  • A positive result is the same cross-host cookie delivery.

Hunting notes

An API, in this sense, is the set of functions one piece of software offers to another, together with the rules for using them.

Timeline

The report was disclosed on 6 December 2023 and is tracked as CVE-2023-46218, with medium severity. A CVE is a public identifier given to a known security flaw so people can refer to it unambiguously.

Glossary

  • curl: a command line program for transferring data to and from servers, commonly used to fetch web pages.
  • libcurl: the library underneath curl that performs the network communication and protocol handling.
  • Cookie: a small piece of text a site asks a client to store and send back on later requests, often used to keep you logged in.
  • Cookie jar: a file where curl stores cookies it has received.
  • Cookie engine: the part of libcurl that reads, stores and sends cookies.
  • Set-Cookie: the response header a server uses to ask the client to store a cookie.
  • Host header: the line in an HTTP request that names the site the client is asking for.
  • Domain: the part of a web address that identifies the site, such as example.com.
  • Public suffix: the shared ending of a domain name, such as com or co.uk, that many unrelated sites sit under.
  • Public Suffix List (PSL): the maintained list of public suffixes used to decide whether a cookie domain is allowed.
  • Super cookie: a cookie set for a public suffix, which is then sent to many unrelated sites under that suffix.
  • libpsl: a library that implements the Public Suffix List check.
  • psl_is_cookie_domain_acceptable: the libpsl function that decides whether a cookie domain is acceptable for a hostname.
  • psl_str_to_utf8lower(): the libpsl helper that converts text to a standard lower case form.
  • Normalisation: converting text to one consistent form, such as all lower case, before comparing it.
  • Case-sensitive: treating upper case and lower case letters as different characters.
  • Bypass: getting past a security check without satisfying it.
  • HTTP: the protocol browsers and servers use to exchange web pages and headers.
  • Header: a line of metadata in an HTTP request or response, such as Set-Cookie or Host.
  • Port: a numbered channel on a machine that a network service listens on.
  • Loopback: network traffic that stays on the local machine.
  • DNS: the system that turns a domain name into the address of a machine.
  • --resolve: a curl option that supplies a name to address mapping for one request instead of using DNS.
  • netcat (nc): a simple tool for reading and writing data over network connections, including listening on a port.
  • API: the set of functions one piece of software offers to another, with the rules for using them.
  • CVE: a public identifier for a known security flaw.
  • Severity: a rating of how serious a flaw is; here, medium.

More by nyymi

View all

51 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.