1 CSRF Mechanics
Cross-Site Request Forgery (CSRF) exploits the browser's automatic inclusion of cookies in cross-origin requests. An attacker's page can submit forms to a different origin — the victim's browser includes their session cookie automatically.
Attack example:
<!-- Attacker's page (evil.com) -->
<form action="https://bank.com/transfer" method="POST" id="csrf">
<input type="hidden" name="to" value="attacker-account">
<input type="hidden" name="amount" value="5000">
</form>
<script>document.getElementById("csrf").submit();</script>When a victim visits evil.com while logged into bank.com, the form auto-submits and the browser automatically includes the bank.com session cookie. The bank sees a valid authenticated request.
What CSRF can do:
- Transfer money or change account settings
- Change email/password
- Delete data or make purchases
- Any state-changing operation the user is authorized for