Add middleware for header count and header list item limits in limits plugin #8285
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.
Overview
Expands the middleware functionality in the limits plugin to include two new header-based request limits, building on the foundation established in PR #8269.
New Features
1. Request Header Count Limit
Adds
http_max_request_headersconfiguration to limit the total number of headers in an HTTP request:2. Header List Items Limit
Adds
http_max_header_list_itemsconfiguration to limit the number of values within individual header fields:Both limits are opt-in (when not specified, no limit is enforced) and respond with
431 Request Header Fields Too Largewhen exceeded.Implementation Details
Middleware Architecture
RequestHeaderCountLimitLayer: Enforced at the middleware level, counts total headers per requestRequestHeaderListItemsLimitLayer: Counts individual values within each header field (e.g.,Accept: json, xml, html= 3 items)Error Response Format
When limits are exceeded, returns standard GraphQL error format:
{ "errors": [ { "message": "Request header fields too many", "extensions": { "details": "Request header fields too many", "code": "INVALID_GRAPHQL_REQUEST" } } ] }Distinction from Server-Level Limits
These middleware-level limits complement existing server-level configuration (
server.http.max_headers):Testing
Documentation
Updated
docs/source/routing/security/request-limits.mdxwith:Backward Compatibility
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
esm.ubuntu.com/usr/lib/apt/methods/https(dns block)If you need me to access, download, or install something from one of these locations, you can either:
This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.