CSRF Explained: The Attack That Uses Your Own Login Against You
Cross-Site Request Forgery (CSRF) is one of the sneakiest web attacks because it does not steal your password or break into a server. It uses something far simpler: the fact that you are already logged in.
The Classic Scenario
Imagine you are logged into your bank in one browser tab. In another tab, you open a blog post, a forum page, or an email link. Hidden inside that page is something like this:
<img src="https://yourbank.example/transfer?to=attacker&amount=1000">
Your browser sees an image tag and helpfully requests that URL — and because you are logged into your bank, the browser attaches your session cookie automatically. The bank sees a request from an authenticated user and processes the transfer. You never clicked anything. You never saw anything. The “image” is invisible.
That is CSRF: an attacker tricks your browser into making a request you never intended, abusing the trust a site places in your authenticated session.
Why It Works
Websites authenticate requests with cookies, and browsers send cookies automatically with every request to that site — including requests triggered by other sites. The server cannot tell whether the request came from its own page or from an attacker’s page, because the cookie looks identical either way. The attacker never sees your cookie; they just ride on it.
CSRF targets any action that changes state: changing an email address or password, transferring money, deleting an account, posting content. Read-only pages are not interesting to CSRF — the damage comes from actions.
Real-World Impact and Bug Bounty Relevance
CSRF bugs still pay on bug bounty programs, especially in account settings, password changes, and any “one-click” action that lacks protection. The classic finding: a password-change or email-change endpoint that accepts a simple GET request or a POST with no token. Testers find these by intercepting requests (Burp Suite, which we covered earlier) and replaying them from a different origin.
How Developers Stop It
The standard defense is an anti-CSRF token: a random, unpredictable value embedded in every form and verified by the server on every state-changing request. An attacker’s page cannot read the token (same-origin policy blocks it), so forged requests fail validation. Other layers include:
- SameSite cookies: Marking session cookies SameSite=Lax or Strict tells the browser not to send them with cross-site requests — this single flag kills most CSRF.
- Checking the Origin/Referer header: Rejecting state-changing requests that do not come from your own site.
- Requiring re-authentication for sensitive actions like password changes or money transfers.
How to Test for It (Legally)
On your own lab or a program that explicitly allows it:
- Log into the app and perform a state-changing action (change a profile setting) while intercepting the request in Burp Suite.
- Remove any token parameter and replay the request from a different origin — for example, a simple HTML page on another domain that auto-submits the same form.
- If the action succeeds without the token, you have found CSRF.
Then report it properly: describe the vulnerable endpoint, the exact request, the impact (what an attacker could change), and a suggested fix. We covered report writing in an earlier post — a clear reproduction gets paid faster than a vague claim.
Your Defense Checklist
As a user: log out of sensitive sites when you are done, be cautious with links while logged in, and use a browser that enforces SameSite cookies (all modern browsers do by default now). As a developer: tokens on every state-changing request, SameSite cookies, and never let a GET request change anything important.
CSRF is a reminder that on the web, “authenticated” and “intended” are two different things. Good security checks both.
And as always: only test systems you own or have written permission to test.



Comments
Post a Comment