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

2024-02-26

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

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

对于上述控制器,以下是我的常见问题解答页面的有效 URL:

http://example.com/faq http://example.com/faq

但是,根据安全扫描和我的测试,以下网址也有效:

http://example.com/faq.anything http://example.com/faq.anything

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


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

.useSuffixPatternMatching(false)

.favorPathExtension(假)

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐