【问题标题】:How to enable CSRF for all request in Spring Security如何为 Spring Security 中的所有请求启用 CSRF
【发布时间】:2021-04-14 14:30:14
【问题描述】:

由于 spring 为某些方法(如 GET)禁用 CSRF 令牌,我们如何使用 spring 安全性为所有请求(包括 GET)启用 CSRF 令牌验证。

【问题讨论】:

    标签: spring spring-security csrf


    【解决方案1】:
    @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().requireCsrfProtectionMatcher(AnyRequestMatcher.INSTANCE);
        }
    }
    

    注意此配置意味着任何请求都需要 csrf 令牌,这是不必要且难以实现的

    【讨论】:

      猜你喜欢
      • 2018-06-06
      • 2019-12-06
      • 2016-01-31
      • 1970-01-01
      • 2014-09-30
      • 2016-05-02
      • 2016-06-21
      • 1970-01-01
      相关资源
      最近更新 更多