Skip to content
Smuggling / CRLF Write-up Advanced

http: properly reject empty http header field names

HAProxy's HTTP/1 parser accepted empty header field names, which truncated the header list and caused some headers to be seen during parsing but not forwarded. An attacker could exploit this to make HAProxy forward more data than advertised and bypass access controls or routing rules.

Bahruz Jabiyev Follow

Published on github.com

haproxy / haproxy Public

Bahruz Jabiyev (@BahruzJabiyev), Anthony Gavazzi, Engin Kirda, Kaan Onarlioglu, Adi Peleg, Harvey Tuch, on github.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 5 min read.

What the report shows

This is a fix commit in the HAProxy repository, titled BUG/CRITICAL: http: properly reject empty http header field names, and it carries the assignment of CVE-2023-25725. The commit message is the whole of the write-up: it explains the flaw, gives a configuration workaround, shows the fix in action, and credits the researchers. The issue was found and reported jointly by Bahruz Jabiyev, Anthony Gavazzi and Engin Kirda of Northeastern University, Kaan Onarlioglu of Akamai Technologies, and Adi Peleg and Harvey Tuch of Google. Amaury Denoyelle of HAProxy Technologies is credited with spotting that the HPACK and QPACK decoders would let the malformed input pass despite a code comment saying otherwise.

The finding is that HAProxy's HTTP header parsers accepted empty header field names. The H1 parser could deliver such a name into the internal list of headers, and the HPACK and QPACK decompressors could also successfully decompress an empty header field name. Because the internal header lists are terminated by an empty header field name, an attacker-supplied empty name truncates the list: headers parsed before it are seen by HAProxy during parsing but never reach upper layers, are not evaluated by http-request rules, and are not forwarded.

The commit message demonstrates the behaviour with a request containing an empty header name, sent to a listener on port 8001:

Bash
$ printf "GET / HTTP/1.1\r\nHost: localhost\r\n:empty header\r\n\r\n" | nc 0 8001
HTTP/1.1 400 Bad request
Content-length: 90
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>

The fixed build rejects the request, and the error ring buffer records a precise diagnostic with the offending position and the source address:

Bash
$ socat /var/run/haproxy.stat <<< "show errors"
Total events captured on [10/Feb/[redacted].530] : 1

[10/Feb/[redacted].155] frontend decrypt (#2): invalid request
  backend <NONE> (#-1), server <NONE> (#-1), event #0, src [redacted]:31092
  buffer starts at 0 (including 0 out), 16334 free,
  len 50, wraps at 16336, error at position 33
  H1 connection flags 0x00000000, H1 stream flags 0x00000810
  H1 msg state MSG_HDR_NAME(17), H1 msg flags 0x00001410
  H1 chunk len 0 bytes, H1 body len 0 bytes :

  00000  GET / HTTP/1.1\r\n
  00016  Host: localhost\r\n
  00033  :empty header\r\n
  00048  \r\n

The fix must be backported as far as 2.0, with the QPACK changes dropped before 2.6. In 2.0 the equivalent legacy-mode code does not suffer from the list truncation but is fixed regardless. The commit does not state a bounty or a CVSS score.

Root cause

The internal header lists used by the muxes were designed to be terminated by an empty header field name, a convention borrowed from HTTP/2's HPACK, where empty names are forbidden by the protocol. When other protocols were migrated to the mux framework, nobody noticed that the H1 parser could still hand an empty header field name to that list. The HPACK decompressor, despite a comment in the code, could also decompress an empty name, and the same mistake was carried into QPACK. The fix blocks empty header names where they are first inserted, in the H1, HPACK and QPACK decoders.

Impact

For HTTP/2 and HTTP/3 the impact is limited: HAProxy sees a request with missing headers, and headers are not used to delimit messages. For HTTP/1 the impact is significant, because the presence and sometimes the contents of sensitive headers are checked during parsing. Headers such as Connection, Upgrade, Host, Content-length and Transfer-Encoding may be seen as one thing by the parser and forwarder and as another by http-request rules. The report states that this can be exploited to make affected versions forward more data than is advertised to the other side, and to bypass access controls or routing rules by crafting extraneous requests. Responses to such requests will normally not be passed back to the client, but the report notes this can still cause harm.

How this kind of bug works

Parsers often use a sentinel value to mark the end of a list, and here the sentinel is an empty header name. If the parser accepts the same value from the wire, an attacker can end the list early. Everything after the injected empty name is dropped from the parsed structure, while anything the front end already inspected during parsing may still influence routing, body-length accounting or access decisions. The result is a disagreement between two components about the same message, which can lead to access-control bypasses. Defences are strict validation of field names at the earliest parsing stage, rejecting anything that does not match the token grammar, and avoiding sentinels that can appear in valid or attacker-supplied input.

How to test for it

  1. Identify front ends that parse HTTP/1 themselves, especially proxies, load balancers and CDNs in front of an origin.
  2. Send a request whose header block contains a line that begins with a colon and no name, placed after a header the front end is known to act on, such as Content-Length or Host.
  3. Observe whether the front end rejects the request with a 400, or accepts it and forwards a request that lacks the earlier headers.
  4. Compare what the front end appears to route on with what the origin receives, for example by pointing the request at a logging endpoint.
  5. Try the same trick with a body whose length is declared before the empty name, and check whether the origin receives more data than declared.

How it is fixed

The commit blocks empty header names where they are first inserted, in the H1, HPACK and QPACK decoders, rather than changing every loop that iterates over the header lists. The report notes that a cleaner long-term solution would be to check the header name's pointer instead of its length in functions such as htx_add_header(), htx_add_trailer() and htx_add_all_headers(), but that would require touching many places. As an interim mitigation, the report gives a rule that denies HTTP/1 requests carrying a body without a Content-Length or Transfer-Encoding header, excluding CONNECT:

Text
http-request deny if { fc_http_major 1 } !{ req.body_size 0 } !{ req.hdr(content-length) -m found } !{ req.hdr(transfer-encoding) -m found } !{ method CONNECT }

Hunting notes

This class of bug hides in any component that parses HTTP itself: reverse proxies, API gateways, WAFs, caching layers and origin servers with their own parsers.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 7 min read.

What happened, in plain words

HAProxy is a piece of software that sits in front of web servers. You can think of it as a receptionist in a building: visitors (web requests) arrive, the receptionist reads their details, decides which office they should go to, and passes them on.

This report is a fix commit in the HAProxy source code repository, titled BUG/CRITICAL: http: properly reject empty http header field names, and it records that the issue was given the identifier CVE-2023-25725. A CVE is a public catalogue number for a known security flaw, so people can look it up and track it. The commit message is the whole write-up: it explains the flaw, offers a temporary configuration workaround, shows the fix working, and credits the people who found it.

The flaw is about HTTP headers. When your browser asks for a web page, it sends a request made of lines. The first line says what it wants (for example GET / HTTP/1.1), and the following lines are headers: labelled pieces of information such as Host: localhost, which tells the server which site is wanted. Each header line has a name, a colon, and a value. HAProxy reads these lines, keeps them in an internal list, and uses some of them to make decisions: how big the body is, where to route the request, whether access is allowed.

The problem: HAProxy accepted a header line with an empty name, meaning a line that starts with a colon and has nothing before it. Internally, HAProxy used an empty header name as a marker meaning "this is the end of the list". So when an attacker sent a header line with an empty name, HAProxy treated it as the end of the headers. Everything after that point was cut off from the list. Headers that HAProxy had already read and acted on during parsing were then never passed on to the next stage, never checked against the site's access rules, and never forwarded to the real server.

The commit message demonstrates this with a request sent to a test listener on port 8001:

Bash
$ printf "GET / HTTP/1.1\r\nHost: localhost\r\n:empty header\r\n\r\n" | nc 0 8001
HTTP/1.1 400 Bad request
Content-length: 90
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>

Line by line: printf builds the raw text of a request. GET / HTTP/1.1 asks for the root page using version 1.1 of HTTP. Host: localhost is a normal header naming the site. :empty header is the malicious line: a colon with no name before it. The final \r\n\r\n ends the header block with a blank line. nc 0 8001 sends that text to the local machine on port 8001. On the fixed build, HAProxy answers 400 Bad request, meaning it refuses the request as invalid. That refusal is the whole point: the malformed line is now caught instead of being silently misread.

The commit also shows HAProxy's diagnostic log, which records exactly where the bad request was spotted:

Bash
$ socat /var/run/haproxy.stat <<< "show errors"
Total events captured on [10/Feb/[redacted].530] : 1

[10/Feb/[redacted].155] frontend decrypt (#2): invalid request
  backend <NONE> (#-1), server <NONE> (#-1), event #0, src [redacted]:31092
  buffer starts at 0 (including 0 out), 16334 free,
  len 50, wraps at 16336, error at position 33
  H1 connection flags 0x00000000, H1 stream flags 0x00000810
  H1 msg state MSG_HDR_NAME(17), H1 msg flags 0x00001410
  H1 chunk len 0 bytes, H1 body len 0 bytes :

  00000  GET / HTTP/1.1\r\n
  00016  Host: localhost\r\n
  00033  :empty header\r\n
  00048  \r\n

This asks HAProxy to show errors. The output says one event was captured, that it came from a frontend called decrypt, and that the error sits at position 33, which is exactly where the :empty header line begins. The dump at the bottom shows the request with offsets, including the offending line.

The impact differs by protocol version. For HTTP/2 and HTTP/3, HAProxy simply sees a request with some headers missing, and since those versions do not use headers to mark where a message ends, the damage is limited. For HTTP/1 the impact is significant: headers such as Connection, Upgrade, Host, Content-length and Transfer-Encoding can be seen one way by the parser and another way by the routing rules. The commit states this can be exploited to make affected versions forward more data than is advertised to the other side, and to bypass access controls or routing rules by crafting extraneous requests. Responses to such requests will normally not be passed back to the client, but the commit notes this can still cause harm.

The fix blocks empty header names at the point where they are first read, in the HTTP/1, HPACK and QPACK decoders. HPACK and QPACK are the compression schemes used for headers in HTTP/2 and HTTP/3 respectively. The commit notes that a cleaner long-term approach would be to change every loop that walks the header list to check the name's pointer rather than its length, in functions such as htx_add_header(), htx_add_trailer() and htx_add_all_headers(), but that would mean touching many places and is easy to get wrong. The fix must be backported as far as version 2.0, meaning applied to older releases too, with the QPACK changes dropped before 2.6.

As a temporary workaround, the commit gives a configuration rule that denies HTTP/1 requests carrying a body without a Content-Length or Transfer-Encoding header, excluding CONNECT:

Text
http-request deny if { fc_http_major 1 } !{ req.body_size 0 } !{ req.hdr(content-length) -m found } !{ req.hdr(transfer-encoding) -m found } !{ method CONNECT }

In plain terms: if the request is HTTP/1, has a body, has neither of those two headers announcing the body, and is not a CONNECT request, refuse it. This relies on the bug's own effect to spot the inconsistency. The commit notes it has no effect in HAProxy 2.0's legacy mode but causes no trouble there either.

The issue was found and reported jointly by Bahruz Jabiyev, Anthony Gavazzi and Engin Kirda of Northeastern University, Kaan Onarlioglu of Akamai Technologies, and Adi Peleg and Harvey Tuch of Google. Amaury Denoyelle of HAProxy Technologies is credited with spotting that the HPACK and QPACK decoders would let the malformed input pass despite a code comment saying otherwise.

In general, how this kind of bug works

This is a class of bug where two parts of a system disagree about the same message. One part reads a request and decides it is harmless; another part reads the same bytes and sees something different. Attackers exploit that gap to slip past filters or access controls.

Here, the "end of form" marker was an empty header name, and the parser accepted that same value from the network.

  1. Validate input strictly at the earliest point, rejecting anything that does not match the allowed grammar for a header name.
  2. Never use a value as an internal end-of-list marker if that same value can arrive from an untrusted source.
  3. Make sure every component that reads the same message agrees on its length, its headers and where it ends.
  4. When you test, send a deliberately malformed request and check whether the front end rejects it cleanly or forwards something inconsistent.

Glossary

  • HAProxy: software that sits in front of web servers, receiving requests and passing them on, often used as a load balancer or proxy.
  • HTTP: the language browsers and servers use to exchange web pages and data.
  • Header: a labelled line in an HTTP request or response, such as Host: localhost, carrying information about the message.
  • Header field name: the part of a header before the colon, for example Host.
  • Request: the message a browser sends to ask a server for something.
  • Response: the message a server sends back.
  • Parser: the part of a program that reads raw text and works out its structure.
  • Mux: short for multiplexer, the HAProxy component that handles several connections or streams at once.
  • HPACK: the header compression scheme used by HTTP/2.
  • QPACK: the header compression scheme used by HTTP/3.
  • HTTP/1, HTTP/2, HTTP/3: successive versions of the HTTP protocol.
  • Sentinel value: a special value used internally to mark something, such as the end of a list.
  • Truncate: to cut something short, here cutting the list of headers at the empty name.
  • CVE: a public catalogue number assigned to a known security flaw.
  • Backport: applying a fix to older versions of the software that are still supported.
  • Frontend: in HAProxy, the part that accepts incoming connections.
  • Backend: in HAProxy, the part that connects to the real servers behind it.
  • Access control: rules that decide who is allowed to reach what.
  • Request smuggling: a class of attack where two components disagree about where one request ends and the next begins.
  • Content-Length: a header stating how many bytes long the body of a request is.
  • Transfer-Encoding: a header stating how the body is encoded for transfer, for example in chunks.
  • CONNECT: an HTTP method used to ask a proxy to open a tunnel to another host.
  • Workaround: a temporary configuration change that reduces the risk before or instead of a proper fix.
  • show errors: an HAProxy command that displays recently captured error events.

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.