fix(http2): bound peer-controlled streams and headers (#1958)

SETTINGS_MAX_CONCURRENT_STREAMS was only consulted when this endpoint created local streams. A peer could ignore the advertised setting and open unbounded streams, allocating stream state, queues, windows, and controllers.

Enforce the configured peer-initiated stream limit locally before creating Http2StreamImpl. Track active peer streams and locally bound reserved PUSH_PROMISE streams as well. Reject excess streams with RST_STREAM REFUSED_STREAM without publishing them through incomingStreams or peerPushes.

Once the peer has acknowledged the advertised stream limit, terminate the connection with GOAWAY ENHANCE_YOUR_CALM after the configured number of consecutive violations. Excess streams received before acknowledgement are still refused but do not count toward the abuse threshold. Disabled server push is also enforced on receipt instead of relying on peer compliance or SETTINGS acknowledgement.

Inbound HEADERS and CONTINUATION fragments were accumulated without a size or time bound. Each continuation copied the preceding block again, making fragmented field-block assembly quadratic. HPACK also retained the complete decoded header list before application-level limits could run.

Add the following secure defaults per connection:

- 100 peer-initiated streams
- 16 KiB compressed field block
- 8 KiB decoded field section
- 16 CONTINUATION frames per field block
- 10 second absolute field-block timeout
- 8 consecutive post-acknowledgement stream-limit violations

Start the field-block timer when the initial HEADERS or PUSH_PROMISE frame header is parsed, before its payload is complete. Retain fragments as chunks and combine them once, enforcing compressed-size and CONTINUATION-count limits while the block is received.

Enforce the decoded field-section limit during HPACK processing using name length + value length + 32 bytes per field. Once the limit is crossed, release retained application-visible headers and continue decoding in discard mode so dynamic-table updates remain synchronized.

Reject a completely decoded oversized field section with RST_STREAM ENHANCE_YOUR_CALM and do not publish its headers. Compressed-size, CONTINUATION-count, and timeout violations terminate the connection with GOAWAY ENHANCE_YOUR_CALM because the shared HPACK context cannot safely continue without complete decompression. Invalid HPACK encoding terminates the connection with COMPRESSION_ERROR.

Advertise SETTINGS_MAX_HEADER_LIST_SIZE while enforcing the configured limit locally because the setting is advisory. This also resolves the unbounded buffering TODO introduced by fdaeafb.

Tests cover ACK-independent stream admission, pre-ACK rejection without abuse counting, post-ACK repeated abuse, exact N and N+1 limits, active and reserved stream recovery, disabled push, compressed and decoded size boundaries, many continuations, slow initial payloads, Huffman and indexed amplification, HPACK dynamic-table synchronization, HEADERS, trailers, and PUSH_PROMISE.

RFC 9113 sections 4.3, 5.1.2, 6.5.2, and 10.5:

https://www.rfc-editor.org/rfc/rfc9113.html

CERT/CC VU#421644:

https://kb.cert.org/vuls/id/421644
14 files changed
tree: 7a05da9ea68aaeacb4725e1caf09bc5a14b71bde
  1. .gemini/
  2. .github/
  3. pkgs/
  4. tool/
  5. .gitattributes
  6. .gitignore
  7. analysis_options.yaml
  8. CONTRIBUTING.md
  9. LICENSE
  10. mono_repo.yaml
  11. README.md
README.md

Build Status

A composable, Future-based library for making HTTP requests.

package:http contains a set of high-level functions and classes that make it easy to consume HTTP resources. It's multi-platform, and supports mobile, desktop, and the browser.

Packages

PackageDescriptionVersion
cronet_httpAn Android Flutter plugin that provides access to the Cronet HTTP client.pub package
cupertino_httpA macOS/iOS Flutter plugin that provides access to the Foundation URL Loading System.pub package
flutter_http_exampleAn Flutter app that demonstrates how to configure and use package:http.—
httpA composable, multi-platform, Future-based API for HTTP requests.pub package
http2A HTTP/2 implementation in Dart.pub package
http_client_conformance_testsA library that tests whether implementations of package:http's Client class behave as expected.
http_multi_serverA dart:io HttpServer wrapper that handles requests from multiple servers.pub package
http_parserA platform-independent package for parsing and serializing HTTP formats.pub package
http_profileA library used by HTTP client authors to integrate with the DevTools Network View.pub package
ok_httpAn Android Flutter plugin that provides access to the OkHttp HTTP client and the OkHttp WebSocket API.pub package
web_socketAny easy-to-use library for communicating with WebSockets that has multiple implementations.pub package
web_socket_channelStreamChannel wrappers for WebSockets. Provides a cross-platform WebSocketChannel API.package issues
web_socket_conformance_testsA library that tests whether implementations of package:web_socket's WebSocket class behave as expected.

Contributing

If you'd like to contribute to any of these packages, see the Contributing Guide.