Skip to content

fix: RFC 9110 compliant header copying - #75

Open
rhclayto wants to merge 6 commits into
TimWolla:mainfrom
rhclayto:rhclayto-rfc9110-patch-1
Open

rhclayto wants to merge 6 commits into
TimWolla:mainfrom
rhclayto:rhclayto-rfc9110-patch-1

Conversation

@rhclayto

@rhclayto rhclayto commented Nov 20, 2026 •

Copy link
Copy Markdown

Headers that must never be copied between connections, per RFC 9110 section 7.6.1.

I ran into a problem where Websocket upgrade headers were causing HAProxy errors. It turns out that copying "connection: upgrade" plus "upgrade: websocket" from the client makes HAProxy's strict H1 parser reject the synthesized auth probe with <BADREQ>, because the probe is a plain HEAD that the frontend cannot service as an upgrade request. Suppressing "connection" also lets haproxy-lua-http add its intended "connection: close".

Headers that must never be copied between connections, per RFC 9110 section 7.6.1.
@TimWolla

Copy link
Copy Markdown
Owner

Thank you! Can you add a test as well?

Comment thread auth-request.lua Resolved
@TimWolla

Copy link
Copy Markdown
Owner

CI failure fixed with #76 after a rebase.

h added 2 commits November 20, 2026 21:13
header_match() gates all three header-copying directions (client to auth
backend, auth backend to protected backend, auth backend to client), but
none of them were covered for hop-by-hop suppression.

Add test/header_match.lua, a standalone unit test that needs only a lua
interpreter. It pins down all nine HOP_BY_HOP_HEADERS entries, asserts a
blocklisted header stays blocked when an operator requests it by name, and
checks that ordinary headers keep matching so widening the two hardcoded
content-length/host comparisons into a table did not over-block. It
self-locates auth-request.lua, so it runs from any working directory.

Add three .vtc tests, one per copying direction, and run the unit test in
CI next to the vtest suite.

Verified against the pre-fix condition (header == "content-length" or
header == "host"): the unit test reports 14 failing checks and each .vtc
test fails on an expected header, so none of them pass for the wrong
reason. The full suite is green on HAProxy 3.4.8: 23 passed, 1 skipped,
0 failed.

Two headers are deliberately not asserted end-to-end. HAProxy 3.4 strips
a client "connection" or "upgrade" header before req_get_headers() is
visible to Lua, and rejects a client request carrying both "connection:
upgrade" and "upgrade: <proto>" at the frontend, with a 400 of its own,
before any Lua action runs. Assertions on those would pass without the
blocklist, so header_match.lua covers them directly instead.
lua-json depends only on lua-lpeg, so nothing in the job guaranteed a Lua
binary on PATH for test/header_match.lua. Install lua5.4 alongside it and
call that binary directly instead of probing PATH.

The unit test itself is version-independent: it passes under lua5.1 and
lua5.4 unchanged.
@rhclayto

Copy link
Copy Markdown
Author

Thank you! Can you add a test as well?

Check.

@rhclayto
rhclayto force-pushed the rhclayto-rfc9110-patch-1 branch from 215d19c to 39c7843 Compare November 21, 2026 04:39
@TimWolla
TimWolla self-requested a review November 21, 2026 11:03

@TimWolla TimWolla left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you. I cleaned out the useless comments from the integration tests (I assume they come from some agent?) and pushed the changes.

For the standalone Lua test I'm looking forward to your feedback if you have reasons for it to stay that I'm missing or if we can just delete it, because an overzealous agent suggested adding it.

Comment thread test/header_match.lua Outdated
Comment on lines +96 to +101
-- 5. The blocklist keys must stay lowercase to keep matching the names HAProxy
-- and haproxy-lua-http hand back. A future edit writing "Connection" would
-- be invisible to the end-to-end tests, so catch it here.
for _, header in ipairs(HOP_BY_HOP) do
check("blocklist key is lowercase: " .. header, header, header:lower())
end

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm not sure this is testing something useful: HOP_BY_HOP is the table that is local to this test, not the one in the actual script.

Comment thread auth-request.lua Resolved
Comment thread test/header_match.lua Outdated

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Overall I'm not sure if the premise of this test if worth introducing unit tests in addition to the integration tests. Getting a “table lookup” correct in Lua is not all that complicated and has little chance for regressions that are not also caught by the integration tests.

@rhclayto

Copy link
Copy Markdown
Author

Thank you. I cleaned out the useless comments from the integration tests (I assume they come from some agent?) and pushed the changes.

For the standalone Lua test I'm looking forward to your feedback if you have reasons for it to stay that I'm missing or if we can just delete it, because an overzealous agent suggested adding it.

We can delete it, no problem.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants