CSRF
一句话解释
CSRF (Cross-Site 请求 Forgery) 是 attack 哪里 malicious website tricks 用户's 浏览器到 制作 unwanted 请求到 site 哪里它们是 logged in.
用大白话说
CSRF (Cross-Site Request Forgery) is a web security attack where a malicious site tricks the browser into making a request to a target site on behalf of the logged-in user. Because the browser automatically includes cookies, the request appears legitimate to the target server.
For example: a user is logged into their bank. They visit a malicious site that contains a hidden form that submits a transfer to the bank's URL. The browser sends the request with the user's session cookie, and the bank processes it as if the user intended it.
Prevention includes: anti-CSRF tokens (a random token embedded in forms that the server validates), SameSite cookie attribute (prevents cookies from being sent with cross-site requests), and checking the 原点 or Referer header. Modern browsers' default SameSite=Lax behavior provides significant CSRF protection.
示例
<!-- Malicious site embeds: -->
<form action="https://bank.com/transfer" method="POST">
<input type="hidden" name="to" value="attacker">
<input type="hidden" name="amount" value="10000">
</form>
<script>document.forms[0].submit();</script>
<!-- Prevention: anti-CSRF token -->
<input type="hidden" name="csrf_token" value="random_token_from_server">CSRF attack 表单 and defense — anti-CSRF 令牌那个 attacker cannot guess or access.
相关术语
相关资源
相关课程
- Web Security 基础
Web security 包含 CSRF.
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。