简体   繁体   English

Spring Boot 不需要 CSRF 令牌

[英]Spring Boot does not require CSRF token

I have a Spring Boot 1.5.12 application and CSRF protection is enabled as default.我有一个 Spring Boot 1.5.12 应用程序,默认启用 CSRF 保护。 I use the CSRF token when I submit my POST request.我在提交 POST 请求时使用 CSRF 令牌。

However, there are some URLS that needs to be fetched via a GET requests, with cookie information but does not require a CSRF token ie但是,有一些 URLS 需要通过 GET 请求获取,带有 cookie 信息但不需要 CSRF 令牌,即

<a href="/stuff"><i class="stuff-xs"></i><span>Stuff</span></a>

How can I force my Spring Boot application which requires a CSRF token for such requests too?如何强制我的 Spring Boot 应用程序也需要 CSRF 令牌来处理此类请求?

PS: I've some comments about CSRF protection not needed for GET requests. PS:我有一些关于 GET 请求不需要 CSRF 保护的评论。 However, it should be protected for it too: https://www.acunetix.com/websitesecurity/csrf-attacks/但是,它也应该受到保护: https : //www.acunetix.com/websitesecurity/csrf-attacks/

The idea of CSRF is to prevent modification of data that you don't initiated. CSRF 的想法是防止修改您未启动的数据。 It is supposed that GET method cannot modify data and that's why it is safe to call any GET URL without CSRF token.假设 GET 方法不能修改数据,这就是为什么在没有 CSRF 令牌的情况下调用任何 GET URL 是安全的。 But if you implement some data changes on GET, then you should change your logic and move it to PUT, POST, DELETE, or PATCH methods.但是,如果您在 GET 上实现了一些数据更改,那么您应该更改您的逻辑并将其移动到 PUT、POST、DELETE 或 PATCH 方法。

If I understand the question correctly, you want to send a CSRF token with a GET request.如果我正确理解了这个问题,您想通过 GET 请求发送 CSRF 令牌。

But GET or HEAD HTTP verbs don't need CSRF protection.但是 GET 或 HEAD HTTP 动词不需要 CSRF 保护。 They are auto immuned to CSRF.他们对 CSRF 自动免疫。

CSRF mainly dupe the user into doing some activity on a malicious webpage which will then trigger a POST, PUT or DELETE verb in the original page impersonating the victim user. CSRF 主要是欺骗用户在恶意网页上进行一些活动,然后在冒充受害用户的原始页面中触发 POST、PUT 或 DELETE 动词。

The good thing is, CSRF cannot read anything due to same origin policy.好消息是,由于同源策略,CSRF 无法读取任何内容。 It is solely based on exploiting the unsafe HTTP methods like POST, PUT and DELETE.它完全基于利用不安全的 HTTP 方法,如 POST、PUT 和 DELETE。

Therefore, GET or HEAD verbs don't need CSRF cookie.因此,GET 或 HEAD 动词不需要 CSRF cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM