Skip to content

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

Key points

  • Cookies are the usual cause, not custom headers.
  • Node.js limits headers to 16 KB by default.
  • Developers hit it on localhost because cookies from all projects pile up.
  • Shrink the cookies before raising limits.

What 431 means

The server is refusing the request because one header, or all of them together, is over the limit. Browsers send all cookies for the domain on every request, including requests for images, so large cookies also cost performance across the site.

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.
  • localhost shared 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.

bash
# 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.

Frequently asked questions

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

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.