Headers are too big.
When to use it
Oversized cookies are the usual culprit.
Common causes and fixes
Headers are too large, and cookies are almost always the cause: piles of tracking cookies, a session stored client-side, or a JWT with many claims kept in a cookie. On localhost, cookies from every app you ever ran accumulate, because cookies ignore the port. Clearing the site’s cookies usually fixes it immediately, which also confirms the diagnosis.
Node.js returns 431 when headers exceed 16 KB, which often bites dev servers such as Vite and Next.js; --max-http-header-size raises the limit. nginx and Apache answer the same problem with 400 instead. The real fix is smaller headers: keep only a session ID in the cookie, scope cookies with narrow Path and Domain values, and delete stale ones.
Client error (4xx)
4xx codes are client errors: the request itself is wrong, unauthorised or points at something that isn’t there. Retrying the same request won’t help.
What it looks like
HTTP/1.1 431 Request Header Fields Too LargeHow to send it
| Node.js / Express | res.status(431).end() |
|---|---|
| Python / Flask | return '', 431 |
| nginx | return 431; |
How to check it
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/