You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2006/05/05 22:59:15 UTC

DO NOT REPLY [Bug 39496] New: - Servlet mapping fails for subdirectory requests when subdirectory exists

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39496>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=39496

           Summary: Servlet mapping fails for subdirectory requests when
                    subdirectory exists
           Product: Tomcat 5
           Version: 5.5.17
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Unknown
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: davemorrissey@gmail.com


I believe I have found a bug in servlet mapping in recent versions of Tomcat.
The circumstances where this bug can be seen are quite convoluted but not uncommon:

* A servlet mapping has been set up that matches requests for 'virtual' pages in
the root and any subdirectory
* A Host element matching a domain name has been set up and mapped to the webapp
folder
* The user browses to a 'virtual' file in a subdirectory, via the domain name
* The subdirectory exists on the file system

Under these circumstances, Tomcat 5.5.16 and 5.5.17 return a 404 error when the
servlet should have handled the request.

Steps to reproduce:

1. Create a hosts file entry to point a domain such as www.testdomain.com at the
local machine.
2. Download and unzip the binary distribution apache-tomcat-5.5.17.zip
3. Add the following Host entry after the default localhost one in conf/server.xml
	<Host name="www.testdomain.com" debug="0" appBase="webapps\test"
			unpackWARs="true" autoDeploy="true">
		<Context path="" docBase="" debug="0"/>
	</Host>
4. Create a folder in webapps named "test". Also create "test/subdir",
"test/WEB-INF" and "test/WEB-INF/classes"
5. Add the following web.xml to WEB-INF.
	<?xml version="1.0" ?>
	<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
	<web-app>
		<servlet>
			<servlet-name>test</servlet-name>
			<servlet-class>TestServlet</servlet-class>
			<load-on-startup>1</load-on-startup>
		</servlet>
		<servlet-mapping>
			<servlet-name>test</servlet-name>
			<url-pattern>*.ser</url-pattern>
		</servlet-mapping>
	</web-app>
6. Compile this code and put it in the classes folder.
	import java.io.IOException;
	import javax.servlet.ServletException;
	import javax.servlet.http.HttpServlet;
	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	public class TestServlet extends HttpServlet {
		protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
			response.getOutputStream().write("Servlet responded".getBytes());
		}
	}
7. Start Tomcat with startup.bat.
8. Browse to the following URLs.

http://localhost:8080/test/page.ser - OK
http://localhost:8080/test/subdir/page.ser - OK
http://localhost:8080/test/subdir2/page.ser - OK
http://www.testdomain.com:8080/page.ser - OK
http://www.testdomain.com:8080/subdir/page.ser - 404
http://www.testdomain.com:8080/subdir2/page.ser - OK

I have tested 5.5.17 Windows and Linux binary distributions, and 5.5.16 under
Windows, which all fail. 5.5.12, 5.0.30 and 4.1.31 successfully return all the
above requests. I couldn't find 5.5.13-15 to test.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 39496] - Servlet mapping fails for subdirectory requests when subdirectory exists

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39496>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=39496


wosc@wosc.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wosc@wosc.de




------- Additional Comments From wosc@wosc.de  2006-06-27 09:29 -------
Hi,

I think the underlying problem is this: Tomcat nowadays deploys *any* directory
contained in the Host's appBase as a webapp. This has nothing to do with
localhost or not, which you can validate by using the same test-webapp described
above, but outside the "webapps"-Directory, e. g.

<Host name="www.testdomain.com" debug="0" appBase="/tmp/test"
  unpackWARs="true" autoDeploy="true">
    <Context path="" docBase="" debug="0"/>
    <Context path="/manager" reloadable="true" 
      docBase="/path/to/apache-tomcat-5.5.17/server/webapps/manager"
privileged="true"/>
</Host>

and then look at the webapps on this host. There is "/" and "/subdir", the
latter of which should not be there. This behaviour is the same if you use
localhost instead of testdomain.com, the difference was caused by the fact that
localhost has appBase="webapps", which does not contain a directory "subdir", so
the virtual mappings can pass unhindered by erroneously deployed webapps.


I dug through the sources and found that version 5.5.12 has these lines in
org.apache.catalina.startup.HostConfig.deployDirectories()
    // Make sure there is an application configuration directory
    // This is needed if the Context appBase is the same as the
    // web server document root to make sure only web applications
    // are deployed and not directories for web space.
    File webInf = new File(dir, "/WEB-INF");
    if (!webInf.exists() || !webInf.isDirectory() ||
        !webInf.canRead())
        continue;

I don't know when or why they were removed, but this clearly is the reason for
the new behaviour -- which I consider unwanted and wrong. Please do tell if
there is a rationale for auto-deploying *all* directories, regardless if they
are, in fact, a webapp; I at least can't see a reason to do so.

As a workaround I suggest using an empty directory as the Host's appBase, and
then putting absolute paths as the Context's docBases. This way, there simply
won't *be* any extra subdirectories for Tomcat to deploy.

Wolfgang

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 39496] - Servlet mapping fails for subdirectory requests when subdirectory exists

Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39496>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=39496


markt@apache.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID




------- Additional Comments From markt@apache.org  2006-09-14 02:40 -------
This is a configuration error. appBase should not equal docBase. In this case
you need to make the following changes.
webapps\test -> webapps\ROOT
appBase="webapps\test" -> appBase="webapps"
path="" -> Not specified. Tomcat infers this
docBase="" -> docBase="ROOT"

That your configuration worked in previous versions was luck. It has never been
a supported use case.

Please follow up on the users mailing list if you require further support.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org