Skip to content

connection: enforce status-written check before hijacking in QUIC (#1748) - #1766

Open
dedsec-terminal wants to merge 1 commit into
cloudflare:masterfrom
dedsec-terminal:fix/1748-quic-hijack-precondition
Open

dedsec-terminal wants to merge 1 commit into
cloudflare:masterfrom
dedsec-terminal:fix/1748-quic-hijack-precondition

Conversation

@dedsec-terminal

Copy link
Copy Markdown

Description

http.Hijacker preconditions differed between the HTTP/2 and QUIC transports:

  • In HTTP/2 (http2RespWriter.Hijack in connection/http2.go), Hijack() verifies that the response status was already written (rp.statusWritten) before returning the hijacked connection, returning an error (status not yet written before attempting to hijack connection) otherwise.
  • In QUIC (httpResponseAdapter.Hijack in connection/quic_connection.go), no precondition check existed, returning a connection even when connectResponseSent was still false. Furthermore, repeated Hijack() or post-hijack Write() calls did not return standard http.ErrHijacked.

This change aligns httpResponseAdapter with http2RespWriter:

  1. Requires connectResponseSent to be true before allowing Hijack(). If not yet written, it returns the same error: status not yet written before attempting to hijack connection.
  2. Tracks hijacked state under mutex protection.
  3. Subsequent Hijack() calls return http.ErrHijacked.
  4. Subsequent Write() calls return 0, http.ErrHijacked.
  5. Post-hijack WriteHeader() calls are safely ignored without attempting to write headers.

Testing & Reproduction

Added unit test TestHTTPResponseAdapter_Hijack in connection/quic_connection_test.go covering:

  • Verifying Hijack() fails with "status not yet written before attempting to hijack connection" before response status is sent.
  • Verifying Hijack() succeeds once response status is sent.
  • Verifying subsequent Hijack() calls return http.ErrHijacked.
  • Verifying subsequent Write() calls return 0, http.ErrHijacked.
  • Verifying WriteHeader() after hijack is a safe no-op.

All connection tests pass cleanly:

go test -v -run TestHTTPResponseAdapter_Hijack ./connection

Checked diff formatting with git diff --check.

Links

Closes #1748

…oudflare#1748)

Align httpResponseAdapter.Hijack precondition with http2RespWriter by requiring
status/response headers to be written prior to hijacking. Reject subsequent
Hijack and Write calls after hijacking with http.ErrHijacked.

Closes cloudflare#1748

Signed-off-by: dedsec-terminal <dedsec.terminal@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 14:54

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

🐛 QUIC Hijack() skips the status-written check that HTTP/2 enforces

2 participants