What the message looks like
400 Bad Request – Request Header Or Cookie Too LargeCommon causes
- Many cookies on the same domain, e.g. analytics, A/B tests and several apps on subdomains.
- SSO/OIDC session cookies or bearer tokens with many group claims.
- A redirect loop that sets another cookie on every pass.
large_client_header_bufferstoo small for the application.- The backend (Node, Tomcat, Gunicorn) also has its own header limits.
Check
- Show current buffer sizes in the config
nginx -T 2>/dev/null | grep -nE 'large_client_header_buffers|client_header_buffer_size' - Test with a 12 KB cookie whether nginx returns 400
curl -sS -o /dev/null -w '%{http_code}\n' -H "Cookie: test=$(head -c 12000 /dev/zero | tr '\0' a)" https://example.com/ - Search error.log for matching entries
grep -i 'too large' /var/log/nginx/error.log | tail -n 5
Fix
- For the user: clear cookies for the domain – that confirms the cause right away.
- In the server block set
large_client_header_buffers 4 32k;and runnginx -t && systemctl reload nginx. - With SSO limit the number of groups in the token or fetch groups from the userinfo endpoint.
- Scope cookies to the needed domain and path instead of
.example.com. - Raise header limits on the backend too, or you get a 431 or 400 there.
Typical scenario
Several users at a company get '400 Request Header Or Cookie Too Large' after logging in through the SSO provider, while it works in an incognito window. On the parent domain .example.com several applications each set their own cookies, and together they exceed the limit. Open the request headers in the developer tools and check the length of the Cookie line; from about 8 KB the nginx default limit applies.
FAQ
How large can I set the buffers?
32k per buffer is almost always enough. Much larger values cost memory per connection and make abuse easier. Better shrink the cause – the large cookie.
Why does it only affect some users?
Because only their browser collected that many cookies, e.g. through many apps or an old loop. A private window confirms it quickly.
Why does deleting cookies only help for a while?
The cookies grow again as soon as users keep working. Anyone who does not remove the cause meets the error again regularly. Fewer and smaller cookies help permanently, not repeated clean-ups in the browser.
What exactly is the limit?
A single header line has to fit into one buffer. large_client_header_buffers defaults to four buffers of 8 KB each, so the request line and each header line may fill at most one buffer. Beyond that you get the 400.
How do I avoid cookie ballast on the parent domain?
Applications should set cookies only for their own host and not for .example.com. In addition, keep sessions on the server and put only an ID in the cookie, rather than storing large tokens or claims in it.