Skip to content

fix(http2): validate Host vs :authority, client PUSH_PROMISE, and closed-stream HEADERS - #2109

Open
mosuem wants to merge 1 commit into
mosum/http2-6o-harden-http2-clientfrom
mosum/http2-6p-rfc9113-host-push-and-closed-headers
Open

mosuem wants to merge 1 commit into
mosum/http2-6o-harden-http2-clientfrom
mosum/http2-6p-rfc9113-host-push-and-closed-headers

Conversation

@mosuem

@mosuem mosuem commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Note

This PR was generated by an AI coding agent (Jetski) on behalf of @mosuem.

Summary

Running httpwg-cli (bearcove/loona's RFC 9113 conformance suite) against package:http2 surfaced three remaining RFC 9113 conformance and security issues not covered by h2spec:

  1. Host vs. :authority mismatch (H2.Host smuggling, RFC 9113 §8.3.1): A request carrying both :authority and a host header identifying a different authority (or duplicate host headers, or userinfo @) was accepted instead of rejected with RST_STREAM(PROTOCOL_ERROR), creating a routing/origin mismatch if translated to HTTP/1.1 downstream.
  2. Incomplete client PUSH_PROMISE buffered on servers (RFC 9113 §8.4): When a client sent a PUSH_PROMISE frame without END_HEADERS, Connection._handleFrameImpl passed it into FrameDefragmenter before checking !isClientConnection, buffering fragments until inboundHeaderBlockTimeout instead of immediately terminating with GOAWAY(PROTOCOL_ERROR).
  3. HEADERS on an already-closed stream reported PROTOCOL_ERROR instead of STREAM_CLOSED (RFC 9113 §5.1): Re-sending HEADERS on a previously opened and closed stream ID (<= lastRemoteStreamId) fell through _registerNewRemoteStreamId's generic PROTOCOL_ERROR check instead of returning GOAWAY(STREAM_CLOSED).

With this PR, httpwg-cli passes 106 / 107 RFC 9113 tests (up from 57 / 107 in 3.1.0 and 102 / 107 on #2108; the single remaining test is unsolicited PING(ACK), which PingHandler intentionally treats as PROTOCOL_ERROR per ping_handler_test.dart).

Why this is right

  • RFC 9113 §8.3.1 & RFC 3986 §6.2.3:

    ":authority" MUST NOT include the deprecated userinfo subcomponent for "http" or "https" schemed URIs.
    [...]
    A server SHOULD treat a request as malformed if it contains a Host header field that identifies an entity that differs from the entity in the ":authority" pseudo-header field. The values of fields need to be normalized to compare them (see Section 6.2 of [RFC3986]). An origin server can apply any normalization method, whereas other servers MUST perform scheme-based normalization (see Section 6.2.3 of [RFC3986]) of the two fields.

  • RFC 9113 §8.4:

    A client cannot push. Thus, servers MUST treat the receipt of a PUSH_PROMISE frame as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.

  • RFC 9113 §5.1 vs. §5.1.1:
    • Receiving HEADERS on a stream that transitioned to closed is a connection error of type STREAM_CLOSED (§5.1).
    • Receiving HEADERS on a lower unused stream ID that was implicitly skipped when a higher stream ID opened remains a connection error of type PROTOCOL_ERROR (§5.1.1).

Changes

  • lib/src/streams/http_message_validator.dart
    • Reject host in trailers, duplicate host headers, userinfo (@) in host or http(s) :authority, and requests where scheme-normalized host disagrees with :authority.
  • lib/src/connection.dart
    • Reject PushPromiseFrame on server connections before _defragmenter.tryDefragmentFrame, and map ConnectionStreamClosedException to GOAWAY(STREAM_CLOSED).
  • lib/src/sync_errors.dart, lib/src/streams/stream_handler.dart
    • Track a bounded 256-entry LinkedHashSet of recently opened remote stream IDs so HEADERS on an already-closed stream raises ConnectionStreamClosedException (STREAM_CLOSED) while skipped lower stream IDs continue to raise ProtocolException (PROTOCOL_ERROR).
  • test/server_test.dart, CHANGELOG.md
    • Add 4 server tests and 3.2.1-wip changelog entry.

Test Verification (Fails Before → Passes After)

Before fix:

00:00 +0 -1: server-tests resource limits rejects mismatched or duplicate host headers while allowing normalized matches [E]
  Expected: <Instance of 'RstStreamFrame'> with `header.streamId`: <1> and `errorCode`: <1>
    Actual: <Instance of 'PingFrame'>

00:00 +0 -1: server-tests resource limits rejects incomplete client PUSH_PROMISE immediately with PROTOCOL_ERROR [E]
  Expected: true
    Actual: <false>

00:00 +0 -1: server-tests resource limits distinguishes HEADERS on a closed stream (STREAM_CLOSED) from a skipped lower stream ID (PROTOCOL_ERROR) [E]
  Expected: <Instance of 'GoawayFrame'> with `errorCode`: <5>
    Actual: <Instance of 'GoawayFrame'>
     Which: has `errorCode` with value <1>

After fix:

00:00 +4: All tests passed!
  • Full package:http2 suite: +307 ~7: All tests passed! (dart format and dart analyze --fatal-infos are clean.)
  • httpwg-cli: Passed 106/107 tests in 0.34 seconds!

Stack

Stacked on #2108. Followed by optional draft #2110 and #2111 (prepare to release 3.2.1).

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

PR Health

Publish ✔️
Package Version Status Publish tag (post-merge)
package:http2 ⭐ 3.2.1-wip WIP (no publish necessary)
  • 1 already published.
  • 8 WIP (no publish necessary).

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

This check can be disabled by tagging the PR with skip-publish-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check (for example, for non-user-visible changes when the package version is already at -wip).

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
http2 None 3.2.0 3.2.1-wip 3.2.1-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Unused Dependencies ✔️
Package Status
http2 ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/http_multi_server/test/cert.dart

This check can be disabled by tagging the PR with skip-license-check.

Coverage ✔️
File Coverage
pkgs/http2/lib/src/connection.dart 💚 88 % ⬆️ 0 %
pkgs/http2/lib/src/streams/http_message_validator.dart 💚 96 % ⬆️ 1 %
pkgs/http2/lib/src/streams/stream_handler.dart 💚 90 % ⬆️ 0 %
pkgs/http2/lib/src/sync_errors.dart 💚 71 % ⬆️ 4 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch 4 times, most recently from c5cc703 to b4d4025 Compare November 17, 2026 10:48
@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch from b4d4025 to 852498a Compare November 17, 2026 10:58
@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch 2 times, most recently from 080f7f8 to f868801 Compare November 18, 2026 11:19
@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch 3 times, most recently from d9a5e89 to 6c960e6 Compare November 18, 2026 12:58
@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch from 6c960e6 to 6a758b1 Compare November 18, 2026 13:57
@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch 2 times, most recently from db9e194 to e1def35 Compare November 18, 2026 14:24
@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch 3 times, most recently from 892627c to 6ec35bc Compare November 19, 2026 11:19
…sed-stream HEADERS

Address three RFC 9113 conformance and security issues uncovered by
`httpwg-cli`:
- Reject `host` in trailers, duplicate `host` headers, userinfo (`@`)
  in `host` or `http(s)` `:authority`, and `host` vs. `:authority`
  mismatches after RFC 3986 §6.2.3 scheme-based normalization
  (RFC 9113 §8.3.1, `H2.Host` request smuggling).
- Reject `PUSH_PROMISE` frames on server connections before header
  defragmentation so incomplete client `PUSH_PROMISE` frames fail
  immediately with `GOAWAY(PROTOCOL_ERROR)` (RFC 9113 §8.4).
- Track recently opened remote stream IDs so `HEADERS` received on an
  already-closed stream reports `GOAWAY(STREAM_CLOSED)` (RFC 9113 §5.1)
  while skipped lower stream IDs continue to report `PROTOCOL_ERROR`
  (RFC 9113 §5.1.1).
@mosuem
mosuem force-pushed the mosum/http2-6p-rfc9113-host-push-and-closed-headers branch from 6ec35bc to b3f1595 Compare November 20, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant