# Cross-Site Request Forgery (CSRF)

> An attack that tricks your browser. It sends a request you never meant to send.

**Field:** Software Development  
**Category:** Security  
**Also known as:** CSRF, XSRF, Session Riding

## Think of it like

Think of it like a trick. Someone hides a cheque under a card, and you sign it.

## Definition

Cross-site request forgery tricks your browser into sending a request. You are logged in to your bank in one tab. A bad page in another tab quietly sends a form to the bank. Your browser adds your login cookie, so the bank thinks it was you. The fix is a secret token on every form, plus cookies marked SameSite.

## Example

Jack is logged in to his shop admin. He opens a link from an email, and a hidden form on that page changes his account email to the attacker's.

## Why it matters

It turns your own login against you. Any action a user can do by a click can be forged this way.

## Common mistake

Letting a GET request change data. A single image tag on another site can then fire it.

## Three principles

- **Your browser is tricked.** Not your password stolen.
- **Cookies ride along.** So it looks like you.
- **Tokens and SameSite.** The usual fix.

## Related terms

- [Cross-Site Scripting (XSS)](https://learn.benibix.com/term/development/cross-site-scripting)
- [HTTP Cookie](https://learn.benibix.com/term/development/cookie)
- [Session (Web)](https://learn.benibix.com/term/development/session)
- [POST Request](https://learn.benibix.com/term/infrastructure/post-request)

## Told apart from

- [XSS vs CSRF](https://learn.benibix.com/compare/xss-vs-csrf): Cross-site scripting and cross-site request forgery both abuse the trust between you and a site, in opposite ways. XSS puts the attacker's script on the real site, where it runs as if the site wrote it. CSRF stays on the attacker's page. It tricks your browser into sending a request to the real site. Safe output stops XSS. Tokens and SameSite cookies stop CSRF.
- [SSRF vs CSRF](https://learn.benibix.com/compare/ssrf-vs-csrf): People think SSRF and CSRF are the same trick because the names sound alike, and they are not. In CSRF, the attacker gets your browser to send a request to a site you are logged in to. In SSRF, the attacker gets the server itself to send the request. Often it goes to a private address inside the server's own network.

---

Source: https://learn.benibix.com/term/development/cross-site-request-forgery
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
