![](/img/trans.png)
[英]Passing JSessionId and CSRF-Token in Spring Boot for POST
[英]CSRF token is configured but still POST requests are not working in spring boot app
我有一個starnd Spring 啟動應用程序,並在我的 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();
I am using CookieCsrfTokenRepository and using Postman to hit the slam API I have authenticated myself before hitting this API and have the JSESSIONI, XSRF-TOKEN from the server side and passing it in the header to slam API
在此之后,我只是發送請求,但我仍然收到 403 禁止。 另一方面,如果我使用以下配置禁用 CSRF 令牌。 發布請求正在成功運行。
http.csrf().disable()
通過我的 POSTMAN 的 post 請求使 CSRF 令牌正常工作我缺少什么?
spring 的文檔說明如下:
默認情況下,CookieCsrfTokenRepository 將寫入名為 XSRF-TOKEN 的 cookie,並從名為 X-XSRF-TOKEN 的 header 或 HTTP 參數 _csrf 中讀取它。 這些默認值來自 AngularJS
在您提供的 postman 圖像中,我只能看到 xsrf 令牌作為 cookie,但沒有 header。 您需要從該 cookie 中提取值並將其發送回正確的 header 或正確的查詢參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.