Skip to content

MDEV-40878 avoid repeated parsing of PROXY headers - #5630

Open
vaintroub wants to merge 1 commit into
10.11from
10.11-MDEV-40878
Open

MDEV-40878 avoid repeated parsing of PROXY headers#5630
vaintroub wants to merge 1 commit into
10.11from
10.11-MDEV-40878

Conversation

@vaintroub

Copy link
Copy Markdown
Member

Do not parse multiple proxy headers. The protocol spec says the header is at the beginning of a connection, so there could only be one.

According to example in the spec, in multi-layer scenarios, where several proxies are involved between client and backend, the intermediate proxy is supposed to be configured to replace the existing header. Thus multiple headers are not expected.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new guard won’t prevent repeated parsing when the first header is PROXY v1 UNKNOWN / PROXY v2 LOCAL because using_proxy_protocol is not set in that path, allowing a second header to still be parsed.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR aims to address MDEV-40878 by preventing repeated parsing of HAProxy PROXY protocol headers on a single connection, aligning with the spec assumption that only one PROXY header appears at the start of the connection.

Changes:

  • Add an early return in handle_proxy_header() to skip proxy-header parsing once the connection is already marked as using the proxy protocol.
  • Add a client test that sends two concatenated PROXY v1 headers and asserts the connection fails.
  • Register the new test in the existing proxy-header test suite.
File summaries
File Description
tests/mysql_client_test.c Adds a regression test for multiple PROXY headers and wires it into the proxy protocol test group.
sql/net_serv.cc Adds a guard to avoid re-processing PROXY headers once NET::using_proxy_protocol is set.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sql/net_serv.cc Outdated
Comment thread tests/mysql_client_test.c Outdated
Comment on lines +20789 to +20794
/* Test that multiple PROXY headers are rejected (MDEV-40878) */
static void test_proxy_header_multiple()
{
MYSQL *m;
const char header[]= "PROXY TCP4 192.0.2.1 127.0.0.1 12345 3306\r\n"
"PROXY TCP4 192.0.2.2 127.0.0.1 12346 3306\r\n";
Comment thread tests/mysql_client_test.c Outdated
Do not parse multiple proxy headers. The protocol spec says the header is
at the beginning of a connection, so there could only be one.

According to example in the spec, in multi-layer scenarios, where several
proxies are involved between client and backend, the intermediate proxy
is supposed to be configured to replace the existing header. Thus multiple
headers are not expected.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The server-side change is narrowly scoped to the PROXY-header retry path and is backed by a targeted regression test covering the intended failure mode.

Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants