Understanding CSRF: How Websites Get Tricked Into Trusting You
Published on
/
4 mins read
/
––– views
Share:
Introduction
Modern websites remember who you are using sessions and cookies. That's what keeps you logged in without entering your password again and again.
But this convenience comes with a hidden risk.
What if a malicious website could force your browser to perform actions on another site… without you knowing?
That's exactly what a CSRF (Cross-Site Request Forgery) attack does.
What is CSRF?
A CSRF attack tricks your browser into sending a request to a website where you are already authenticated.
The key idea is simple:
You are logged into a trusted site (like a bank or social media)
You visit a malicious site
That site silently sends a request using your credentials
Since your browser automatically includes cookies, the target website thinks you made the request.
As described in the reference material, this works because authentication is stored in the browser (usually via cookies), which are automatically attached to requests.
Why CSRF Works
Web apps rely heavily on cookies for authentication.
Here's the problem:
Cookies are automatically sent with every request to the same domain
Websites often don't verify where the request came from
So, a malicious site can "borrow" your session
That's the core vulnerability.
A Simple Example
Imagine this flow:
You log into your bank account
You don't log out
You open another random website
That website silently triggers this request:
https://bank.com/transfer?to=attacker&amount=5000
Your browser sends this request with your session cookie.
The bank processes it like a normal request.
You just lost ₹5000… without clicking anything.
Real Attack Example (GET-based CSRF)
One classic way CSRF works is through something as harmless as an image.