Angularjs Spring Boot CSRF筛选器在后端实现,前端发送CSRF头,但引发http 403错误

Angularjs Spring Boot CSRF筛选器在后端实现,前端发送CSRF头,但引发http 403错误,angularjs,spring,spring-security,csrf,http-status-code-403,Angularjs,Spring,Spring Security,Csrf,Http Status Code 403,我已经在后端和前端应用程序中实现了csrf过滤器,我可以看到XSRF-TOKEN被发送,但我仍然收到http 403错误 Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'XSRF-TOKEN'. 我在我的后端和前端应用程序中都设置了相同的头名称为XSRF-TOKEN。 你可以看到下面的网络配置 @Override protected void configure(HttpSe

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

Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'XSRF-TOKEN'.
我在我的后端和前端应用程序中都设置了相同的头名称为XSRF-TOKEN。 你可以看到下面的网络配置

    @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;
    }
当我在浏览器中检查请求cookies时,我可以看到XSRF-TOKEN被发送到后端。 这个问题的原因可能是什么


提前感谢。

这不是一个真正的解决方案,但在处理请求之前,可以尝试添加拦截器。然后将标题转储到控制台,以查看您真正得到了什么。感谢您的推荐,但我已经尝试过了,在调用页面/登录之前,服务器直接拒绝了请求。我看不到打印头文件进入服务器。切换.addFilterAfter(…)和.csrf().csrfTokenRepository()的顺序如何?我指的是不同的地方,顺序不同。谢谢你的回答。我将其更改为
。和().csrf().csrfTokenRepository(csrfTokenRepository())。和().addFilterAfter(新的CsrfHeaderFilter(),CsrfFilter.class)然后这次我使用apppostman(chrome插件)发送了请求。我专门将保存在服务器中的XSRF-TOKEN放入请求中,然后我得到了以下错误<代码>{“时间戳”:1459886043768,“状态”:403,“错误”:“禁止”,“消息”:“在请求参数“_CSRF”或标头“XSRF-Token.”,“路径”/“登录”上发现无效的CSRF令牌“a49e1258-1912-461e-b918-96a8b4b9fbd7”。
知道吗@muguaI想知道是否正在删除repository.setSessionAttributeName(“u csrf”);这会有所不同。我想说,如果您只是使用标题名称,那么就没有必要这样做。