What is Cross-Site Request Forgery (CSRF)
You'll learn: How attackers can trick your browser into performing unwanted actions on websites where you're already logged in.
The Core Concept
Cross-Site Request Forgery (CSRF) is an attack that exploits the trust a website has in your browser. When you're authenticated to a website, your browser automatically sends your session cookies with every request to that site. CSRF attacks abuse this automatic behavior by tricking your browser into making requests you didn't intend to make.
Here's how it works: Imagine you're logged into your bank at mybank.com. Your session cookie proves you're authenticated. An attacker creates a malicious website or email containing a hidden request to mybank.com/transfer?to=attacker&amount=1000. When you visit the attacker's page while still logged in to your bank, your browser automatically includes your bank session cookie with that transfer request. The bank sees a legitimate-looking authenticated request and processes it—even though you never intended to transfer money.
The Exploitation Chain
The key to CSRF is that the attack leverages your existing authenticated session. The attacker doesn't steal your credentials or cookies—they don't need to. They simply craft malicious requests that your browser sends on their behalf, complete with your valid authentication.
Real-World Analogy
Think of CSRF like someone slipping a signed check into your outgoing mail. You've already authenticated yourself by signing checks earlier (your session). The attacker doesn't forge your signature (steal credentials)—they just trick the mail carrier (your browser) into delivering a check you didn't knowingly write, using your legitimate signature.
Key Takeaway: CSRF exploits the automatic inclusion of authentication credentials (like session cookies) in cross-site requests, allowing attackers to perform unauthorized actions as the victim without needing to steal their credentials.