{{ message }}
feat(http1): add max_header_size limit for server and client - #4183
Open
Aditya-9-6 wants to merge 1 commit into
Open
feat(http1): add max_header_size limit for server and client#4183Aditya-9-6 wants to merge 1 commit into
Aditya-9-6 wants to merge 1 commit into
Conversation
Adds max_header_size(val: usize) on both server and client HTTP/1 builders. This allows configuring an explicit byte limit for request/response headers (including the start line and chunked trailers). When the limit is exceeded: - On server: responds with 431 Request Header Fields Too Large and closes the connection. - On client: returns a Parse::TooLarge error (is_parse_too_large). - On chunked decoder: replaces existing TODO in proto/h1/conn.rs with the configured h1_max_header_size. Closes hyperium#3832.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Motivation
Resolves #3832.
Currently, HTTP/1 header size limits can only be indirectly bounded using
max_buf_size. However, settingmax_buf_sizealso restricts the maximum single read buffer for streaming request or response bodies. Furthermore, there was an existing TODO inproto/h1/conn.rsnoting thath1_max_header_sizeshould be wired up to the chunked decoder for trailers.This PR adds explicit
max_header_size(bytes)configuration options to bothserver::conn::http1::Builderandclient::conn::http1::Builder.Solution & Architecture
server::conn::http1::Builder):pub fn max_header_size(&mut self, val: usize) -> &mut Self.431 Request Header Fields Too Large(RFC 6585 §5) and closes the connection.client::conn::http1::Builder):pub fn max_header_size(&mut self, val: usize) -> &mut Self.error.is_parse_too_large() == true.io::Buffered::parse_headersas bytes are read, preventing buffering unbounded amounts of header data.Server::parse/Client::parseagainstparsed_lento protect scenarios where a single read buffer already contains subsequent data.// TODO: remove this when we land h1_max_header_size supportplaceholder inproto::h1::conn.rs(decode::Decoder::new) with the configuredh1_max_header_size.Verification
src/proto/h1/role.rs:test_h1_max_header_size: Tests exact boundary conditions on both server and client parsers.tests/server.rs:max_header_size_exceeded: Verifies server returns431 Request Header Fields Too Largewhen request header size exceeds limit.max_header_size_accepted: Verifies server accepts requests when within limit.max_header_size_with_large_max_buf_size: Verifiesmax_header_sizeenforcement is decoupled from and strictly enforced even whenmax_buf_sizeis large.tests/client.rs:client_max_header_size_exceeded: Verifies client errors withis_parse_too_large() == true.client_max_header_size_accepted: Verifies client successfully receives responses within limit.cargo test --lib --features full,cargo test --test server --features full,cargo test --test client --features full).