Diagnosing and Fixing Tomcat 400 Bad Request Errors from Oversized Request Headers
Clients hit Tomcat 400 Bad Request when request headers exceed the connector’s maxHttpHeaderSize. This guide walks through symptoms, diagnostics, configuration changes, verification, and escalation steps to resolve the issue on Tomcat 9/10.
10 Aug 2026, 22:23 UTC

Problem Overview
Clients receive an HTTP 400 Bad Request when Tomcat rejects a request. The server log contains messages such as Request header fields too large or Header size exceeds limit. The root cause is the maxHttpHeaderSize attribute on the Connector being smaller than the actual request header size.
Recognizable Symptoms
| Symptom | Typical Log Entry | What to Check |
|---|---|---|
| 400 Bad Request in browser or client | org.apache.catalina.connector.CoyoteAdapter - Request header fields too large | Inspect request headers |
| Client timeout or connection reset | Same header size error | Verify connector limits |
| Unexpected 500 errors after retry | Header size exceeded message | Check for proxy header injection |
Diagnostic Checklist
- Inspect Connector Configuration
Open
$CATALINA_BASE/conf/server.xmland locate the<Connector>element that handles HTTP traffic. Verify themaxHttpHeaderSizeattribute. If it is missing, the default is 8 192 bytes.<Connector port="8080" protocol="HTTP/1.1" maxHttpHeaderSize="65536" connectionTimeout="20000" /> - Capture a Sample Request
Use
curlor a browser dev‑tools network panel to view all headers sent for a typical request. Example usingcurl:curl -v -H "Large-Header: $(printf 'A%.0s' {1..70000})" http://localhost:8080/yourappCount the total header size (bytes) manually or with a script.
- Compare Header Size to Configured Limit
If the request header size exceeds
maxHttpHeaderSize, Tomcat will reject it. - Identify Additional Header Sources
- Reverse proxies (NGINX, Apache HTTPD) that add
X-Forwarded-For,X-Forwarded-Proto, or custom headers. - Application code that sets large cookies or custom authentication tokens.
- Load balancers that inject health‑check headers.
- Reverse proxies (NGINX, Apache HTTPD) that add
- Check for Custom Valves or Filters
Some custom
Valveimplementations may impose their own header size limits.
Corrective Actions
- Increase
maxHttpHeaderSize
Set the attribute to a value that comfortably exceeds the largest observed header. A common safe value is 64 KB (65 536 bytes). For Tomcat 9/10, edit
server.xmlor an appropriatecontext.xml:<Connector port="8080" protocol="HTTP/1.1" maxHttpHeaderSize="65536" connectionTimeout="20000" />After editing, restart Tomcat:
catalina.sh stop && catalina.sh start(or the Windows equivalent). - Refactor Application Headers
Review application code that sets headers. For example, avoid storing large tokens in cookies or move data to the request body. If a header is required, consider base64‑encoding it and trimming whitespace.
- Coordinate with Upstream Proxies
Ask the team managing NGINX or Apache HTTPD to reduce the size of injected headers or enable header compression. In NGINX, you can set
proxy_buffer_sizeandproxy_buffersto accommodate larger headers. - Deploy a Reverse Proxy for Header Truncation
If header size cannot be reduced, place a reverse proxy (e.g., NGINX) that strips or compresses headers before forwarding to Tomcat.
Verification Steps
- After restarting, resend the test request:
curl -v -H "Large-Header: $(printf 'A%.0s' {1..70000})" http://localhost:8080/yourappThe expected result is a
200 OKresponse and no header‑size error incatalina.out. - Monitor Tomcat memory usage. Use
jvisualvmortopto ensure that the increasedmaxHttpHeaderSizedoes not cause abnormal heap growth. - If a reverse proxy is used, repeat the test through the proxy and confirm that the header reaches Tomcat unchanged.
Escalation Criteria
- If increasing
maxHttpHeaderSizedoes not resolve the 400 errors, investigate network devices, load balancers, or custom Valve code that may impose additional limits. - If header size remains problematic and cannot be trimmed, consider redesigning the API to avoid large headers or implementing a dedicated header‑compression proxy.
- Escalate to security or network teams if anomalously large headers appear, as this may indicate a DoS attack vector.
Limitations and Risks
- Increasing
maxHttpHeaderSizeraises per‑request memory allocation and can increase garbage‑collection pressure under high load. Monitor heap usage and GC logs. - Large headers can be exploited for denial‑of‑service attacks. Ensure that upstream firewalls or reverse proxies still enforce appropriate limits.
- Changes to
server.xmlrequire a Tomcat restart; schedule maintenance windows to avoid downtime.
Practical Checklist Summary
- Verify
maxHttpHeaderSizeinserver.xml. - Measure actual request header size with
curlor dev‑tools. - Adjust
maxHttpHeaderSizeor refactor headers. - Restart Tomcat and retest.
- Monitor memory and logs for regressions.
Following this diagnostic flow will quickly isolate the cause of 400 Bad Request errors due to oversized headers and guide you to an appropriate, safe fix.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.