【发布时间】:2021-08-13 19:43:51
【问题描述】:
我有一个 Starnd Spring Boot 应用程序,并在我的 sprint 安全配置中配置了 csrf,如下所示:
http.csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).and().authorizeRequests()
.mvcMatchers(HttpMethod.POST,"/slam").authenticated()
.antMatchers("/myPage").authenticated()
.antMatchers("/login").permitAll()
.antMatchers("/contact").denyAll()
.and().formLogin().and().httpBasic();
我正在使用 CookieCsrfTokenRepository 并使用 Postman 来命中 slam API 我在点击这个 API 之前已经对自己进行了身份验证,并从服务器端获得了 JSESSIONI、XSRF-TOKEN 并将其在标头中传递给 slam API
在此之后,我只是发送请求,但我仍然收到 403 禁止。 另一方面,如果我使用以下配置禁用 CSRF 令牌。发布请求正在成功运行。
http.csrf().disable()
通过我的 POSTMAN 的 post 请求使 CSRF 令牌正常工作我缺少什么?
【问题讨论】:
标签: spring spring-boot spring-security csrf