Tomcat harden security Follow
To harden Apache Tomcat and prevent penetration or exploitation attempts, follow these secure configuration best practices. These measures reduce the attack surface and help defend against both automated and targeted attacks.
✅ 1. Remove or Restrict Default Applications
Application | Recommendation |
---|---|
/manager |
Remove unless absolutely needed. |
/host-manager |
Remove or restrict by IP. |
/examples |
Remove entirely. |
/docs |
Remove if not required. |
Remove Example Apps:
🔐 2. Secure tomcat-users.xml
Only define specific roles and users with least privilege. For example:
Use long, complex passwords. Never use default usernames
🛑 3. Restrict IP Access to Admin Interfaces
For tomcat restriction edit:
<tomcat>/conf/context.xml
For ServiceManager specific restriction, copy tomcat context.xml file to the following location:
<tomcat>/webapps/ServiceManager/WEB_INF/context.xml
Restrict by IP using RemoteAddrValve
:
🔒 4. Enable HTTPS and Disable HTTP
Redirect all HTTP to HTTPS using reverse proxy or configure server.xml
:
Disable plain-text HTTP connector:
📦 5. Secure File Permissions
-
Run Tomcat under a dedicated non-root user.
-
Restrict file access:
-
Prevent shell access for the Tomcat user:
🛡️ 6. Disable Unused Connectors and Features
In <tomcat>/conf/server.xml
:
-
Disable AJP if not used:
-
Remove auto-deploy if not needed:
📄 7. Hide Server Information
In web.xml
, disable server info leakage:
Also remove version banners:
In conf/web.xml
, disable directory listings:
🔁 8. Keep Tomcat and Java Updated
-
Regularly update Tomcat to the latest stable release.
-
Keep the underlying Java JDK/JRE up to date.
-
Subscribe to the Apache Tomcat security announcements.
📋 9. Enable Logging and Monitoring
-
Enable access logs:
$CATALINA_HOME/logs/
-
Integrate with
fail2ban
, SIEMs, or alerting tools. -
Review logs regularly for brute force, RCE attempts, etc.
🧱 10. Additional Recommendations
-
Use a reverse proxy (NGINX/Apache) to isolate Tomcat from direct exposure.
-
Limit exposure to internal networks or specific IPs using firewalls.
-
Use security headers:
X-Content-Type-Options
,X-Frame-Options
,Strict-Transport-Security
, etc. -
Disable Java serialization unless required.
Comments
0 comments
Please sign in to leave a comment.