Spring security 在Spring Weblux中禁用给定路径的身份验证和csrf?
我想为整个应用程序启用oauth2,除了一个url 我的配置:Spring security 在Spring Weblux中禁用给定路径的身份验证和csrf?,spring-security,kotlin,spring-security-oauth2,spring-webflux,csrf-protection,Spring Security,Kotlin,Spring Security Oauth2,Spring Webflux,Csrf Protection,我想为整个应用程序启用oauth2,除了一个url 我的配置: @EnableWebFluxSecurity class SecurityConfig { @Bean fun securityWebFilterChain(http: ServerHttpSecurity) = http .authorizeExchange() .pathMatchers("/devices/**/register").permit
@EnableWebFluxSecurity
class SecurityConfig {
@Bean
fun securityWebFilterChain(http: ServerHttpSecurity) =
http
.authorizeExchange()
.pathMatchers("/devices/**/register").permitAll()
.and()
.oauth2Login().and()
.build()
}
application.yml:
spring.security.oauth2.client.registration.google.client-id: ...
spring.security.oauth2.client.registration.google.client-secret: ...
所有路径都受到oauth2的保护,但问题是,当我调用允许的端点时,/devices/123/register
,作为响应,我得到:
CSRF令牌已关联到此客户端
我需要以不同的方式配置此路径吗?
permitAll
只是一个关于权限的声明——所有典型的web应用程序漏洞都像XSS和CSRF一样得到了缓解
如果您试图指示Spring Security应完全忽略/devices/**/register
,则可以执行以下操作:
http
.securityMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... omit the permitAll statement
http
.csrf()
.requireCsrfProtectionMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... keep the permitAll statement
但是,如果您仍然希望该端点获得安全响应头,而不是CSRF保护,则可以执行以下操作:
http
.securityMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... omit the permitAll statement
http
.csrf()
.requireCsrfProtectionMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... keep the permitAll statement