Troubleshooting guide
431 Request Header Fields Too Large: how to fix it
A 431 means the headers were too big, and nearly always that means cookies. It is a common surprise in local development, where every project shares `localhost`.
3 min read10 sectionsUpdated
On this page
Common causes
- Oversized session or identity cookies, particularly JWTs carrying many roles and groups, or SSO tokens.
- Analytics and consent cookies accumulating on a shared parent domain.
localhostshared across projects, as cookies are not separated by port.- A proxy adding headers until the total passes the backend's limit.
Measure it
In browser DevTools, open Application, then Cookies, and sort by size. From the server side, you can reproduce with a cookie header of known size.
# Reproduce with a 20 KB cookie
curl -si -H "Cookie: a=$(head -c 20000 /dev/zero | tr '\0' 'x')" https://example.com/ | head -3
# Node.js: print the active limit
node -p "require('http').maxHeaderSize"
# Effective Nginx header buffers
sudo nginx -T 2>/dev/null | grep -E 'large_client_header_buffers|client_header_buffer_size'Fixes
Store a short session ID in the cookie and keep the data on the server. Scope cookies to the specific subdomain and path that uses them, and do not set everything on the parent domain. For local development, clear localhost cookies or use project-specific hostnames such as app.localhost.
If you truly need more room, Node.js accepts --max-http-header-size=32768, and Nginx needs large_client_header_buffers raised at the same time. Remember the next proxy in the chain has its own limit.
Catch it automatically
A 431 tends to hit your most active users first, because they have accumulated the most cookies. Chart 431 and 400 together in APM, and use session replay and real-user data to see whether failures concentrate after login.
Why do I get 431 only on localhost?
Cookies are shared across every port on localhost, so several projects can add up to a very large header. Clear them or use separate hostnames.
How big can a cookie be?
Browsers allow about 4 KB per cookie, but the combined total can still exceed server header limits.
Is 431 the same as 400?
It is more specific. Some servers return plain 400 for the same problem, including Nginx with its "Request Header Or Cookie Too Large" page.
Check it now, free
- Website down checker: Is it down for everyone or just me? Check any site now.
- HTTP headers checker: See the raw response headers of any URL.
Related reading
- 413 Request Entity Too Large: how to raise the limit safely: Fix 413 Request Entity Too Large in Nginx, Apache, Node.js, PHP and Kubernetes ingress: find which layer sets the limit and raise it safely for uploads.
- 429 Too Many Requests: what it means and how to fix it: 429 Too Many Requests explained: rate limits, the Retry-After header, backoff with jitter for clients, and how to set fair rate limits on your own API.
- 408 Request Timeout: causes and how to fix it: Understand 408 Request Timeout: slow client uploads, idle keep-alive connections and proxy settings, and how it differs from a 504 Gateway Timeout.
- Elasticsearch CircuitBreakingException: how to fix it: Fix Elasticsearch CircuitBreakingException Data too large: reduce fielddata and huge aggregations, size JVM heap correctly and check shard counts per node.
- PostgreSQL "too many clients already": how to fix it: Fix PostgreSQL FATAL: sorry, too many clients already. See who holds connections, stop leaks, add PgBouncer and size max_connections the right way.
- JavaScript heap out of memory: how to fix it in Node.js: Fix FATAL ERROR: JavaScript heap out of memory. Set --max-old-space-size correctly, handle build-time failures and find runtime leaks with heap snapshots.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.