Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
The community reviewed whether to reopen this question 2 years ago and left it closed:
Needs more focus Update the question so it focuses on one problem only by editing this post.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
传统 CSRF 攻击的工作原理是在攻击者的站点上放置预先填充的表单并跨域提交。然后,它使用随请求自动发送的凭据,以浏览器所有者的身份为幌子发送攻击者的数据。
通过在 cookie(或会话)和表单中放入令牌并检查它们是否匹配,您可以防御这种情况。攻击者不能只是发送请求来获取 CSRF 令牌,因为:
当您处理网络服务(并且您需要使该 API 跨源工作)时,情况会有所不同。这里的关键防御是设计 API,以便:
Content-Type: application/json
请求标头)。……或者两者兼而有之。
A traditional CSRF attack works by placing a pre-populated form on the the attacker's site and submitting it cross-origin. It then uses credentials that are automatically sent with the request to send the attacker's data under the guise of the browser owner's identity.
By putting a token in both the cookies (or session) and the form and checking to see if they match, you can defend against this. The attacker can't just send a request to get the CSRF token because:
When you are dealing with a web service (and you need to make that API work across origins), things are different. The key defence here is to design the API so either:
Content-Type: application/json
request header).… or both.