Closed zouzg7829 closed 9 months ago
+1
搜一下CVE-2023-22602漏洞,使用SpringSecurity新版本需要改写代码的,简单一点是改成这样:
return httpSecurity
.authorizeHttpRequests(authorizeRequests -> authorizeRequests
.requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/")).permitAll()
.requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/*.html")).permitAll()
.requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/**.html")).permitAll()
.requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/**.css")).permitAll()
.requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/**.js")).permitAll()
.requestMatchers(AntPathRequestMatcher.antMatcher("/druid/**")).permitAll()
.anyRequest().authenticated())
.build();
更严谨的做法是改成MvcRequestMatcher
搜一下CVE-2023-22602漏洞,使用SpringSecurity新版本需要改写代码的,简单一点是改成这样:
return httpSecurity .authorizeHttpRequests(authorizeRequests -> authorizeRequests .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/")).permitAll() .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/*.html")).permitAll() .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/**.html")).permitAll() .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/**.css")).permitAll() .requestMatchers(AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/**.js")).permitAll() .requestMatchers(AntPathRequestMatcher.antMatcher("/druid/**")).permitAll() .anyRequest().authenticated()) .build();
更严谨的做法是改成MvcRequestMatcher
按照你写的代码修改,运行Application,同样抛出之前的错误, 异常信息中,重点如下: This is because there is more than one mappable servlet in your servlet context: {org.springframework.web.servlet.DispatcherServlet=[/], com.alibaba.druid.support.jakarta.StatViewServlet=[/druid/*]}.
我的能正常启动,我用的springboot3.1.5+ spring security config6.1.5 + spring security web6.1.5,改写之前应用启动时和你一样的提示,按照提示修改了就启动成功了
这个问题和druid没什么关系,你还是去spring security社区找找吧,看看升级之后代码需要怎么改写。
我用eclipse + jdk17对当前master分支代码重新做了一下验证,在druid-spring-boot-3-starter模块的测试package里加上你的这个SecurityConfig,确认不改写就抛异常,改写了就ok。 当然现在的master分支的core模块在jdk17上编译有错误,还要改pom和代码,主要需要修改的内容如下:
@Resource
注解,jdk17没有这个注解,需要替换成@Autowired
和@Qualifier
,改了StatAnnotationBeanPostProcessor.java。在druid-spring-boot-3-starter测试package填加SecurityConfig,修改pom添加SecurityConfig需要的spring-security:
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<scope>test</scope>
</dependency>
<springboot3.version>3.1.5</springboot3.version>
to @zrlw : 按照你的步骤,能显示druid的登陆页面,但是输入正确的用户名和密码登陆不上去,Http Response返回403. application.yml文件中也删除了所有的中文字符,采用UTF-8格式。
配置spring-security默认是开启csrf,403是被CsrfFilter阻断了,druid是restful,post请求都不带csrfToken,目前druid并没有提供这些功能,用security意味着你自己要定制。 如果你不担心跨站攻击,可以直接禁用csrf了事,否则你就要写很多代码了,如果不熟悉相关内容,应该还有很多问号或者惊叹号在前面等着你。
配置spring-security默认是开启csrf,403是被CsrfFilter阻断了,druid是restful,post请求都不带csrfToken,目前druid并没有提供这些功能,用security意味着你自己要定制。 如果你不担心跨站攻击,可以直接禁用csrf了事,否则你就要写很多代码了,如果不熟悉相关内容,应该还有很多问号或者惊叹号在前面等着你。
Thanks!
AbstractRequestMatcherRegistry.java:208行的原因,idea中下载源码,debug一下就知道了,所有pattern都要显示声明为antPattern或者mvcPattern
配置spring-security默认是开启csrf,403是被CsrfFilter阻断了,druid是restful,post请求都不带csrfToken,目前druid并没有提供这些功能,用security意味着你自己要定制。 如果你不担心跨站攻击,可以直接禁用csrf了事,否则你就要写很多代码了,如果不熟悉相关内容,应该还有很多问号或者惊叹号在前面等着你。
403加这个就行了 .csrf(httpSecurityCsrfConfigurer -> httpSecurityCsrfConfigurer.ignoringRequestMatchers( antMatchers("/druid/**") ))
to @zrlw : 按照你的步骤,能显示druid的登陆页面,但是输入正确的用户名和密码登陆不上去,Http Response返回403. application.yml文件中也删除了所有的中文字符,采用UTF-8格式。
403加这个就行了 .csrf(httpSecurityCsrfConfigurer -> httpSecurityCsrfConfigurer.ignoringRequestMatchers( antMatchers("/druid/**") ))
使用的druid-spring-boot-3-starter版本号为1.2.20
appliction.yml配置如下:
项目采用了SpringSecurity安全配置
启动不了,抛出如下异常:
异常信息中,重点如下:
This is because there is more than one mappable servlet in your servlet context: {org.springframework.web.servlet.DispatcherServlet=[/], com.alibaba.druid.support.jakarta.StatViewServlet=[/druid/*]}.
但是如果去掉appliction.yml文件中的statViewServlet配置,则可以启动, 也即application.yml: