Skip to content

fix(http2): harden Http2Client request/response validation and unread body backpressure - #2108

Open
mosuem wants to merge 1 commit into
mosum/http2-6n-validate-hpack-and-http-headersfrom
mosum/http2-6o-harden-http2-client
Open

mosuem wants to merge 1 commit into
mosum/http2-6n-validate-hpack-and-http-headersfrom
mosum/http2-6o-harden-http2-client

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

Hardens Http2Client (package:http2/client.dart) across four areas:

  1. Outbound request validation & IPv6 :authority bracketing: Validates URL authority, HTTP method token, and request header names/values before dialing (rejecting :-prefixed pseudo-header injection, CR/LF/NUL/CTLs, and te values other than trailers, and stripping fields nominated by Connection), and encloses IPv6 literals in square brackets ([::1]:port) in :authority and pool keys.
  2. Response header state machine: Requires a valid 3-digit :status (100..599, excluding 101), ignores 1xx informational headers instead of merging them into StreamedResponse.headers, ignores trailing HEADERS instead of mutating responseHeaders, rejects DATA arriving before :status, and resets the stream on protocol errors.
  3. Unread response-body backpressure: Pauses the underlying stream subscription as soon as final response headers arrive until response.stream is listened to, preventing an unread StreamedResponse from auto-granting WINDOW_UPDATEs up to 4 MiB and buffering unbounded DATA inside bodyController.
  4. Full-connection liveness (ClientConnection.isAlive): Distinguishes a dead/finishing connection from one that is merely at its SETTINGS_MAX_CONCURRENT_STREAMS capacity so a single-stream RST_STREAM on a full connection does not poison and evict the connection from ClientPool.

Why this is right

  • RFC 9113 §8.3.1 & RFC 3986 §3.2.2: :authority uses URI host [ ":" port ] syntax, where IPv6 literals MUST be enclosed in [ and ] (whereas Dart's Uri.host returns bare ::1 without brackets).
  • RFC 9113 §8.1, §8.3.2, & RFC 9110 §15.2: Every HTTP/2 response header block MUST include :status; 1xx responses are interim and do not carry final response header fields; DATA frames MUST NOT precede the final response header section.
  • RFC 9113 §5.2 & §5.4.2: Flow-control credit (WINDOW_UPDATE) should only advance as the receiver consumes data, and a stream error (RST_STREAM) affects only that stream, not healthy sibling streams on a full connection.

Changes

  • lib/src/http2_client.dart — Outbound header/URL/IPv6 validation, strict response state machine, unread-body subscription pause until onListen, and !connection.isAlive check.
  • lib/src/connection.dart, test/pool_mocks.mocks.dart — Add ClientConnection.isAlive.
  • test/http2_client_test.dart, CHANGELOG.md — Add four end-to-end TLS tests and 3.2.1-wip changelog entry.

Test Verification (Fails Before → Passes After)

Before fix:

00:00 +0 -1: http2-client-test validates-outbound-headers-and-brackets-ipv6-authority [E]
  Expected: '[::1]:34885'
    Actual: '::1:34885'

00:00 +0 -1: http2-client-test rejects-missing-status-and-data-before-headers-and-ignores-1xx-headers [E]
  Expected: null
    Actual: 'hint'

00:00 +0 -1: http2-client-test does-not-grant-credit-for-unread-response-body [E]
  The client granted 393216 bytes of credit before response.stream was listened to.

00:00 +0 -1: http2-client-test stream-reset-on-full-connection-keeps-connection-healthy [E]
  Expected: <1>
    Actual: <2>

After fix:

00:00 +4: All tests passed!

Full package:http2 suite at this point of the stack: +303 ~7: All tests passed! (dart format and dart analyze --fatal-infos are clean.)

Stack

Stacked on #2107. Followed by #2109, 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/http2_client.dart 💔 86 % ⬇️ 3 %

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-6o-harden-http2-client branch 4 times, most recently from 9ab395a to 60b9a13 Compare November 17, 2026 10:48
@mosuem
mosuem force-pushed the mosum/http2-6o-harden-http2-client branch 2 times, most recently from acb7cd6 to 28d2a01 Compare November 17, 2026 13:54
@mosuem
mosuem force-pushed the mosum/http2-6o-harden-http2-client branch 2 times, most recently from 185389e to cb11393 Compare November 18, 2026 12:43
@mosuem
mosuem force-pushed the mosum/http2-6o-harden-http2-client branch from cb11393 to 6cf77bf Compare November 18, 2026 12:53
@mosuem
mosuem force-pushed the mosum/http2-6o-harden-http2-client branch from 6cf77bf to 4e75e5e Compare November 18, 2026 12:58
@mosuem
mosuem force-pushed the mosum/http2-6o-harden-http2-client branch 2 times, most recently from c3907ff to b23e2dc Compare November 18, 2026 14:11
@mosuem
mosuem force-pushed the mosum/http2-6o-harden-http2-client branch 4 times, most recently from 05cce28 to 0b4df9c Compare November 19, 2026 11:19
… body backpressure

Validate outbound request URLs, methods, and headers before dialing and
bracket IPv6 literals in :authority (RFC 9113 §8.3.1, RFC 3986 §3.2.2);
require a valid :status response header, ignore 1xx and trailer headers
when building StreamedResponse.headers, reject DATA before :status, and
pause unread response bodies until listened to; and keep full pooled
connections alive across single-stream resets.
@mosuem
mosuem force-pushed the mosum/http2-6o-harden-http2-client branch from 0b4df9c to 24f2332 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