New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two trailing slashes and the default servlet cannot resolve to a controller [SPR-12372] #16979

Closed
spring-issuemaster opened this Issue Oct 23, 2014 · 7 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Oct 23, 2014

Gaurav Khanna opened SPR-12372 and commented

If we map the DispatcherServlet as the default servlet as in:
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

And the controller has the request mapping as in:
@RequestMapping("/controller/**")

And if we have a GET request with two trailing slashes as in:
http://xxx.xxx/app/controller/REQ// [URI 1]

Then the default servlet (spring) is not able to find a mapping for it and we get a 404. However if we have a single trailing "/" then it works. Or if have multiple slashes anywhere in the REQ (together or separated) that works fine too. For instance:
http://xxx.xxx/app/controller/REQ//A [URI 2] [Here "A" could be just one character except the "/"]

Also, if we make the DispatcherServlet map to "/*" then two or more trailing "/" slashes work as well.

Should the default servlet (spring) not map URI 1 above without the wildcard in web.xml?


Affects: 3.2.1

Issue Links:

  • #15100 404 error with double slash in context path ("is duplicated by")
  • #15845 RequestMapping maps double-slashes to single slashes

Referenced from: commits e02719e

0 votes, 5 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 24, 2014

Brian Clozel commented

Hi g_khanna

Do you have other servlets configured within your application?
What application container are you using (Tomcat, Jetty, ...)?

According to the Servlet specification, "/" and "/*" mappings have different meanings.

12.2 Specification of Mappings

  • A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.
  • A string containing only the ’/’ character indicates the "default" servlet of the application.
    In this case the servlet path is the request URI minus the context path and the path info is null.

In this case, I think that mapping to / and querying for "/whatever//", another servlet may be servicing that request. Turning on DEBUG logs for "org.springframework.web.servlet" could show if those requests are indeed processed by the DispatcherServlet or something else.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 24, 2014

Gaurav Khanna commented

  1. There is only one servlet configured.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0">
      
   
    <display-name>OcspResponder</display-name>

   	<servlet>
		<servlet-name>spring</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/spring-servlet.xml</param-value>
        </init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>spring</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

</web-app>
  1. The spring dispatcher is getting invoked:
2014-10-24 18:44:09,053 [http-bio-8080-exec-1] TRACE [o.s.w.s.DispatcherServlet]  Bound request context to thread: org.apache.catalina.connector.RequestFacade@18b8e570
2014-10-24 18:44:09,053 [http-bio-8080-exec-1] DEBUG [o.s.w.s.DispatcherServlet]  DispatcherServlet with name 'spring' processing GET request for [/XXX/controller/MEMwQTA/MD0wOzAJBgUrDgMCGgUABBRAC0Z68eay0wmDug1gfn5ZN0gkxAQUw5zz/NNGCDS7zkZ/oHxb8+IIy1kCAi//]
2014-10-24 18:44:09,053 [http-bio-8080-exec-1] TRACE [o.s.w.s.DispatcherServlet]  Testing handler map [org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@7ec10c7b] in DispatcherServlet with name 'spring'
2014-10-24 18:44:09,053 [http-bio-8080-exec-1] TRACE [o.s.w.s.h.BeanNameUrlHandlerMapping]  No handler mapping found for [/]
2014-10-24 18:44:09,053 [http-bio-8080-exec-1] TRACE [o.s.w.s.DispatcherServlet]  Testing handler map [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping@390adbaa] in DispatcherServlet with name 'spring'
2014-10-24 18:44:09,054 [http-bio-8080-exec-1] TRACE [o.s.w.s.m.a.DefaultAnnotationHandlerMapping]  No handler mapping found for [/]
2014-10-24 18:44:09,054 [http-bio-8080-exec-1] WARN  [o.s.w.s.PageNotFound]  No mapping found for HTTP request with URI [/XXX/controller/MEMwQTA/MD0wOzAJBgUrDgMCGgUABBRAC0Z68eay0wmDug1gfn5ZN0gkxAQUw5zz/NNGCDS7zkZ/oHxb8+IIy1kCAi//] in DispatcherServlet with name 'spring'
2014-10-24 18:44:09,054 [http-bio-8080-exec-1] TRACE [o.s.w.s.DispatcherServlet]  Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@18b8e570
2014-10-24 18:44:09,054 [http-bio-8080-exec-1] DEBUG [o.s.w.s.DispatcherServlet]  Successfully completed request
2014-10-24 18:44:09,054 [http-bio-8080-exec-1] TRACE [o.s.w.c.s.XmlWebApplicationContext]  Publishing event in WebApplicationContext for namespace 'spring-servlet': ServletRequestHandledEvent: url=[/XXX/controller/MEMwQTA/MD0wOzAJBgUrDgMCGgUABBRAC0Z68eay0wmDug1gfn5ZN0gkxAQUw5zz/NNGCDS7zkZ/oHxb8+IIy1kCAi//]; client=[127.0.0.1]; method=[GET]; servlet=[spring]; session=[null]; user=[null]; time=[1ms]; status=[OK]

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 29, 2014

Gaurav Khanna commented

Hi,
Any updates?
Thanks.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Oct 30, 2014

Brian Clozel commented

Hi, I've created a repro project and I'm looking at it.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Nov 3, 2014

Gaurav Khanna commented

Hi Brian,

Saw some activity today. Has this issue been replicated and confirmed?

Regards.
Gaurav Khanna "khanna111"

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Nov 3, 2014

Brian Clozel commented

Hi Gaurav Khanna

The repro project I created last week does reproduce this issue. After some digging, it seems this happens when several conditions occur:

  • using Tomcat (same use case with Jetty 9 doesn't show that problem)
  • mapping as the default servlet (using /* as servlet mapping "fixes" the issue)
  • having double slashes in specific parts of the request URL

I've scheduled this issue to 4.1.3, as 4.1.2 is around the corner; also, this issue might actually be only one example of many others, so I need some time to test multiple scenarios with multiple app containers.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator

spring-issuemaster commented Nov 3, 2014

Gaurav Khanna commented

Thanks Brian for the quick turnaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment