Repository navigation
fix(h1): close the connection after a refused CONNECT - #8
Merged
Merged
Conversation
Early tunnel bytes that arrive in the same read as the CONNECT head go to overread when the empty request body is framed, not through the idle stash. The stash is what turns keepalive off, so a refused CONNECT left the connection reusable. With pipelining enabled, reuse() then passed those bytes on as the next request, so client data meant as opaque tunnel bytes was parsed as an HTTP request after a 403 or 407. Disable keepalive for every final non-2xx response to CONNECT, so the refusal is sent with Connection: close and the connection is never reused, whichever read the early bytes came in. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Ed Snible <snible@us.ibm.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
shaneutt
approved these changes
Nov 3, 2026
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.
What
Close the downstream connection after any final non-2xx response to CONNECT. In
prepare_response_header, this adds anelse ifto the CONNECT 2xx branch that callsset_keepalive(None)before theConnectionheader value is chosen. A 403/407 to CONNECT is now always sent withConnection: close, andreuse()returnsNone.Follow-up to #7. The review is on that PR.
Why
#7 keeps early tunnel bytes (bytes the client sends after the CONNECT head, before the response) out of the next request, but only when they arrive in a later read. The idle branch of
read_body_or_idlestashes them and turns keepalive off.When those bytes arrive in the same read as the CONNECT head,
init_content_length_owned(0, preread_body)puts them in overread, and the stash never runs. Keepalive stays on, and on a refusal with pipelining enabled,reuse()passes the overread to the next session aspipelined_prefix:A front end that treats bytes after a CONNECT as opaque tunnel data would see them parsed here as an HTTP request. Without pipelining (the default),
reuse()already closes because of the overread, but the refusal still saidConnection: keep-alive.Turning keepalive off for every refused CONNECT makes the existing comment ("A refused CONNECT closes the connection") true no matter how the bytes were read. The cost is one new connection for a client that retries after a 407, which a client sees
Connection: closefor anyway.Testing
same_read_early_bytes_close_a_refused_connect: same read +set_pipelining_enabled(true)+ 407, asserts!will_keepalive()andreuse()isNone. It fails without the fix.cargo test -p quixotic-plecostomus-core --lib: 587 passed.cargo test -p quixotic-plecostomus-proxy --lib: 77 passed.--test test_basic connect: 12 passed.cargo fmt --all -- --checkandcargo clippy -p quixotic-plecostomus-core --all-targets -- -D warnings: clean.Assisted-By: Claude Code