Repository navigation
fix(proxy-protocol): discard the address block of a PROXY-v2 LOCAL header - #1334
Merged
Merged
Conversation
FlorentinDUBOIS
requested review from
Wonshtrum and
llenotre
as code owners
September 18, 2026 18:56
…ader The PROXY protocol v2 wire format does not tie the `LOCAL` command to the `AF_UNSPEC` family — only HAProxy's own emitter pairs the two. A crafted peer could therefore send `LOCAL` (0x20) with family `0x11` and a fully populated 12-byte `AF_INET` block, and `parse_addr_v2` switches on the family nibble alone, so that block reached every consumer of `HeaderV2::addr`. All six attribute `ProxyAddr::source()` to the client, so any peer able to reach a listener with `expect_proxy = true`, or a relay or SNI-preread PROXY listener, could forge the source address Sōzu records in its access logs, injects as `X-Real-IP`, and counts against `max_connections_per_ip` — and so evade that cap by picking a fresh address per connection. Per the HAProxy PROXY protocol specification §2.2, a `LOCAL` header describes a connection the upstream proxy originated on its own behalf, typically a health check, and its address block must be ignored in favour of the real socket endpoints. `parse_v2_header` now yields `ProxyAddr::AfUnspec` for every `LOCAL` header. The `match` is exhaustive on purpose: a future command must make an explicit attribution decision rather than inherit `PROXY`'s by default. One choke point serves all six consumers: none of them reads `command` or `family`, none re-serializes the parsed header — `relay.rs` forwards the buffered bytes verbatim — and all six obtain the address exclusively through this `ProxyAddr`. The six do not resolve `AfUnspec` alike, and that split is operator-visible. The four TCP-side consumers fall back to the front socket's `peer_addr`, so the session proceeds attributed to the real peer. The two HTTP-side ones do not: `HttpSession::upgrade_expect` and `HttpsSession::upgrade_expect` each need both a source and a destination, `AfUnspec` supplies neither, and the refused upgrade becomes `SessionIsToBeClosed` — the session is closed at the expect stage, before any request is read. That is not a regression for legitimate traffic, because HAProxy pairs `LOCAL` with `AF_UNSPEC`, which already parsed to `AfUnspec`; only the forged populated block changes behaviour, from "upgrade with attacker-chosen addresses" to "close". Framing and validation are unchanged. The block is still parsed rather than skipped, so a malformed or unknown family is still rejected and the declared length still delimits the header, and the `family` byte is still reported as it was read off the wire. A `PROXY` header carrying the same block is still honoured, and the guards for that were seen red under the opposite mutation, which proves this secures PROXY support rather than disabling it. Three comments asserting the fallback already happened "when the header carried `Command::Local` (no encapsulated addresses)" were false and are corrected. While editing the module's lifecycle document, 29 of its 35 `file.rs:NNN` citations proved stale — single lines uniformly off by one after a module-doc line was inserted, ranges off by 38 to 57 after the `debug_assert!` campaign grew the functions — and are corrected too. Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/ppv2-local-address
branch
from
September 18, 2026 19:10
ff91881 to
c7754a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security: a forged PROXY-v2
LOCALheader lets any peer choose the source address Sōzu trustsThe PROXY protocol v2 wire format does not tie the
LOCALcommand to theAF_UNSPECfamily —only HAProxy's own emitter pairs the two. A crafted peer can send
LOCAL(ver/cmd0x20) withfamily
0x11and a fully populated 12-byteAF_INETblock, andparse_addr_v2switches on thefamily nibble alone.
That block reached every consumer of
HeaderV2::addr, all of which attributeProxyAddr::source()to the client. So any peer able to reach a listener withexpect_proxy = true,or a relay or SNI-preread PROXY listener, could forge the source address Sōzu
X-Real-IP,max_connections_per_ip— evading that cap entirely by picking a freshaddress per connection.
Fix
Per the HAProxy PROXY protocol specification §2.2, a
LOCALheader describes a connection theupstream proxy originated on its own behalf (typically a health check) and its address block must be
ignored in favour of the real socket endpoints.
parse_v2_headernow yieldsProxyAddr::AfUnspecfor every
LOCALheader — one choke point rather than a check at each consumer.The
matchis exhaustive on purpose: a future command must make an explicit attribution decisionrather than silently inherit
PROXY's.One choke point is sound because none of the consumers reads
commandorfamily, nonere-serializes the parsed header (
relay.rsforwards the buffered bytes verbatim), and all obtainthe address exclusively through this
ProxyAddr.The six consumers do not resolve
AfUnspecalikeThis is operator-visible and the documentation now says so, because it got it wrong three times
during review:
LOCALExpectProxyProtocol::into_pipepeer_addrRelayProxyProtocol::into_pipepeer_addrOutput::Routed { proxy_source })peer_addrTcpSession::effective_session_address— feeds the raw-TCPmax_connections_per_ipgatepeer_addrHttpSession::upgrade_expectHttpsSession::upgrade_expectThe HTTP pair each need both a source and a destination;
AfUnspecsupplies neither, and therefused upgrade becomes
SessionIsToBeClosed— closed at the expect stage, before any request isread.
Not a regression for legitimate traffic. HAProxy pairs
LOCALwithAF_UNSPEC, which alreadyparsed to
AfUnspec, so those sessions already closed. Only the forged populated block changesbehaviour: from "upgrade with attacker-chosen addresses" to "close".
Framing and validation unchanged
The block is still parsed rather than skipped, so a malformed or unknown family is still rejected and
the declared length still delimits the header; the
familybyte is still reported as read.it_should_not_parse_proxy_protocol_with_unknown_familyis untouched and green.Tests — red in both directions
Command::Local => parsed_addr(undoing the fix) turns exactly five tests red: the IPv4 and IPv6parser guards, and one guard at each of
expect.rs,relay.rs,tcp_preread.Command::Proxy => AfUnspec, turns six positive guards red — provingthis secures PROXY support rather than disabling it.
Each carries a
To SEE THESE RED:block naming the exact mutation, per the house convention.Also in this changeset
Three comments claimed the
peer_addrfallback already happened "when the header carriedCommand::Local(no encapsulated addresses)". The parenthetical was false — that is exactly theassumption this fix exists to remove — and they are corrected.
While editing the module's
LIFECYCLE.md, 29 of its 35file.rs:NNNcitations proved stale: singlelines uniformly off by one (a
//!module-doc line inserted after the document was written), rangesoff by 38 to 57 (the
debug_assert!campaign growing the functions). They are corrected here becausethat file documents the behaviour this PR changes. The same rot elsewhere in
doc/is filedseparately rather than expanded into this PR.
Verification
The HTTP close was confirmed empirically, not by reading: flipping the
expect_proxye2e emitter toCommand::Localturnstest_x_real_ip_send_and_elidered with "backend received no request".