我在后端和前端应用程序中实现了csrf过滤器,我可以看到XSRF-TOKEN被发送,但我仍然得到http 403错误 .

Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'XSRF-TOKEN'.

我在后端和前端应用程序中设置了相同的 Headers 名称 XSRF-TOKEN . 你可以在下面看到webconfig .

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
    .httpBasic()
  .and()
    .authorizeRequests()
      .antMatchers("/", "/index.html").permitAll()
      .antMatchers("/login").permitAll()
      .antMatchers("/favicon.ico").permitAll()
      .antMatchers("/*.html").permitAll()
      .antMatchers("/css/*.css").permitAll()
      .antMatchers("/js/*.js").permitAll()
      .antMatchers("/currency_service/currencies").permitAll()
      .antMatchers("/currency_service/currency").permitAll()
      .antMatchers("/pages/*.html").permitAll()
    .anyRequest().authenticated()
      .and()
    .logout()
    .permitAll()
      .and()
      .addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class)
      .csrf().csrfTokenRepository(csrfTokenRepository());
}

    @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
        .inMemoryAuthentication()
            .withUser("username").password("password").roles("USER");
}

private CsrfTokenRepository csrfTokenRepository() {
      HttpSessionCsrfTokenRepository repository = new HttpSessionCsrfTokenRepository();
      repository.setHeaderName("XSRF-TOKEN");
      repository.setSessionAttributeName("_csrf");
      return repository;
    }

当我在浏览器中检查请求cookie时,我可以看到 XSRF-TOKEN 被发送到后端 . 这个问题可能是什么原因?

先感谢您 .