Cross-Site Request Forgery (CSRF)
Learn how CSRF attacks forge authenticated requests and how CSRF tokens and SameSite cookies defend against them.
What is CSRF?
Cross-Site Request Forgery (CSRF) tricks an authenticated user's browser into making unauthorized requests to a web application. The browser automatically sends cookies with requests, so the server cannot distinguish legitimate from forged requests without extra measures.
How CSRF Works
Scenario:
- Victim is logged into bank.com (session cookie in browser)
- Victim visits attacker's page with:
<img src="https://bank.com/transfer?to=attacker&amount=1000"> - Browser sends the GET request with the bank.com cookie attached
- Bank processes the transfer
All lessons in this course
- SQL Injection: How and Why It Works
- Cross-Site Scripting (XSS)
- Cross-Site Request Forgery (CSRF)
- Security Misconfiguration and Exposed Services