Bound the number of http headers and query parameters per message - #3524
Open
chenBright wants to merge 1 commit into
Open
Bound the number of http headers and query parameters per message#3524chenBright wants to merge 1 commit into
chenBright wants to merge 1 commit into
Conversation
chenBright
force-pushed
the
fix_http_header_query
branch
from
September 5, 2026 16:55
b358a46 to
3d0c834
Compare
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.
What problem does this PR solve?
Issue Number: resolve
Problem Summary:
CaseIgnoredHasher(headers) andDefaultHasher(query map) are both plainresult = result * 101 + cwith no per-process seed, andFlatMappicks abucket by masking the low bits of the hash. An attacker only needs the low
log2(nbucket)bits to match, which is brute-forceable offline in seconds andreusable against every process, since nothing is seeded.
Both maps then degrade to a single chain:
on_header_value()callsGetOrAddHeader()for every field, so each headercosts a linear scan of the chain built so far. The cost is on the lookup side
and is paid unconditionally on the parse hot path.
URI::ParseQueries()inserts throughFlatMap::operator[], which walks thechain to dedup. The cost is on the insert side.
Either one turns a single request into O(n^2) work in the server's IO path.
Nothing bounded
n: h1 had no field-count limit at all, and h2'smax_header_list_sizebounds the decoded bytes of a header block, not thenumber of fields in it.
What is changed and the side effects?
Changed:
Tomcat's
maxHeaderCount, Envoy'smax_request_headers_count, PHP'smax_input_vars, Django'sDATA_UPLOAD_MAX_NUMBER_FIELDSandTomcat 11's
maxParameterCount, all of which were introduced as hashDoSmitigations.
Therefore, two flags are introduced to bound the number of http headers and
query parameters per message:
-http_max_header_count(default 100), checked inHttpMessage::on_header_value()for h1 and inH2StreamContext::ConsumeHeaders()afterAppendHeader()for h2.-http_max_query_count(default 1000), checked inURI::SetHttpURL()for h1and in
URI::SetH2Path()for h2. It counts&separators rather than mapentries: the splitter walks every segment even when the keys repeat, and it is
that walk the limit is meant to bound.
Setting flag to <= 0 lifts the limit.
Side effects:
Performance effects:
Breaking backward compatibility:
Check List: