We use embedded Tomcat and deploy a web app programatically using the addWebapp(Host, String, String, LifecycleListener) method. The LifecycleListener is a ContextConfig that has a default web.xml configured that should prevent the JSPServlet from being loaded. Other than expected, it turns out that addWebapp actively ignores the configured default web.xml and Tomcat instead loads statically hard-coded default configuration that includes the JSPServlet and servlet mappings for it. This behaviour led to a remote code execution vulnerability in one of our products. The code below shows how Tomcat is initialized. final Tomcat tomcat; // ... final ContextConfig contextConfig = new ContextConfig(); contextConfig.setDefaultWebXml(getDefaultWebXml()); final Context ctx = tomcat.addWebapp (host, getContextPath(), getDocBaseDir(), (LifecycleListener)contextConfig); // ... tomcat.start();
*** Bug 64009 has been marked as a duplicate of this bug. ***
The class level Javadoc does document that the various addWebapp methods configure the Default Servlet, JSP servlet etc. The LifecycleListener in #addWebapp(Host, String, String, LifecycleListener) is intended for additional configuration rather than as a complete replacement. I'll go through the Javadoc and try and make this clearer.
https://bz.apache.org/bugzilla/show_bug.cgi?id=62755 seems to be a related issue. It seems that the provided fix did not make it into the Tomcat codebase.
(In reply to Mark Thomas from comment #2) > The class level Javadoc does document that the various addWebapp methods > configure the Default Servlet, JSP servlet etc. The LifecycleListener in > #addWebapp(Host, String, String, LifecycleListener) is intended for > additional configuration rather than as a complete replacement. > > I'll go through the Javadoc and try and make this clearer. Is there a documented way to safely deploy a web app in embedded Tomcat without having the JspServlet added? I've tried to override classes, but a mixture of static and private methods prevented me from getting a clean implementation.
Javadoc updated in: - master for 9.0.31 onwards - 8.5.x for 8.5.51 onwards - 7.0.x for 7.0.100 onwards I also back-ported the enhancement in 62755 to 8.5.x and 7.0.x. With the current API in 8.5.x, if you don't want the JSP servlet then one option is to use addContext() and configure everything manually. Further help and advice is available via the users mailing list if required.