2

I have a Spring MVC (5.0.8.RELEASE) application and a recent security scan indicates that it has "Path-Based Vulnerability". Here is the controller:

@RequestMapping(value = "/faq", method = RequestMethod.GET)
public String faq(HttpServletRequest request) {
    return "faq";
}

For the above controller, here is the valid url for my FAQ page:

http://example.com/faq

However, based on the security scan and what I tested, the following url works too:

http://example.com/faq.anything

How can I configure Spring MVC to make http://example.com/faq to the only valid URL? (suppose that I don't use @PathVariable)

curious1
  • 14,155
  • 37
  • 130
  • 231

1 Answers1

2

Because spring support suffix ".*" default. /person is also mapped to /person.* /person.xml or /person.pdf or /person.any is also mapped. - To completely disable the use of file extensions, you must set both of these:

.useSuffixPatternMatching(false)

.favorPathExtension(false)

https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-ann-requestmapping-suffix-pattern-match

Markus Pscheidt
  • 6,853
  • 5
  • 55
  • 76
Huy Nguyen
  • 1,931
  • 1
  • 11
  • 11