Skip to content
Info disclosure Disclosed report Advanced

Curl_compareheader() fails to match multi-value HTTP headers

A loop condition in curl's header comparison function only checks the first byte of a header value, so a server sending 'Connection: upgrade, close' is not recognised as requesting closure. curl then reuses the connection, and a later request to the same host:port sends its credentials to the attacker's still-open socket.

henriqueg Follow

Originally disclosed on HackerOne

  • Disclosed after 24 hours

Summary

Curl_compareheader() in lib/http.c fails to scan the full value of HTTP headers for substring matches. Due to an incorrect loop condition, only the first byte position of the header value is checked. This causes curl to miss connection options like close when they appear as non-first tokens in comma-separated header values such as Connection: upgrade, close.

When a malicious server sends Connection: upgrade, close, curl fails to detect the close token and incorrectly keeps the connection alive in its pool. A subsequent request to the same host:port reuses this connection, sending its credentials (Authorization headers, cookies) to the still-listening attacker server.

Detailed Description

The Connection header field is defined in RFC 9110 §7.6.1 with ABNF grammar Connection = #connection-option, where # denotes a comma-separated list. Therefore Connection: upgrade, close is a valid header containing two connection options. RFC 9112 §9.6 states:

A client that receives a "close" connection option MUST cease sending requests on that connection and close the connection after reading the response message containing the "close" connection option.

The bug is in the for loop at lib/http.c line 1438:

C
for(len = curlx_strlen(&val); len >= curlx_strlen(&val); len--, p++) {

The loop initializes len to the value length and then checks len >= curlx_strlen(&val) - the same value. After the first iteration and len--, the condition is false and the loop exits. Only position 0 is ever checked.

The same function is used for matching Connection: close, Connection: keep-alive, Transfer-Encoding: chunked, Expect: 100-continue, and proxy Connection / Proxy-Connection headers. All are affected.

No other major HTTP client has this bug. wget, Python requests, Python http.client, and Node.js http all correctly parse multi-value Connection headers.

Impact

Impact

A malicious server can exploit this to steal credentials from subsequent requests via connection pool poisoning:

  1. Attacker's server responds to a victim request with Connection: upgrade, close
  2. curl misses the close token and keeps the connection in its pool
  3. Attacker keeps the TCP socket open (violating its own close declaration)
  4. Victim's next request to the same host:port reuses the poisoned connection
  5. The request - including Authorization headers and cookies - sent to the attacker's still-listening socket

This is exploitable in environments where curl makes sequential requests to the same host:port, such as API gateways, Kubernetes services behind shared Ingress, CI/CD pipelines, and shared hosting.

PoC - Exploitation

The PoC server (server.py) simulates two services behind the same host:port:

  • /public - attacker-controlled endpoint that poisons the connection
  • /private - legitimate endpoint that requires Authorization and returns account data

Test 1 - Direct request to /private (safe baseline):

Shell
# Terminal 1
python3 server.py 8000

# Terminal 2
curl -s http://127.0.0.1:8000/private \
     -H "Authorization: Bearer SECRET_TOKEN"

Output:

[private] Auth received: Authorization: Bearer SECRET_TOKEN
[private] Returned account data (normal flow)
{"account": "[email protected]", "balance": 42000}

Credentials go to the legitimate /private handler. No leak. This is the expected behavior.

Test 2 - Visit /public first, then /private (attack):

Shell
# Terminal 1
python3 server.py 8000

# Terminal 2
curl -s http://127.0.0.1:8000/public \
     --next \
     -H "Authorization: Bearer SECRET_TOKEN" \
     http://127.0.0.1:8000/private

Output:

[attacker] Request from 127.0.0.1: GET /public HTTP/1.1
[attacker] Sent 'Connection: upgrade, close'
[attacker] Waiting for leaked request on same socket...

[attacker] *** INTERCEPTED REQUEST ***

      GET /private HTTP/1.1
      Host: 127.0.0.1:8000
      User-Agent: curl/8.19.0-DEV
      Accept: */*
  >>> Authorization: Bearer SECRET_TOKEN

[attacker] This request was meant for /private.
[attacker] The credentials were leaked because curl
[attacker] reused the poisoned connection.

Request #1 to /public had NO credentials. Request #2 to /private carried Authorization: Bearer SECRET_TOKEN. But the /private handler never ran - the attacker's /public handler captured the credentials on the reused TCP socket.

PS. The --next flag resets per-request options so Authorization applies only to the second URL.

Attachments

Screenshot_2026-03-10_112650.png
Screenshot_2026-03-10_112650.png From the original on HackerOne

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

Context

curl parses a number of HTTP headers by looking for known tokens inside the header value. The helper Curl_compareheader() in lib/http.c is used to match Connection: close, Connection: keep-alive, Transfer-Encoding: chunked, Expect: 100-continue, and the proxy Connection / Proxy-Connection headers. When curl sees close in a Connection header, it must stop sending requests on that connection and close it after reading the response, as RFC 9112 §9.6 requires.

The Connection header is defined in RFC 9110 §7.6.1 with the grammar Connection = #connection-option, where # denotes a comma-separated list. So Connection: upgrade, close is a valid header carrying two connection options, and a client must honour the close token wherever it appears in the list.

Setup

The report does not describe any special accounts, roles or third-party tooling. The work is against the curl source tree at https://github.com/curl/curl, and the proof of concept runs locally: a Python server (server.py) on port 8000 and a curl client. The client version shown in the captured request is curl/8.19.0-DEV. The PoC server simulates two services behind the same host:port:

  • /public: an attacker-controlled endpoint that poisons the connection.
  • /private: a legitimate endpoint that requires Authorization and returns account data.

The precondition for the attack is an environment where curl makes sequential requests to the same host:port, such as API gateways, Kubernetes services behind a shared Ingress, CI/CD pipelines and shared hosting.

Finding it

The researcher looked at the loop that scans the header value in Curl_compareheader() at lib/http.c line 1438:

C
for(len = curlx_strlen(&val); len >= curlx_strlen(&val); len--, p++) {

The loop initialises len to the length of the value and then compares it against that same length in the condition. After the first iteration, len-- makes the condition false and the loop exits. Only byte position 0 of the header value is ever checked, so a token that appears anywhere other than the start of the value is missed.

That is why Connection: upgrade, close slips through: close is the second token, not the first. The same helper backs the other header matches listed above, so all of them are affected in the same way. The researcher also notes that no other major HTTP client has this bug: wget, Python requests, Python http.client and Node.js http all correctly parse multi-value Connection headers.

Exploitation

The attack is connection pool poisoning. A malicious server answers a victim request with Connection: upgrade, close. curl misses the close token and keeps the connection in its pool. The attacker keeps the TCP socket open, violating its own close declaration. The victim's next request to the same host:port reuses the poisoned connection, and the request, including Authorization headers and cookies, is sent to the attacker's still-listening socket.

Step 1: Baseline, direct request to /private

Start the PoC server and send a request straight to the legitimate endpoint:

Shell
# Terminal 1
python3 server.py 8000

# Terminal 2
curl -s http://[redacted]:8000/private \
     -H "Authorization: Bearer SECRET_TOKEN"

The output shows the credentials reaching the legitimate handler and the account data coming back:

Text
[private] Auth received: Authorization: Bearer SECRET_TOKEN
[private] Returned account data (normal flow)
{"account": "[redacted]", "balance": 42000}

No leak here. This is the expected behaviour.

Step 2: Visit /public first, then /private

Now make the client hit the attacker endpoint first and the private endpoint second, on the same host:port, using --next to separate the two requests:

Shell
# Terminal 1
python3 server.py 8000

# Terminal 2
curl -s http://[redacted]:8000/public \
     --next \
     -H "Authorization: Bearer SECRET_TOKEN" \
     http://[redacted]:8000/private

The --next flag resets per-request options, so the Authorization header applies only to the second URL. The first request to /public carries no credentials.

The server output shows the attacker handler receiving the first request, answering with the poisoned header, and then capturing the second request on the same socket:

Text
[attacker] Request from [redacted]: GET /public HTTP/1.1
[attacker] Sent 'Connection: upgrade, close'
[attacker] Waiting for leaked request on same socket...

[attacker] *** INTERCEPTED REQUEST ***

      GET /private HTTP/1.1
      Host: [redacted]:8000
      User-Agent: curl/8.19.0-DEV
      Accept: */*
  >>> Authorization: Bearer SECRET_TOKEN

[attacker] This request was meant for /private.
[attacker] The credentials were leaked because curl
[attacker] reused the poisoned connection.

Request #1 to /public had no credentials. Request #2 to /private carried Authorization: Bearer SECRET_TOKEN, but the /private handler never ran: the attacker's /public handler captured the credentials on the reused TCP socket.

Screenshot_2026-03-10_112650.png
Screenshot_2026-03-10_112650.png From the original on HackerOne

Root cause

The defect is the loop condition in Curl_compareheader(). Comparing len against curlx_strlen(&val) on every iteration means the loop can only ever run once, so the scan stops at the first byte position of the header value. A comma-separated list such as upgrade, close is therefore never searched past its first token, and the close option is not detected.

Because the same helper is used for Connection: close, Connection: keep-alive, Transfer-Encoding: chunked, Expect: 100-continue and the proxy Connection / Proxy-Connection headers, the failure is not limited to the close case. The report does not describe any other defence that would have caught the poisoned connection; the client simply trusts its own (broken) header match when deciding whether to keep the socket in the pool.

Impact

A malicious server can steal credentials from subsequent requests by poisoning the connection pool. The victim's next request to the same host:port, including Authorization headers and cookies, is delivered to the attacker's still-listening socket instead of the intended service. This applies where curl makes sequential requests to the same host:port, such as API gateways, Kubernetes services behind a shared Ingress, CI/CD pipelines and shared hosting. The platform records the severity as medium, with the weakness classed as an expected behaviour violation.

Fix

Variants to test

  1. Send Connection: upgrade, close from a test server and check whether the client reuses the socket for a second request to the same host:port. A positive result is the second request arriving on the same TCP connection after the server declared close.
  2. Try other multi-value forms of the affected headers, for example Transfer-Encoding: gzip, chunked or Expect: something, 100-continue, and observe whether the client honours the second token.
  3. Test the proxy variants, Connection and Proxy-Connection, through a proxy setup with a comma-separated value. A positive result is the client keeping a connection the proxy asked it to close.
  4. Run the same sequence against other clients (wget, Python requests, Python http.client, Node.js http) as a control. A positive result there would indicate a broader parsing problem rather than the curl-specific loop bug.

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

What happened, in plain words

curl is a very common program for fetching things from the internet. You may not have used it directly, but a lot of software you do use calls it behind the scenes: scripts, build systems, API gateways, and so on. When curl talks to a web server, it can keep the network connection open after a reply and reuse it for the next request. That saves time, because opening a new connection is slow.

A web server can tell curl to close a connection by putting the word close in a response header called Connection. curl is supposed to read that header and, if it sees close, stop using the connection. The bug in this report is that curl only looks at the very first word of that header. If the server writes Connection: upgrade, close, the word close is the second item in a comma-separated list, and curl never notices it. It keeps the connection open and reuses it.

A malicious server can abuse this. It answers a request with Connection: upgrade, close, then keeps its end of the connection open even though it just said it would close it. When the victim's next request goes to the same host and port, curl reuses that same connection, and the request, including any login token or cookie, lands in the attacker's hands instead of the real service.

The report calls this connection pool poisoning. The platform records it as a medium-severity issue, classed as an expected behaviour violation: the program did not do what its own documentation and the HTTP standard say it should.

Background: the pieces you need

Before the details, a few everyday ideas.

  • HTTP: the language browsers and programs use to talk to web servers. A request asks for something; a response answers it. Both are made of a first line, then a set of headers (name and value pairs), then an optional body.
  • Header: a labelled line in a request or response, like Connection: close. Think of it as a note in the margin of a letter.
  • Connection: the actual network link between two computers. Opening one takes time, so programs often keep it open and send several requests over it, one after another. This is called a persistent connection, and the collection of open connections a program keeps is called a connection pool.
  • Host and port: a host is a computer's address (a name or an IP address); a port is a numbered door on that computer. [redacted]:8000 means the local machine, door 8000. Two different services can sit behind the same host and port, which is exactly what makes this attack possible.
  • API: a way for one program to ask another for data or actions, usually over HTTP. An API gateway is a front door that routes API traffic to the right service behind it.
  • Token / cookie: a short piece of text that proves who you are. A cookie is stored by the browser; an Authorization header carries a token on each request. If someone else gets it, they can act as you. In this report the token is SECRET_TOKEN, a placeholder.
  • curl: the command-line program and library that makes these HTTP requests. The report is about the library part, in a file called lib/http.c.
  • RFC: a document that describes how internet standards work. RFC 9110 and RFC 9112 are the ones that define HTTP headers and connection behaviour.
  • ABNF grammar: a formal way of writing down the allowed shape of a piece of text. Connection = #connection-option means the header holds one or more connection options, separated by commas. The # symbol is the part that means "comma-separated list".
  • Byte position: a numbered slot in a piece of text, starting at 0. Position 0 is the first character.

Context: what curl is supposed to do

curl reads several HTTP headers by searching for known words inside the header value. A helper function called Curl_compareheader() in lib/http.c does this search. It is used to recognise:

  • Connection: close
  • Connection: keep-alive
  • Transfer-Encoding: chunked
  • Expect: 100-continue
  • the proxy headers Connection and Proxy-Connection

When curl sees close in a Connection header, the standard (RFC 9112 §9.6) says it must stop sending requests on that connection and close it after reading the response. The Connection header itself is defined in RFC 9110 §7.6.1 as a comma-separated list of options. So Connection: upgrade, close is perfectly valid, and a client must honour the close wherever it appears in the list, not only at the front.

Setup: what the researcher used

The report does not describe any special accounts, roles or third-party tools. The work is against the curl source code at https://github.com/curl/curl, and the proof of concept runs entirely on the local machine: a small Python server (server.py) listening on port 8000, and a curl client. The client version shown in the captured request is curl/8.19.0-DEV.

The PoC server pretends to be two services behind the same host and port:

  • /public: an endpoint controlled by the attacker, which poisons the connection.
  • /private: a legitimate endpoint that requires an Authorization header and returns account data.

The attack only works where curl makes one request after another to the same host and port. The report lists examples: API gateways, Kubernetes services behind a shared Ingress, CI/CD pipelines and shared hosting. In all of those, many different services can share one address, so a connection reused for the wrong service is a real risk.

Finding it: the broken loop

The researcher looked at the loop that scans the header value in Curl_compareheader(), at lib/http.c line 1438:

C
for(len = curlx_strlen(&val); len >= curlx_strlen(&val); len--, p++) {

Line by line, in plain words:

  1. len = curlx_strlen(&val) sets len to the length of the header value. If the value is upgrade, close, that is its length in characters.
  2. len >= curlx_strlen(&val) is the condition checked before every pass. It compares len with the same length again. On the first pass, 14 is greater than or equal to 14, so the loop runs.
  3. len--, p++ runs after each pass: len goes down by one, and p moves one character forward in the value.
  4. On the second check, len is 13 and the length is still 14, so 13 is not greater than or equal to 14. The loop stops.

So the loop can only ever run once, and only byte position 0 of the header value is ever checked. A word that appears anywhere other than the very start of the value is missed. That is why Connection: upgrade, close slips through: close is the second item, not the first.

The same helper backs all the other header matches listed above, so they are all affected in the same way. The researcher also notes that no other major HTTP client has this bug: wget, Python requests, Python http.client and Node.js http all correctly parse multi-value Connection headers.

Exploitation: stealing credentials

The attack is connection pool poisoning. A malicious server answers a victim request with Connection: upgrade, close. curl misses the close token and keeps the connection in its pool. The attacker keeps the network socket open, breaking its own promise to close. The victim's next request to the same host and port reuses the poisoned connection, and the request, including Authorization headers and cookies, is sent to the attacker's still-listening socket.

Step 1: a safe baseline

First, start the PoC server and send a request straight to the legitimate endpoint. This step exists to show what normal, correct behaviour looks like, so that the attack in step 2 is clearly different.

Shell
# Terminal 1
python3 server.py 8000

# Terminal 2
curl -s http://[redacted]:8000/private \
     -H "Authorization: Bearer SECRET_TOKEN"

What each part does:

  1. # Terminal 1 and # Terminal 2 are comments telling you to use two separate terminal windows.
  2. python3 server.py 8000 runs the PoC server with Python 3, listening on port 8000.
  3. curl -s runs curl in silent mode, so it does not print progress bars.
  4. http://[redacted]:8000/private is the address of the legitimate endpoint on the local machine.
  5. -H "Authorization: Bearer SECRET_TOKEN" adds an Authorization header carrying the token. Bearer is just the scheme name; the token follows it.

The output shows the credentials reaching the legitimate handler and the account data coming back:

Text
[private] Auth received: Authorization: Bearer SECRET_TOKEN
[private] Returned account data (normal flow)
{"account": "[redacted]", "balance": 42000}

Line by line:

  1. [private] Auth received: ... is the legitimate handler confirming it saw the token.
  2. [private] Returned account data (normal flow) says the normal code path ran.
  3. The last line is the JSON body returned to the client: an account name and a balance.

No leak here. This is the expected behaviour.

Step 2: visit /public first, then /private

Now make the client hit the attacker endpoint first and the private endpoint second, on the same host and port, using --next to separate the two requests:

Shell
# Terminal 1
python3 server.py 8000

# Terminal 2
curl -s http://[redacted]:8000/public \
     --next \
     -H "Authorization: Bearer SECRET_TOKEN" \
     http://[redacted]:8000/private

Line by line:

  1. The server is started the same way as before.
  2. curl -s http://[redacted]:8000/public sends the first request to the attacker endpoint. No credentials are attached to it.
  3. --next tells curl that the options after it apply to a new, separate request. It resets per-request options, so the Authorization header applies only to the second URL.
  4. -H "Authorization: Bearer SECRET_TOKEN" attaches the token to the second request only.
  5. http://[redacted]:8000/private is the second request, to the legitimate endpoint.

The server output shows the attacker handler receiving the first request, answering with the poisoned header, and then capturing the second request on the same socket:

Text
[attacker] Request from [redacted]: GET /public HTTP/1.1
[attacker] Sent 'Connection: upgrade, close'
[attacker] Waiting for leaked request on same socket...

[attacker] *** INTERCEPTED REQUEST ***

      GET /private HTTP/1.1
      Host: [redacted]:8000
      User-Agent: curl/8.19.0-DEV
      Accept: */*
  >>> Authorization: Bearer SECRET_TOKEN

[attacker] This request was meant for /private.
[attacker] The credentials were leaked because curl
[attacker] reused the poisoned connection.

Line by line:

  1. [attacker] Request from [redacted]: GET /public HTTP/1.1 is the first request arriving at the attacker handler.
  2. [attacker] Sent 'Connection: upgrade, close' is the poisoned response header. The attacker is claiming it will close the connection, but it will not.
  3. [attacker] Waiting for leaked request on same socket... shows the attacker keeping the socket open and waiting.
  4. *** INTERCEPTED REQUEST *** marks the moment the second request arrives on that same socket.
  5. GET /private HTTP/1.1 is the second request, the one meant for the legitimate service.
  6. Host: [redacted]:8000 says which host and port the request was aimed at.
  7. User-Agent: curl/8.19.0-DEV identifies the client and version.
  8. Accept: */* says the client accepts any content type.
  9. >>> Authorization: Bearer SECRET_TOKEN is the credential, now in the attacker's hands.
  10. The closing lines explain that the request was meant for /private and that the credentials leaked because curl reused the poisoned connection.

Request #1 to /public had no credentials. Request #2 to /private carried Authorization: Bearer SECRET_TOKEN, but the /private handler never ran: the attacker's /public handler captured the credentials on the reused socket.

Screenshot_2026-03-10_112650.png
Screenshot_2026-03-10_112650.png From the original on HackerOne

Root cause

The defect is the loop condition in Curl_compareheader(). Comparing len against curlx_strlen(&val) on every pass means the loop can only ever run once, so the scan stops at the first byte position of the header value. A comma-separated list such as upgrade, close is therefore never searched past its first item, and the close option is not detected.

Because the same helper is used for Connection: close, Connection: keep-alive, Transfer-Encoding: chunked, Expect: 100-continue and the proxy Connection / Proxy-Connection headers, the failure is not limited to the close case. The report does not describe any other defence that would have caught the poisoned connection; the client simply trusts its own broken header match when deciding whether to keep the socket in the pool.

Impact

A malicious server can steal credentials from later requests by poisoning the connection pool. The victim's next request to the same host and port, including Authorization headers and cookies, is delivered to the attacker's still-listening socket instead of the intended service. This applies where curl makes one request after another to the same host and port, such as API gateways, Kubernetes services behind a shared Ingress, CI/CD pipelines and shared hosting. The platform records the severity as medium, with the weakness classed as an expected behaviour violation.

Fix

Variants to test

  1. Send Connection: upgrade, close from a test server and check whether the client reuses the socket for a second request to the same host and port. A positive result is the second request arriving on the same connection after the server declared close.
  2. Try other multi-value forms of the affected headers, for example Transfer-Encoding: gzip, chunked or Expect: something, 100-continue, and observe whether the client honours the second item.
  3. Test the proxy variants, Connection and Proxy-Connection, through a proxy setup with a comma-separated value. A positive result is the client keeping a connection the proxy asked it to close.
  4. Run the same sequence against other clients (wget, Python requests, Python http.client, Node.js http) as a control. A positive result there would indicate a broader parsing problem rather than the curl-specific loop bug.

Glossary

  • ABNF grammar: a formal notation for describing the allowed shape of text, such as a header value.
  • API gateway: a front door that routes API traffic to the right service behind it.
  • Authorization header: a request header that carries a credential, such as a token, proving who is making the request.
  • Bearer: the name of a common scheme for sending a token in an Authorization header.
  • CI/CD pipeline: an automated build and deployment system that runs scripts, often using curl.
  • Connection: the network link between two computers; also the name of the HTTP header that carries connection options.
  • Connection pool: the set of open connections a program keeps so it can reuse them.
  • Connection pool poisoning: tricking a client into keeping a connection open and reusing it for a request that should have gone elsewhere.
  • Cookie: a small piece of text a browser or client stores and sends back to prove who you are.
  • curl: a command-line program and library for making HTTP requests.
  • Endpoint: a specific address on a server, such as /public or /private.
  • Header: a labelled line in an HTTP request or response, made of a name and a value.
  • Host: a computer's address, by name or IP address.
  • Ingress: a Kubernetes component that routes incoming traffic to services behind it.
  • JSON: a text format for structured data, such as {"account": "...", "balance": 42000}.
  • Kubernetes: a system for running and managing many services, often sharing network addresses.
  • Persistent connection: a connection kept open and reused for several requests.
  • PoC: proof of concept, a small demonstration that the bug is real.
  • Port: a numbered door on a computer, such as 8000.
  • Proxy: an intermediary that forwards requests on your behalf.
  • RFC: a document that defines an internet standard.
  • Severity: a rating of how serious a bug is; here, medium.
  • Socket: the program's handle on a network connection.
  • Token: a short piece of text that proves identity, sent with requests.
  • User-Agent: a header that identifies the client program and version.
  • Weakness class: the category a bug is filed under; here, expected behaviour violation.
  • wget: another command-line program for downloading things over HTTP.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.