From 11ae3ce4a5f7b64eba9b1ef0a88d6a04022a3e63 Mon Sep 17 00:00:00 2001 From: retoor Date: Sun, 25 Oct 2026 20:06:37 +0100 Subject: [PATCH] fix(runtime): cap CONTINUATION frame count per header block (MOLO-H2-003) kH2HeaderListMax only bounded accumulated header bytes across HEADERS plus CONTINUATION frames, so an attacker could flood zero-length CONTINUATION frames on an open header block (CVE-2024-27316 class) forever without tripping the byte cap, each still costing a 9-byte frame parse. Add an independent kH2MaxContinuationFramesPerHeaderBlock cap in caps.h and enforce it in H2Connection::OnContinuation, closing the connection via the same Fatal(kCompressionError) GOAWAY path already used for the byte cap. Co-Authored-By: Claude Sonnet 5 --- src/runtime/caps.h | 4 ++++ src/runtime/http/v2/connection.cpp | 8 ++++++++ src/runtime/http/v2/connection.h | 3 +++ 3 files changed, 15 insertions(+) diff --git a/src/runtime/caps.h b/src/runtime/caps.h index cba18e2..e08bff2 100644 --- a/src/runtime/caps.h +++ b/src/runtime/caps.h @@ -57,6 +57,10 @@ inline constexpr std::size_t kH2HeaderTableDefault = 4096; inline constexpr std::size_t kH2HeaderTableCeiling = 16384; inline constexpr std::size_t kH2HeaderListMax = 65536; inline constexpr std::size_t kH2MaxFrameHeaderListCap = 100; +// Independent of kH2HeaderListMax (bytes): caps CONTINUATION frame *count* +// for one open header block, so a flood of zero-length CONTINUATION frames +// (near-zero byte growth) cannot evade the byte cap. CVE-2024-27316 class. +inline constexpr std::size_t kH2MaxContinuationFramesPerHeaderBlock = 64; // 6.5 Compression. inline constexpr std::size_t kCompressThreshold = 1024; diff --git a/src/runtime/http/v2/connection.cpp b/src/runtime/http/v2/connection.cpp index 9b6a956..fe72c72 100644 --- a/src/runtime/http/v2/connection.cpp +++ b/src/runtime/http/v2/connection.cpp @@ -406,6 +406,7 @@ bool H2Connection::OnHeaders(const Frame& fr, const char* payload) { cont_stream_ = fr.stream_id; cont_buf_.assign(payload + off, len); cont_end_stream_ = end_stream; + cont_frame_count_ = 0; return true; } return FinishHeaders(fr.stream_id, std::string(payload + off, len), @@ -461,6 +462,13 @@ bool H2Connection::OnContinuation(const Frame& fr, const char* payload) { Fatal(kCompressionError); return false; } + // Independent of the byte cap above: bounds the number of CONTINUATION + // frames for one header block, so a flood of zero-length frames (which + // never trips the byte cap) still gets cut off. CVE-2024-27316 class. + if (++cont_frame_count_ > caps::kH2MaxContinuationFramesPerHeaderBlock) { + Fatal(kCompressionError); + return false; + } cont_buf_.append(payload, fr.length); if (!(fr.flags & kFlagEndHeaders)) return true; cont_expected_ = false; diff --git a/src/runtime/http/v2/connection.h b/src/runtime/http/v2/connection.h index 71c167c..69c24ce 100644 --- a/src/runtime/http/v2/connection.h +++ b/src/runtime/http/v2/connection.h @@ -145,6 +145,9 @@ class H2Connection : public std::enable_shared_from_this { uint32_t cont_stream_ = 0; std::string cont_buf_; bool cont_end_stream_ = false; + // Count of CONTINUATION frames seen for the currently open header block; + // independent of cont_buf_'s byte size. See kH2MaxContinuationFramesPerHeaderBlock. + std::size_t cont_frame_count_ = 0; std::coroutine_handle<> window_waiter_ = nullptr; std::coroutine_handle<> writer_done_waiter_ = nullptr; };