小编典典

如何配置Spring MVC来防止“基于路径的漏洞”

spring-mvc

我有一个Spring MVC(5.0.8.RELEASE)应用程序,最近的安全扫描表明它具有“基于路径的漏洞”。这是控制器:

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

对于上述控制器,这是我的常见问题解答页面的有效网址:

http://example.com/faq

但是,根据安全性扫描和我测试的内容,以下网址也适用:

http://example.com/faq.anything

如何配置Spring
MVC使http://example.com/faq成为唯一有效的URL?(假设我不使用@PathVariable)


阅读 387

收藏
2020-06-01

共1个答案

小编典典

因为默认情况下spring支持后缀“。”。/ person也映射到/person.
/person.xml或/person.pdf或/person.any也被映射。-要完全禁用文件扩展名,您必须同时设置以下两项:

.useSuffixPatternMatching(false)

.favorPathExtension(false)

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

2020-06-01