Repository navigation
Description
Summary
ExpectProxyProtocol::readable (lib/src/protocol/proxy_protocol/expect.rs) reads the inbound PROXY v2 header in fixed stages: up to 28 bytes, then up to 52, then up to 232. It never reads only the bytes of the header itself. When the header is shorter than the stage it lands in and the client has already sent payload behind it, the read pulls payload bytes into the 232-byte header buffer. On Upgrade that buffer is dropped: neither ExpectProxyProtocol::into_pipe (TCP, lib/src/tcp.rs) nor HttpSession::upgrade_expect / HttpsSession::upgrade_expect (lib/src/http.rs, lib/src/https.rs) carries the unparsed remainder forward. The payload is silently truncated.
Reproduction (TCP cluster with proxy_protocol = ExpectHeader)
Client sends header and payload in one write; the payload is ABCDEFGHIJKLMNOPQRSTUVWXYZ.
| Header | Length | Stage read | Backend receives |
|---|---|---|---|
v2 LOCAL, AF_UNSPEC, len=0 |
16 | 28 | MNOPQRSTUVWXYZ (12 bytes lost) |
v2 PROXY, AF_INET, len=12 |
28 | 28 | intact |
v2 PROXY, AF_INET, len=20 (12 address + 8 TLV bytes) |
36 | 28 then 52 | QRSTUVWXYZ (16 bytes lost) |
v2 PROXY, AF_INET6, len=36 |
52 | 28 then 52 | intact |
v2 PROXY, AF_INET6, len=44 (TLVs) |
60 | 28, 52, then 232 | everything up to 232 bytes lost |
Bytes of the 16-byte LOCAL header:
0d 0a 0d 0a 00 0d 0a 51 55 49 54 0a 20 00 00 00
On HTTP and HTTPS listeners with expect_proxy = true, the same loss cuts the start of the HTTP request or of the TLS ClientHello, so a PROXY header with TLVs (HAProxy send-proxy-v2-ssl, send-proxy-v2-ssl-cn, AWS NLB, ...) followed by a request in the same segment gets a 400 or a failed handshake instead of the response. The headers whose length matches a stage boundary exactly (28 and 52 bytes) are unaffected, which is why the existing tests pass.
When the header and payload arrive in separate segments the read returns early and nothing is lost, so the defect depends on TCP coalescing.
Expected
The expect stage consumes exactly the header (16 + len bytes for v2) and leaves every following byte for the next stage. A header declaring more than 232 bytes, a malformed header, or a PROXY v1 (text) header still closes the session without dialing a backend.
Scope
RelayProxyProtocol(relay.rs) already measures the consumed prefix and keeps the rest in the buffer handed to the pipe.- The SNI preread path (
lib/src/protocol/tcp_preread/mod.rs) skips exactly the parsed header. SendProxyProtocoldoes not read an inbound header.- PROXY v1 is not parsed by Sōzu at all: a v1 header is rejected on its first byte and the session closes.
doc/configure.mdcurrently describesexpect_proxyas "PROXY protocol v1/v2".
Activity
FlorentinDUBOIS commentedon Oct 3, 2026
Fix proposed in #1844.
fix(proxy-protocol): preserve payload after short v2 headers (#1844)