Skip to main content
 首页 » 编程设计

spring中如何配置Spring MVC来防止 "Path-Based Vulnerability"

2025年12月25日30lyhabc

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

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

对于上述 Controller ,这是我的常见问题解答页面的有效 URL:

http://example.com/faq

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

http://example.com/faq.anything

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

请您参考如下方法:

因为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