春季安全性:OauthResourceServer + CSRF

时间:2020-04-27 14:10:04

标签: spring spring-security spring-security-oauth2

我们当前的设置存在问题:我们将spring oauth 2安全配置迁移到了最新的spring安全配置。 (https://github.com/spring-projects/spring-security/wiki/OAuth-2.0-Migration-Guide

从那时起,我们的资源服务器csrf配置不再起作用。

此时https://github.com/spring-projects/spring-security/blob/master/web/src/main/java/org/springframework/security/web/csrf/CsrfFilter.java#L116,过滤器应验证请求是否需要csrf保护。

requestMatchers 包含两个RequestMatcher:

https://github.com/spring-projects/spring-security/blob/master/config/src/main/java/org/springframework/security/config/annotation/web/configurers/CsrfConfigurer.java#L83忽略 https://github.com/spring-projects/spring-security/blob/master/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurer.java#L498,因为** init *方法无效(尝试忽略身份验证)https://github.com/spring-projects/spring-security/blob/master/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurer.java#L459

现在的问题是:它不起作用。一旦我们尝试访问受保护的资源(需要身份验证),CsrfFilter将不再起作用。 CsrfFilter中的第一个请求匹配器适用,但是第二个验证没有身份验证可用的请求匹配器失败,因此无法将csrf安全性应用于受保护的资源。

我们完全调试了它,找不到错误,也找不到解决方法。

0 个答案:

没有答案