Skip to content

fix: tighten HTTP/1.1, HTTP/2, HTTP/3 and WebSocket compliance - #136

Open
Antruly wants to merge 14 commits into
masterfrom
fix/compliance-1.14
Open

Antruly wants to merge 14 commits into
masterfrom
fix/compliance-1.14

Conversation

@Antruly

@Antruly Antruly commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

What

Tighten protocol handling found by the HttpArena compliance run.

HTTP/1.1

  • Reject RFC 9112 obs-fold continuation lines in the parser (return 400 and close).
  • Handle * request-target: OPTIONS * -> 204, other methods -> 400.
  • Reject CONNECT to an origin server with 405 instead of routing its authority as a path.

HTTP/2

  • Observe frame headers before nghttp2_session_mem_recv2 and answer frames on closed streams at the wire layer with RST_STREAM(STREAM_CLOSED).
  • Handle HEADERS on a closed stream as a connection error.
  • Reject decreasing new stream ids, invalid PING and peer GOAWAY with the required connection behavior.
  • Emit RST_STREAM(FLOW_CONTROL_ERROR) before the session's GOAWAY when WINDOW_UPDATE overflows.

HTTP/3

  • Reject a ClientHello without quic_transport_parameters and answer a TLS alert without ALPN overlap with no_application_protocol.
  • Report the FIN of a peer unidirectional stream when the type byte and FIN arrive in the same read, so a closed QPACK decoder/encoder or control stream ends the connection with H3_CLOSED_CRITICAL_STREAM.
  • Validate control-stream frames per RFC 9114: duplicate SETTINGS identifiers (H3_SETTINGS_ERROR), CANCEL_PUSH for an unallowed push id (H3_ID_ERROR), a decreasing MAX_PUSH_ID (H3_ID_ERROR), trailing octets after MAX_PUSH_ID (H3_FRAME_ERROR), and a control frame larger than 1 MiB (H3_EXCESSIVE_LOAD). These five checks live in the nghttp3 copy under the build tree; NGHTTP3_VERSION still points at the upstream tag and nghttp3's public header/ABI is unchanged.

WebSocket

  • Reject a one-byte CLOSE payload, invalid close codes and non-UTF-8 close reasons.
  • Preserve an empty CLOSE payload instead of echoing the local 1005 placeholder.
  • Stop parsing/delivering frames after CLOSE is received.

Evidence

Built the exact 1.13.2-dev tree with the HttpArena entry recipe and ran the suites against the built image:

  • h2spec 2.6.0: 146/146 passed (TLS listener; was 134/146).
  • Raw HTTP/1 probes: obs-fold 400, GET * 400, OPTIONS * 204, CONNECT 405.
  • Raw WebSocket close probes: code 999 -> Close 1002, length 1 -> Close 1002, empty -> empty Close.
  • h3spec 0.1.15: 86 examples, 0 failures, 1 pending (0-RTT not run); the server stayed up for the whole suite. The five control-stream cases fail 8 assertions against the unpatched nghttp3 copy and pass with the patch.
  • web_app_h3_http_func: five real-QUIC regressions for the close codes above, plus the critical-stream FIN case.
  • ctest on the HTTP/3-enabled Release tree: 165 passed, 2 skipped (Redis unavailable), 1 environment-blocked (test_web_http_server_func needs 127.0.0.1:20001, occupied by an unrelated local service; the test passes in an isolated network namespace).

Commit author: zhuweiye <61441059+Antruly@users.noreply.github.com>

HTTP/1.1: reject RFC 9112 obs-fold and handle asterisk-form/CONNECT targets. WebSocket: validate close codes, reason UTF-8 and empty close payloads; ignore frames after Close.
Track streams closed by nghttp2, inspect frame headers before recv, and answer STREAM_CLOSED/FLOW_CONTROL_ERROR at the raw layer. Close on invalid PING and peer GOAWAY; preserve the existing h2 session path for normal traffic.
OpenSSL 3.5's QUIC TLS registers quic_transport_parameters as a custom
extension, so a ClientHello without it is accepted and the handshake is
reported complete. On the server, ngtcp2's negotiated_version is only set
from conn_recv_transport_params; it therefore stays 0 while 1-RTT tx keys
are already installed, and the next write hits
assert(conn->negotiated_version) in conn_write_pkt and aborts the
process. That is the "server crashed during the suite" h3spec result.

RFC 9001 8.2 requires aborting such a handshake with the TLS alert
missing_extension. Add a ClientHello callback on the server SSL_CTX that
checks the extension, marks QUIC sessions through SSL ex_data so TLS over
TCP on the same context is untouched, and returns
SSL_CLIENT_HELLO_ERROR with SSL_AD_MISSING_EXTENSION. Also carry the TLS
alert into CONNECTION_CLOSE: handle_conn_error now builds
CRYPTO_ERROR | alert from ngtcp2_conn_get_tls_alert2 instead of collapsing
a TLS failure into PROTOCOL_VIOLATION.

Regression evidence (h3spec 0.1.15, min H3 server, self-signed cert, -n):
- pre-fix: the single missing_extension test leaves the server dead with
  ngtcp2_conn.c:3618 conn_write_pkt assertion; full suite 37/81 with the
  crash cascading into 44 failures.
- post-fix: single test passes and the server stays up; full suite
  78 passed / 7 failed / 1 pending, 86 examples, exit at 20.6s with no
  crash (7 remaining failures are separate H3 error-code gaps).
- ctest -R 'quic|h3': 12/12 passed (Release, QUIC+HTTP3 build).
nghttp3's nghttp3_conn_read_uni() identifies a peer unidirectional
stream from the first varint and returns before looking at fin when the
type code is the last byte of that read.  The H3 connection marked the
FIN as delivered and never re-presented it, so a QPACK decoder/encoder
or control stream closed together with its type byte produced no
H3_CLOSED_CRITICAL_STREAM and the connection stayed up.

Deliver an explicit zero-length FIN for a fully consumed peer uni
stream after the data read.  Add an end-to-end regression: a raw QUIC
client opens a unidirectional stream, writes 0x03 with FIN, and the
server must close the connection with error 0x0104.

h3spec: decoder-stream-closed case now passes; suite 86 examples,
5 failures (was 6), 1 pending.
nghttp3 1.18 (and 1.19.0) accepts five control-stream violations that
h3spec 0.1.15 reports: a duplicate SETTINGS identifier, a CANCEL_PUSH for
a push ID that MAX_PUSH_ID never allowed, a decreasing MAX_PUSH_ID,
trailing octets after the MAX_PUSH_ID varint, and an unbounded control
frame length.

Patch the nghttp3 copy in the build tree; NGHTTP3_VERSION still points
at the upstream tag and nghttp3's public header/ABI is untouched.  Each
replacement carries a configure-time assertion so an upstream change to
those lines fails loudly instead of silently skipping the patch.

Add five end-to-end QUIC regressions to web_app_h3_http_func: they fail
8 checks against the unpatched library and pass with it.  h3spec 0.1.15:
86 examples, 0 failures, 1 pending.
@Antruly Antruly changed the title fix: tighten HTTP/1.1, HTTP/2 and WebSocket compliance fix: tighten HTTP/1.1, HTTP/2, HTTP/3 and WebSocket compliance Dec 4, 2026
Do not close the transport before nghttp2 records a peer GOAWAY; run the same raw preface sniff on the h2c feed path.
The raw frame observer treated response HEADERS on a client connection as
peer-opened streams. Out-of-order delayed responses then queued
GOAWAY(PROTOCOL_ERROR) and dropped the remaining responses (per_stream B).

After a valid peer GOAWAY with no active streams nghttp2 stops reading and
suppresses the PING ACK. A server must close the transport then, otherwise
h2spec 3.8.1 and 7.1 wait until timeout; clients must keep the connection
and their in-flight responses.
…AWAY

- h2c probe: classify the first line before falling back to HTTP/1. A line
  without an HTTP/<d>.<d> version marker is not a valid request line, so it
  goes back to nghttp2, which closes with GOAWAY(PROTOCOL_ERROR) instead of
  an HTTP/1 400 response (h2spec 3.5.2).
- session: NGHTTP2_ERR_BAD_CLIENT_MAGIC selects PROTOCOL_ERROR for the
  closing GOAWAY; nghttp2 only returns -903 and queues no frame itself.
- connection: after a fatal recv nghttp2 must not be called again, so the
  GOAWAY is built in the raw layer. After a peer GOAWAY the connection stays
  readable and a late PING is answered with a raw ACK, avoiding the TCP RST
  that an immediate close produced (h2spec generic 3.8.1, http2 7.1).
- tests: web_h2_cleartext_func gains an invalid-preface round and a
  GOAWAY-then-PING round.
- docs: refresh line references after the source insertions.

This branch has not been deployed

No deployments
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.

1 participant