What is CSRF?
You'll learn what Cross-Site Request Forgery attacks are and why authenticated users can be tricked into performing unintended actions.
What is Cross-Site Request Forgery?
Cross-Site Request Forgery (CSRF, pronounced "sea-surf") is a web security vulnerability where an attacker tricks a victim's browser into making unwanted requests to a site where the victim is already authenticated. Unlike XSS, which exploits a user's trust in a website, CSRF exploits a website's trust in the user's browser.
How CSRF Works
Imagine you're logged into your bank's website. While still logged in, you visit a malicious site. That site contains hidden code that makes your browser send a request to your bank—perhaps to transfer money. Because your browser automatically includes your authentication cookies with every request to the bank, the bank thinks you intentionally made that request.
The attack works because:
- Browsers automatically send credentials (cookies, HTTP authentication) with every request to a domain
- The malicious site forges a request that looks legitimate
- The target site can't distinguish between a real user action and a forged one
Common CSRF attack scenarios include:
- Changing account settings (email, password)
- Making purchases or financial transactions
- Posting content on behalf of the victim
- Modifying access permissions
Why CSRF is Dangerous
CSRF attacks don't steal data directly—they make victims perform actions they didn't intend. The attacker leverages the victim's existing authenticated session to bypass access controls entirely.
Key Takeaway: CSRF exploits the web's stateless nature and automatic credential transmission, allowing attackers to forge requests that appear to come from legitimate, authenticated users.