Find out what your server refused in the request
400 Bad Request means the server refused to process a request because it judged something in the request itself to be wrong: broken syntax, invalid framing, a header it won't accept or a body your app couldn't parse. The status blames the client, meaning the browser or script that sent the request, but the cause is often your own site, such as a cookie it keeps growing until the server rejects it. Find which layer sent the 400, and its log usually names the part it refused.
What a server rejects with a 400
A header or cookie over the size limit
Servers cap the size of each request header. A site that keeps adding cookies, or one cookie that grows on every visit, can push the Cookie header past that cap, and every request from that browser fails until its cookies are cleared.
A request that breaks HTTP's rules
HTTP/1.1 requires a server to answer 400 when a request has no Host header, more than one, or one with an invalid value, and when its Content-Length values conflict. A request line with invalid characters in the address should get a 400 as well, or a redirect to the properly encoded address.
A body your app couldn't read
Your app or API sends its own 400 when the body isn't valid JSON or a form field fails validation. The response body usually carries the app's reason.
A request cut off partway
A load balancer can answer 400 when the client closes the connection before it has sent the whole request body.
nginx's documentation says it returns 400 when one request header field outgrows its buffer, 8 KB by default. RFC 9112 sets the Host header and request line rules, and its section 6.3 the Content-Length rule, and Amazon's load balancer guide lists oversized headers and cut-off bodies among the causes of its 400s.
Test whether header size triggers the 400
# Print the status line and the software that answered
curl -sI https://yoursite.com/ | grep -iE '^(HTTP|server)'
# Send a 20,000-character cookie and print the final status
curl -sI -o /dev/null -w '%{http_code}\n' https://yoursite.com/ -H "Cookie: test=$(head -c 20000 /dev/zero | tr '\0' 'a')"
Work out where the 400 came from
A 400 can come from your CDN, a load balancer, the web server or your app, and each enforces its own rules. When the error is a plain page that names the web server, the request never reached your app. When it's a JSON error in your app's own format, the app rejected the body or a parameter. RFC 9110 defines the status broadly, so the layer that sent it matters more than the code.
If the oversized cookie test returns 400 and the plain request doesn't, look at the cookies your site sets. A
000means the server dropped the request without sending a status, which some servers do when a header is too large, so read it the same way. Open the browser's developer tools on an affected browser, list the cookies for your domain and look for ones that grow on every visit or that store whole objects instead of an ID.
How to fix a 400 Bad Request error
- Find the layer that refused the requestMatch the error page and the Server header to a layer you run, then read that layer's error log for the minute of the 400. It usually records which header, line or body check failed.
- Stop cookies from growing without limitStore a session ID in the cookie and keep the session data on the server, give every cookie an expiry, and remove cookies your site no longer reads. Raising the header limit only buys time while a cookie keeps growing.
- Fix requests your own code buildsIf a form or your site's JavaScript sends the failing request, log exactly what it sends and compare that with what the endpoint expects: the content type, valid JSON and every required field.
- Line up header limits across layersIf your CDN accepts larger headers than the web server behind it, the web server rejects requests the CDN let through. Set each layer's limit with the others in mind.
Frequently asked questions
Why does clearing cookies fix a 400 error?
Because the browser stops sending the oversized or corrupted cookie, and the next request fits under the server's header limit. If the error returns after a few visits, a cookie your site sets is growing again, and the fix belongs in your site's code, not in the visitor's browser.
Does a 400 error affect my site in Google?
Only for the URLs that return it. Google ignores whatever content comes with a 400, and a page already in its index that keeps answering 400 gets removed. Google's status code guide handles 400 like every other client error except 429.
Is a 400 error the visitor's fault?
Not usually. The client in client error means the browser or app that sent the request, not the person using it. Clearing cookies can get one visitor past a cookie-size 400, but a 400 that many visitors see points to something your site does, such as a cookie it sets, a form it builds or a rule in the server's settings.
Watch for errors your visitors hit
- Website reliabilityHear about it when your site goes down, not days later from a customer.
- 413 Content Too LargeFind the layer whose body size limit refused the upload, then raise it or keep uploads under it.
- 502 Bad GatewayFind the server behind your proxy that failed, then read the proxy's error log to see how.
- Cookie securityChoose cookie attributes that fit your sign-in flow and limit unnecessary exposure.