Why do I get 431 on localhost in Next.js or Vite?
Multiple local apps on `localhost` share cookies across ports! Clear cookies for `localhost` in DevTools or raise `--max-http-header-size`.
HTTP 431 Request Header Fields Too Large means one or more request headers (almost always `Cookie` or a bloated JWT `Authorization` header) exceeded the server's header size limit—commonly 16KB in Node.js or 8KB in Nginx.
# Node.js / Next.js / Vite (raise to 32KB if needed)
NODE_OPTIONS="--max-http-header-size=32768" npm start
# Nginx
large_client_header_buffers 4 32k;
curl -i -sS -w '\nRequest size: %{size_request} bytes\n' https://example.com/
Multiple local apps on `localhost` share cookies across ports! Clear cookies for `localhost` in DevTools or raise `--max-http-header-size`.
Node.js defaults to 16KB (16384 bytes) total for all request headers combined to mitigate DoS attacks.
Keep JWTs under 2KB by storing session state server-side (Redis/DB) and referencing only a compact opaque session ID in the cookie.