Spring Security RegexRequestMatcher 认证绕过漏洞(CVE-2022-22978)允许攻击者通过精心构造的请求绕过正则表达式模式匹配器,从而绕过身份验证,访问未授权的资源。Spring Security 已发布修复程序,建议用户尽快升级。

以下是修复程序的步骤:

  1. 升级 Spring Security 版本到 5.5.3 及以上。

  2. 在 Spring Security 配置文件中,使用 request-matcher-ref 属性指定 RegexRequestMatcher 的 bean 名称,例如:

<security:intercept-url pattern="/secure/**" access="ROLE_USER" request-matcher-ref="myRequestMatcher"/>
  1. 在 Spring Security 配置文件中,定义一个 bean 来实例化 RegexRequestMatcher,并设置正确的正则表达式模式,例如:
<bean id="myRequestMatcher" class="org.springframework.security.web.util.matcher.RegexRequestMatcher">
    <constructor-arg name="pattern" value="/secure/.*"/>
    <constructor-arg name="httpMethod" value="GET"/>
</bean>

这将创建一个名为 myRequestMatcherRegexRequestMatcher 对象,使用正则表达式 /secure/.* 匹配所有以 /secure/ 开头的 URL,并且只匹配 GET 请求。

  1. 部署并测试应用程序,确保访问受限资源时必须进行身份验证。

注意:如果您正在使用 Spring Boot,则需要在 application.properties 文件中添加以下行:

spring.security.filter.dispatcher-types=ASYNC, ERROR, FORWARD, INCLUDE, REQUEST

这将确保 Spring Security 过滤器在异步请求、错误处理、转发和包含请求时也能正常工作。

升级到修复版本并且正确配置 RegexRequestMatcher 后,应用程序将不再受到 CVE-2022-22978 漏洞的影响。

CVE-2022-22978 Spring Security RegexRequestMatcher 认证绕过漏洞修复指南

原文地址: https://www.cveoy.top/t/topic/nsTw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录