对于最新的稳定版本,请使用 Spring Security 6.4.1spring-doc.cadn.net.cn

Exploit Protection 迁移

5.8 迁移指南包含在更新到 6.0 时进行 Exploit Protection 迁移的几个步骤。 建议您先执行这些步骤。spring-doc.cadn.net.cn

以下步骤与如何完成 Exploit Protection 支持的迁移相关。spring-doc.cadn.net.cn

延迟加载 CsrfToken

在 Spring Security 5.8 中,默认的CsrfTokenRequestHandler用于使CsrfToken可供应用程序使用的是CsrfTokenRequestAttributeHandler. 字段的默认值csrfRequestAttributeNamenull,这会导致在每个请求上加载 CSRF 令牌。spring-doc.cadn.net.cn

在 Spring Security 6 中,csrfRequestAttributeName默认为_csrf. 如果您仅为了更新到 6.0 而配置了以下内容,则现在可以将其删除:spring-doc.cadn.net.cn

requestHandler.setCsrfRequestAttributeName("_csrf");

防止 CSRF BREACH

在 Spring Security 5.8 中,默认的CsrfTokenRequestHandler用于使CsrfToken可供应用程序使用的是CsrfTokenRequestAttributeHandler.XorCsrfTokenRequestAttributeHandler已添加以允许选择加入 CSRF BREACH 支持。spring-doc.cadn.net.cn

在 Spring Security 6 中,XorCsrfTokenRequestAttributeHandler是默认值CsrfTokenRequestHandler用于使CsrfToken可用。 如果您配置了XorCsrfTokenRequestAttributeHandler仅为了更新到 6.0,您可以将其完全删除。spring-doc.cadn.net.cn

如果您已将csrfRequestAttributeNamenull为了选择退出延迟令牌,或者如果您配置了CsrfTokenRequestHandler出于任何其他原因,您可以保留配置。spring-doc.cadn.net.cn

支持 WebSocket 的 CSRF BREACH

在 Spring Security 5.8 中,默认的ChannelInterceptor用于使CsrfToken可用的 WebSocket 安全性CsrfChannelInterceptor.XorCsrfChannelInterceptor已添加以允许选择加入 CSRF BREACH 支持。spring-doc.cadn.net.cn

在 Spring Security 6 中,XorCsrfChannelInterceptor是默认值ChannelInterceptor用于使CsrfToken可用。 如果您配置了XorCsrfChannelInterceptor仅为了更新到 6.0,您可以将其完全删除。spring-doc.cadn.net.cn