spring-security - 在 Spring Weblux 中为给定路径禁用身份验证和 csrf?
问题描述
我想为整个应用程序启用 oauth2,除了一个 url。
我的配置:
@EnableWebFluxSecurity
class SecurityConfig {
@Bean
fun securityWebFilterChain(http: ServerHttpSecurity) =
http
.authorizeExchange()
.pathMatchers("/devices/**/register").permitAll()
.and()
.oauth2Login().and()
.build()
}
应用程序.yml:
spring.security.oauth2.client.registration.google.client-id: ...
spring.security.oauth2.client.registration.google.client-secret: ...
所有路径都受到 oauth2 的保护,但问题是当我调用一个允许的端点时,作为/devices/123/register
响应,我得到:
CSRF Token has been associated to this client
我是否需要以不同的方式配置此路径?
解决方案
permitAll
只是关于权限的声明——所有典型的 Web 应用程序漏洞仍然像 XSS 和 CSRF 一样得到缓解。
如果您试图表明/devices/**/register
Spring Security 应该完全忽略它,那么您可以执行以下操作:
http
.securityMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... omit the permitAll statement
但是,如果您仍然希望该端点获得安全响应标头,而不是 CSRF 保护,那么您可以这样做:
http
.csrf()
.requireCsrfProtectionMatcher(new NegatedServerWebExchangeMatcher(
pathMatchers("/devices/**/register")))
... keep the permitAll statement
推荐阅读
- arrays - 如何使用 Observable 填充 Angular Mat-Table
- javascript - Making a conditional function more efficient
- python - Import two modules in Main file, and call methods in them from each other
- html - 如何使用@media 修改动画
- json - Process multi-level nested escaped JSON strings inside JSON with fluentd
- ssis - SSIS Count duplicates
- html - 如何删除 div 和 html 之间不需要的空间?
- 3d - How to export 3D object in autocad 3D
- javascript - 是否可以将 Ant 设计主题更改为动态
- docker - 如何将凭据添加到 Docker ADD 命令