How CSRF Attacks Work
You'll learn: The step-by-step mechanics of how attackers exploit authenticated browser sessions to trick victims into performing unwanted actions.
The Core Idea
Cross-Site Request Forgery (CSRF) attacks weaponize the browser's automatic credential-sending behavior. When you're logged into a site, your browser automatically includes authentication cookies with every request to that domain. An attacker crafts a malicious request that, when triggered by your browser, appears to come legitimately from you—because it does, just without your knowledge or consent.
The Attack Chain
Step 1: Victim Authentication
You log into your bank at bank.com. The server sets an authentication cookie that your browser stores and will automatically send with future requests to bank.com.
Step 2: Attacker Crafts Malicious Request
The attacker creates a webpage on evil.com containing a hidden form or image tag that makes a state-changing request to bank.com:
<img src="https://bank.com/transfer?to=attacker&amount=1000">
Step 3: Victim Visits Attacker's Site
You visit evil.com while still logged into bank.com (common when using multiple tabs).
Step 4: Browser Automatically Sends Credentials
Your browser loads the malicious page and encounters the crafted request. It automatically includes your bank.com authentication cookie—because that's what browsers do.
Step 5: Server Processes Forged Request
bank.com receives what appears to be a legitimate, authenticated request from you and executes the transfer.
The victim never sees or approves the action. The attacker exploited the trust relationship between the browser and server.
Key Takeaway: CSRF attacks succeed because browsers automatically include authentication credentials with cross-origin requests, allowing attackers to forge state-changing operations that appear legitimate to the server.