My existing Spring Web MVC application has the following handler mapping in the Controller.
@RequestMapping(method = RequestMethod.GET, value = "/welcome")
I trigger the following requesthttp://www.example.com/welcome
and this works fine.
The problem is
http://www.example.com/welcome.check.blah
also works!!!
Also, a HTTP GET request URL to the application with script tag is getting redisplayed though it fails the authorization.
Example http://www.example.com/welcome<script>alert("hi")</script>
gets redisplayed as such in the browser window and as a result of my authorization logic "Not authorized" message is displayed.
I wonder if this is a security issue and should I need do any encoding/filtering in the code?
You can also restrict this in the web.xml by mentioning the url pattern. Instead of giving "/", you can mention "/.htm" in your web.xml.
Something like
You can use the useDefaultSuffixPattern property.
Also refer URL Pattern Restricting in SPRING MVC
In current Spring Java config, there is a slightly easier way to configure the same thing:
When you use Spring to request a mapping of that type (i.e. "/anything") Spring actually maps your controller to several URLs:
/welcome
/welcome.*
/welcome/
To prevent this - either be more specific when you RequestMapping (i.e. /welcome.htm ), or manually map the URL to controller in your Xml config:
Cheers, Pete
This behavior is due to the option
useSuffixPatternMatch
which is true by default inside theRequestMappingHandlerMapping
(I assume you use Spring MVC 3.1).To set
useSuffixPatternMatch
to false, the easiest way is to use@Configuration
: