CSRF explained in plain terms means an attack in which a malicious website tricks your browser into sending a request to another site where you are already logged in. The central question is how a site you never meant to visit can act with your authority, and the short answer is that your browser automatically attaches your login credentials to requests, whether you asked for them or not.
Imagine leaving your house key in the front door while you pop next door for a chat. Anyone passing by can turn that key and walk in, even though you never invited them. A cross-site request forgery attack, usually shortened to CSRF, works the same way: your logged-in session is the key in the door, and a hidden request from another site turns it.
CSRF is one of the oldest tricks on the web, and it still matters because it needs no password theft, no malware, and no skill on the victim’s part. All it needs is for you to visit a booby-trapped page while logged in somewhere else, and for that somewhere else to trust requests that arrive with your credentials attached.
Key takeaways
- CSRF is an attack that tricks your browser into sending an unwanted request to a site where you are logged in.
- It works because browsers automatically attach cookies to requests, even ones triggered by another site.
- The attacker never sees your password or your session: they simply borrow your authority for one request.
- Anti-CSRF tokens, SameSite cookies, and checking the request origin are the main defences.
- Any action that changes state, from changing an email address to transferring money, needs CSRF protection.
What CSRF is
Cross-site request forgery is a web attack that abuses the trust a website places in its users’ browsers. When you log in to a website, it gives your browser a session cookie, a small token that proves you are who you claim to be. From then on, your browser sends that cookie with every request to the site, so you do not have to log in again on every page.
The flaw is that the browser cannot tell whether you meant to make a request. If a page you are viewing contains a hidden form or an image tag pointing at another site, your browser will fetch it, and it will attach your cookies for that site as it does so. The target site sees a properly authenticated request and carries it out, having no way of knowing that the request came from a page you never intended to use.
A classic example is a money transfer. Suppose you are logged in to your bank, and you open a forum page containing a hidden form that submits a transfer to the attacker’s account. Your browser sends the form to the bank, with your session cookie attached, and the bank processes it as though you had filled in the form yourself. The attacker never learns your password; they simply ride on your session.
CSRF differs from cross-site scripting, though the two are often confused. Cross-site scripting injects malicious code into a trusted site so it runs in your browser, while CSRF needs no code on the target site at all: it simply abuses the way browsers handle requests between sites. Our guide to network security explains the wider defences that protect web traffic, and CSRF protection is one layer within them.
How CSRF works
It starts with the victim being logged in. The attacker needs a live session to ride on, so they choose a popular target, a bank, an email provider, a social network, or a shopping site, and they wait for someone who is logged in to visit their trap. The trap can be a web page, an email containing a link, or even a comment on a forum.
Next comes the forged request. The attacker crafts a request that performs an action on the target site, such as changing an email address, posting a message, or transferring funds. They hide it in something the browser will fetch automatically, a form that submits itself when the page loads, or an image tag whose source points at the target site’s action URL. The victim sees nothing unusual, perhaps just a blank image or a page that looks entirely innocent.
Then the browser does the attacker’s work for them. It sends the request to the target site and, because the request goes to a site the browser holds cookies for, it attaches the session cookie automatically. The target site checks the cookie, finds a valid session, and carries out the action. From the server’s point of view, the request looks exactly like one the user made deliberately.
Finally, the attacker collects the result. The changed email address lets them reset the victim’s password; the transfer moves money to their account; the posted message spreads the trap further. The victim may never realise anything happened until they notice the consequences, which is why CSRF is so dangerous: it is silent, and it needs only a single careless click, or sometimes no click at all.

Comparing CSRF with other web attacks
| Aspect | CSRF | Cross-site scripting |
|---|---|---|
| What it abuses | Browser trust in your session | Trust in code from a site |
| Attacker needs | A victim logged in to the target | A way to inject script into a page |
| What the attacker sees | Nothing, only the action’s result | Page contents and user data |
| Typical damage | Unwanted actions in your name | Stolen data and hijacked sessions |
| Main defence | Anti-CSRF tokens and SameSite cookies | Output encoding and content policies |
Where CSRF is used
Banking and payment sites are the highest-value targets, because a single forged request can move money. Attackers hide transfer forms in pages that look harmless, and a victim who is logged in to their bank can lose funds by doing nothing more than opening the wrong tab. Banks therefore treat CSRF protection as essential, not optional.
Email and social accounts are attacked for a different prize: control. Changing the email address on an account lets the attacker reset the password and lock the real owner out. From there they can read private messages, impersonate the victim, and spread the attack to the victim’s contacts, who trust a message that appears to come from a friend.
Content and shopping sites face the same risk at a lower value per victim. A forged request can post spam, change a delivery address, or place an order, and because these sites are visited by millions of people, even a low success rate pays. Any site where a logged-in user can change something, from a forum profile to a smart-home setting, is a potential target.
CSRF also appears in attacks on devices and internal systems. A router’s web interface, a company intranet page, or a smart device’s settings page can all be reached from a browser, and a forged request can change their configuration. This is why the attack matters beyond the big public websites: any web interface that trusts a browser session is in scope.
Strengths and limits
From the attacker’s point of view, the strength of CSRF is its simplicity. It needs no vulnerability in the target site’s code beyond missing protection, no malware on the victim’s machine, and no special skill. A single hidden form is enough, and the attack scales: one booby-trapped page can catch every logged-in visitor who stumbles across it.
It is also hard for victims to notice. There is no suspicious download, no fake login page, and often no visible sign at all. The request happens in the background, and by the time the victim discovers a changed setting or a missing sum of money, the attacker is long gone. That silence is what makes CSRF a favourite of attackers who prefer quiet theft to noisy break-ins.
Its limits are equally real. The attacker must catch the victim while logged in, and the victim must visit the trap, so the attack depends on timing and luck. Modern browsers and frameworks have also made the basic attack much harder: SameSite cookies stop many forged requests, and most web frameworks now add anti-CSRF tokens by default.
Finally, CSRF can only do what the victim could do. It cannot read data back, because the browser’s same-origin rules stop the attacker’s page from seeing the response, and it cannot perform actions the victim has no permission for. It is a narrow weapon, but within that narrow scope it is remarkably effective, which is why the defences against it are treated as standard practice. Our guide to cryptography explains the tokens and signing techniques that underpin some of those defences.
CSRF checklist
- Use anti-CSRF tokens on every form and request that changes state.
- Set session cookies with the SameSite attribute, ideally in strict mode.
- Check the Origin and Referer headers on state-changing requests.
- Require re-authentication for sensitive actions such as password changes.
- Never perform state changes through GET requests.
- Use short-lived sessions and log users out when they close the browser.
- Apply CSRF protection to API endpoints as well as web pages.
- Keep frameworks and libraries updated so their built-in protections stay current.
- Test your defences by attempting a forged request from a different origin.
Frequently asked questions
What is CSRF in simple terms?
CSRF is an attack in which a malicious page tricks your browser into sending a request to a site where you are logged in, such as your bank. The site trusts the request because it arrives with your session cookie, so it carries out an action you never asked for.
How is CSRF different from phishing?
Phishing tricks you into giving away your password, while CSRF needs no password at all. A phishing page pretends to be a real site and asks you to log in; a CSRF attack simply borrows your existing logged-in session to make a request in your name.
Can CSRF steal my password?
No. CSRF cannot read responses or steal credentials, because the browser blocks the attacker’s page from seeing the reply. What it can do is perform actions as you, such as changing an email address, which may then let the attacker reset your password by another route.
Do I need to do anything to protect myself?
As a user, the simplest habits help: log out of important sites when you finish, and avoid clicking links in suspicious emails while logged in elsewhere. Most of the real protection, though, sits with the website, which must use anti-CSRF tokens and SameSite cookies.
What is an anti-CSRF token?
An anti-CSRF token is a secret, unpredictable value that a site includes in each form and checks when the form is submitted. A forged request from another site cannot know the token, so the site rejects it, even though the session cookie is valid.
Does HTTPS stop CSRF?
No. HTTPS encrypts traffic, but it does nothing to stop a forged request, which is sent over the same encrypted connection your browser uses for everything else. CSRF protection needs tokens, SameSite cookies, and origin checks, not just encryption. Our guide to SSL certificates explains what encryption does and does not protect against.
The bottom line
CSRF explained in one line is this: a hidden request from a page you did not trust, riding on the session of a site you did, and carried out because the site could not tell the difference.
For anyone building a website, the answer is to protect every action that changes state with tokens, SameSite cookies, and origin checks. For everyone else, it is a reminder that being logged in is a kind of trust, and a browser that trusts automatically can be made to act without you.
This article is general information about how cross-site request forgery works, not advice about securing a particular application.







