Guides
8 min readUpdated400 Bad Request: Request Header or Cookie Too Large (and HTTP 431)
Quick answer
"Request Header Or Cookie Too Large" is nginx's 400 Bad Request page for a request whose headers do not fit its buffers, usually because a site has piled up cookies. Other servers answer the same problem with 431 Request Header Fields Too Large. Visitors fix it by deleting that site's cookies. Owners should find which cookie grew, and why, before raising limits such as nginx's large_client_header_buffers, which defaults to four 8 KB buffers.
01What does Request Header or Cookie Too Large mean?
A browser sends every cookie that applies to a site in the Cookie header of every request, images and scripts included. nginx reads request headers into a 1 KB buffer and, when that is not enough, into up to four larger buffers of 8 KB each. A single header line must fit into one of them, and all headers together must fit into the four. When either rule is broken, nginx stops reading and answers with this page.
The standard status for the problem is 431 Request Header Fields Too Large, defined in RFC 6585, which may be used when the headers as a whole are too large or when one header is. nginx predates it and uses 400 with its own wording instead; internally it tracks the case as code 494. It is the same fault under three numbers, and it is one of the commonest reasons for a 400 Bad Request.
HTTP/1.1 400 Bad Request
Server: nginx/1.22.1
Content-Type: text/html
Connection: close
<head><title>400 Request Header Or Cookie Too Large</title></head>
<center><h1>400 Bad Request</h1></center>
<center>Request Header Or Cookie Too Large</center>02Default header and cookie limits by server and CDN
Limits differ by a factor of more than a hundred between products, which is why a request can pass the CDN and fail at the origin, or pass nginx and fail at the Node.js application behind it.
| Software | Default limit | Status and wording when exceeded |
|---|---|---|
| nginx | One header line up to 8 KB; all headers up to 4 × 8 KB (large_client_header_buffers 4 8k) | 400, Request Header Or Cookie Too Large (414 if the request line is too long) |
| Apache httpd | 8,190 bytes per header field (LimitRequestFieldSize), 100 fields (LimitRequestFields) | 400, Size of a request header field exceeds server limit |
| IIS (HTTP.sys) | 16,384 bytes per header (MaxFieldLength); 16,384 bytes for request line and headers (MaxRequestBytes) | 400, Request header too long |
| Node.js | 16 KB for all headers (--max-http-header-size) | 431, empty body |
| Go net/http | 1 MB (DefaultMaxHeaderBytes) | 431 Request Header Fields Too Large |
| Cloudflare | 128 KB for all request headers (32 KB in total and 16 KB per header until October 2025) | Rejected at the edge; Cloudflare's changelog names 413, and a 140 KB header in an October 2026 test had its connection reset |
| Amazon CloudFront | 32,768 bytes for request line, query string and headers together | 494 |
| Browsers (RFC 6265 minimum) | At least 4,096 bytes per cookie and 50 cookies per domain | Not an HTTP error: the browser stores them and keeps sending them |
03How cookies add up: a worked example
Consider a site that stores a single sign-on session as two cookies of 3,900 bytes each, while analytics and A/B testing tools add twelve cookies of about 150 bytes. Over HTTP/1.1 all of them travel in one Cookie header line: 2 × 3,900 + 12 × 150 = 9,600 bytes, before separators. That is more than the 8,192 bytes of one nginx buffer, so nginx rejects every request, even though each cookie is below the 4,096 bytes per cookie that RFC 6265 asks browsers to support.
The browser is not at fault: RFC 6265 asks it to store at least 50 cookies of 4,096 bytes for one domain, about 200 KB, far more than any server default accepts. The same RFC says servers should use as few and as small cookies as possible, which puts the fix on the site's side.
04How to fix it as a visitor
Delete the cookies for the affected site only, then reload. You will be signed out of that site, and nothing else changes.
- Chrome: click View site information to the left of the address, then Cookies and site data, then Manage on-device site data, and delete the site's entries; or go to Settings, Privacy and security, Third-party cookies, See all site data and permissions, search for the site and choose Delete
- Other browsers have the same per-site option in their privacy settings or in the panel behind the icon next to the address
- Open a private window to confirm the diagnosis: if the site loads there, cookies were the cause
- If the error returns within days, the site keeps adding cookies; tell its operator, because only they can fix it
06How to raise the limit in nginx, and where to put it
Raise the buffer size only once you know which header grew and that it is legitimate. Buffers are allocated on demand and released when the connection goes idle, so 16 KB costs nothing for ordinary requests, but every extra kilobyte is memory that a slow-header attack such as Slowloris can make each connection hold. The nginx DDoS hardening guide pairs these buffers with short header timeouts.
Placement matters. nginx documents that a value set in a server block may be overridden by the default server's value, and a test on nginx 1.22.1 showed what that means: a larger buffer in a name-based server worked when the Host header came before the Cookie header and failed when the Cookie came first, because nginx had not yet chosen the server. Set it in the http block, or in the default server of that address and port.
Optionally, replace the bare error page with one that tells visitors what to do. Mapping nginx's internal code 494 to 431 also gives monitoring the standard status. In the test, nginx 1.22.1 sent this 431 with an empty reason phrase, which HTTP permits.
Check every hop. If nginx forwards to a Node.js application, Node's 16 KB limit still applies, and the visitor gets a 431 from the upstream instead. Oversized response headers are a separate limit, proxy_buffer_size, which produces a 502 Bad Gateway instead.
# in the http block, or in the default_server for this address and port
large_client_header_buffers 4 16k;
server {
listen 80 default_server;
server_name _;
# 494 is nginx's internal code for "Request Header Or Cookie Too Large"
error_page 494 =431 @header_too_large;
location @header_too_large {
default_type text/html;
return 431 "<h1>Your browser sent too many or too large cookies</h1><p>Delete the cookies for this site and reload the page.</p>\n";
}
}07Apache, Node.js and IIS: where the limits live
- Apache httpd: LimitRequestFieldSize sets the bytes allowed per header (default 8,190) and LimitRequestFields the number of headers (default 100). With name-based virtual hosts the value is taken from the first virtual host for that address and port, and the log line AH00561 Request header exceeds LimitRequestFieldSize appears only at LogLevel info. Example, illustrative and not run here: LimitRequestFieldSize 16380
- Node.js: start the process with node --max-http-header-size=32768 server.js, or pass maxHeaderSize: 32768 to http.createServer; both raised the limit in a test on Node.js 22
- IIS: MaxFieldLength and MaxRequestBytes live under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters and take effect after the HTTP service restarts. Kerberos tokens grow with the number of Active Directory groups a user belongs to, and Microsoft suggests 4/3 of the token size plus 200 bytes for both values
- Behind a CDN, the edge limit must be at least as large as the origin's, or the edge rejects requests that the origin would accept
08How to stop cookies from growing back
- Scope cookies to the host that needs them: omit the Domain attribute instead of setting the parent domain, so they are not sent to every subdomain
- Keep session state on the server and send only an identifier, rather than a large signed token with many claims
- Give analytics and experiment cookies an expiry, and remove tags that nobody reads
- Watch for chunked authentication cookies, numbered parts of one large session, that multiply after each sign-in
- Large Negotiate (Kerberos) tokens in the Authorization header cause the same error on intranet sites; see 401 and authentication schemes
Questions
Frequently asked questions
Sources
Sources and verification
nginx 1.22.1 limits, page text, log lines, the Host-order behaviour of server-level buffers and the 431 error_page were reproduced in an isolated network namespace with curl 7.88.1; the Node.js 22 limit and both ways of raising it were tested the same way; the curl size probe was run against example.com, which is served through Cloudflare, plus one request with a 140 KB header. The Apache and IIS values are quoted from their documentation and were not run. Debian 12, October 2026.
- 01RFC 6585, section 5: 431 Request Header Fields Too Large · RFC Editor
- 02RFC 6265, HTTP State Management Mechanism, section 6.1: Limits · RFC Editor
- 03Module ngx_http_core_module: large_client_header_buffers, client_header_buffer_size · nginx.org
- 04Apache core: LimitRequestFieldSize, LimitRequestFields, LimitRequestLine · Apache HTTP Server
- 05Node.js command-line options: --max-http-header-size · Node.js
- 06Go net/http: DefaultMaxHeaderBytes · Go
- 07Http.sys registry settings for Windows (MaxFieldLength, MaxRequestBytes) · Microsoft Learn
- 08HTTP 400 error responses to HTTP requests (Kerberos tokens) · Microsoft Learn
- 09Connection limits · Cloudflare docs
- 10Increased HTTP header size limit to 128 KB (16 October 2025) · Cloudflare changelog
- 11Request and response behaviour for custom origins (maximum request length, 494) · AWS
- 12View, add, edit and delete cookies · Chrome for Developers
- 13Clear, allow and manage cookies in Chrome · Google Chrome Help
Last updated