首页 > 解决方案 > spring security csrf 保护不接受标头或cookie(X-XSRF-token)

问题描述

我正在使用 Spring Security 开发一个 SPRING 休息服务,并且我已经启用了 CSRF 令牌,如下所示

http
    .csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()).

现在,问题是我需要将 XSRF 令牌传递给服务器以完成身份验证,因为我已经尝试了几种使用 curl 命令的方法,但没有运气,任何帮助都会有很大的帮助。以下是我使用过的 curl commnads 示例和服务器响应。

    curl -i -X POST -d username=user1@gmail.com -d password=user  -c 
    /opt/cookies.txt --header "X-XSRF-TOKEN=18280b55-8fc7-4266-9116- 
    d21df13b841d"  http://localhost:8080/login

这是来自服务器的响应

HTTP/1.1 401 
Set-Cookie: XSRF-TOKEN=18280b55-8fc7-4266-9116-d21df13b841d; Path=/
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Security-Policy: default-src 'self'; base-uri 'self';     https://fonts.google.com/; script-src 'self' https: 'unsafe-inline' ; style-src 'self' https: 'unsafe-inline' ; connect-src 'self' ; font-src https://fonts.google.com/ ; form-action 'self' ; frame-ancestors 'none' ; img-src 'self' ; media-src 'self' ; object-src 'none' ; plugin-types 'none' ; child-src 'none'; object-src 'none'
Referrer-Policy: origin
Content-Length: 0
Date: Mon, 20 May 2019 18:56:10 GMT

标签: javaspringspring-bootspring-securitycsrf-token

解决方案


推荐阅读