代码之家  ›  专栏  ›  技术社区  ›  curious1

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

  •  0
  • curious1  · 技术社区  · 7 年前

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

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

    http://example.com/faq

    http://example.com/faq.anything

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

    1 回复  |  直到 7 年前
        1
  •  2
  •   Markus Pscheidt WEGSY85    7 年前

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

    .favorPathExtension(错误)

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