diff --git a/src/runtime/caps.h b/src/runtime/caps.h index cba18e2..df82308 100644 --- a/src/runtime/caps.h +++ b/src/runtime/caps.h @@ -36,6 +36,10 @@ inline constexpr std::size_t kMaxConnectionsCeiling = 65536; inline constexpr std::size_t kMaxRequestsPerH1Connection = 1000; inline constexpr std::size_t kH2MaxConcurrentStreamsDefault = 100; inline constexpr std::size_t kH2MaxConcurrentStreamsCeiling = 1000; +// Rapid Reset (CVE-2023-44487 class) mitigation: a single connection may not +// open-then-reset more streams than this over its lifetime. Exceeding it is +// a fatal, GOAWAY-closed connection error (see H2Connection::OnRst). +inline constexpr std::size_t kH2MaxStreamResetsPerConnection = 200; inline constexpr std::size_t kHeaderBlockMax = 65536; inline constexpr std::size_t kHeaderFieldMax = 100; inline constexpr std::size_t kHeaderLineMax = 16384; diff --git a/src/runtime/http/v2/connection.cpp b/src/runtime/http/v2/connection.cpp index 9b6a956..24bc73d 100644 --- a/src/runtime/http/v2/connection.cpp +++ b/src/runtime/http/v2/connection.cpp @@ -39,6 +39,7 @@ constexpr uint32_t kFrameSizeError = 0x6; constexpr uint32_t kRefusedStream = 0x7; constexpr uint32_t kCancel = 0x8; constexpr uint32_t kCompressionError = 0x9; +constexpr uint32_t kEnhanceYourCalm = 0xb; bool IsH2HopHeader(std::string_view name) { return EqCaseInsensitive(name, "connection") || @@ -541,6 +542,17 @@ bool H2Connection::OnRst(const Frame& fr, const char* payload) { Fatal(kFrameSizeError); return false; } + // Rapid Reset (CVE-2023-44487 class): unbounded open-then-reset churn + // never counts against max_concurrent_streams because the stream is + // gone before the next HEADERS arrives (the dispatch already happened, + // win or lose, whether or not the stream is still tracked here by the + // time this RST_STREAM is parsed). Cap the lifetime count of client + // RST_STREAM frames instead, and close the connection the same way + // other protocol-limit violations in this file are closed. + if (++client_resets_ > caps::kH2MaxStreamResetsPerConnection) { + Fatal(kEnhanceYourCalm); + return false; + } auto it = streams_.find(fr.stream_id); if (it == streams_.end()) return true; // idle or closed: ignore uint32_t code = ((uint32_t)(unsigned char)payload[0] << 24) | diff --git a/src/runtime/http/v2/connection.h b/src/runtime/http/v2/connection.h index 71c167c..8a824ce 100644 --- a/src/runtime/http/v2/connection.h +++ b/src/runtime/http/v2/connection.h @@ -140,6 +140,9 @@ class H2Connection : public std::enable_shared_from_this { bool fatal_ = false; uint32_t max_stream_id_ = 0; std::size_t requests_ = 0; + // Rapid Reset guard: client-initiated RST_STREAM count over the + // connection's lifetime (see caps::kH2MaxStreamResetsPerConnection). + std::size_t client_resets_ = 0; // CONTINUATION reassembly state. bool cont_expected_ = false; uint32_t cont_stream_ = 0;