Cross-Site Request Forgery

Have you ever been logged into your bank or email and then clicked a random link from another site—only to find something odd happened in your account? That's CSRF in action.
A CSRF (Cross-Site Request Forgery) attack is a type of web security vulnerability that tricks a victim into submitting a malicious request to a web application where they're already authenticated. CSRF exploits the trust a site has in the user's browser.
🔍 How CSRF Works
-
Victim logs in to a legitimate website (e.g., bank.com) and has a valid session with a cookie stored in their browser.
-
The victim then visits a malicious website (controlled by the attacker) while still logged in.
-
The attacker's site crafts a request (e.g., fund transfer) to bank.com and automatically sends it using the victim's browser.
-
Since the request includes the valid session cookie, the bank processes it as if the user had initiated it.
📌 Example of CSRF
htmlCopyEdit<!-- Malicious HTML on attacker's site --> <img src="https://bank.com/transfer?to=attacker&amount=1000" />
When the victim's browser loads this image, it silently sends a GET request to bank.com using the victim's session.
🧨 Common Targets
-
Fund transfers
-
Email or password changes
-
Purchasing items
-
Deleting data
✅ How to Prevent CSRF
-
Use CSRF tokens: Unique tokens in forms that must match the user's session.
-
SameSite cookies: Set cookies with SameSite=Strict or Lax to restrict cross-origin requests.
-
Double-submit cookies: Send the token in both a cookie and request body/header.
-
Check referer/origin headers: Ensure requests come from valid sources.
-
User re-authentication for critical operations.
🔐 Modern Defense: SameSite Cookie Attribute
httpCopyEditSet-Cookie: sessionid=xyz; SameSite=Strict; Secure
This prevents the browser from sending cookies along with cross-site requests, mitigating CSRF.
📘 Related Vulnerability
-
XSS (Cross-Site Scripting): While CSRF abuses trust in the user, XSS abuses trust in the browser content.
🎯 Case Study: YouTube CSRF Vulnerability (2008)
In 2008, a security researcher named Nir Goldshlager discovered a significant CSRF vulnerability in YouTube. The flaw allowed an attacker to delete any video from a user's account without their knowledge or permission, as long as the user was logged in.
How the Attack Worked:
A victim, already logged into their YouTube account, could be tricked into visiting a malicious website or clicking a crafted link. This site would automatically make a request to:
https://www.youtube.com/video_delete?video_id=xyz
Because the victim's browser was authenticated with YouTube, the server would accept the request and delete the specified video. There was no CSRF token used to validate whether the request was intentional.
Why It Was Dangerous:
This meant anyone could delete content from another user's account just by luring them into visiting a web page. No pop-up confirmation or password prompt stood in the way. This vulnerability could have led to mass deletion of content, abuse of high-profile accounts, and loss of user trust.
Google's Response:
Google quickly patched the issue after it was reported. They added proper CSRF protection mechanisms, including CSRF tokens and confirmation dialogs for sensitive actions like video deletions. This incident also emphasized the importance of bug bounty programs, which reward ethical hackers for discovering such vulnerabilities responsibly.
Key Takeaways:
-
Even trusted platforms like YouTube can suffer from basic web vulnerabilities like CSRF.
-
Protecting sensitive operations with CSRF tokens and user confirmations is essential.
-
Responsible disclosure and bug bounty programs are critical to keeping large platforms secure.
🏦 Case Study: ING Bank CSRF Vulnerability (2011)
In 2011, security researchers discovered a critical CSRF vulnerability in ING Direct, a major European online banking platform. The flaw allowed attackers to initiate unauthorized money transfers from users' accounts.
What Was the Issue?
ING's online banking portal allowed users to transfer funds after logging in. However, the funds transfer request could be triggered via a simple HTTP GET or POST request—and there was no CSRF protection in place.
How the Attack Worked:
- A victim logs into their ING Direct account in one browser tab.
- The victim is then tricked into visiting a malicious website in another tab.
- That site silently triggers an HTTP POST request to ING's money transfer endpoint, such as:
<form action="https://my.ingdirect.nl/transfer" method="POST">
<input type="hidden" value="NL99EVIL0123456789" />
<input type="hidden" value="1000" />
<input type="submit" />
</form>
<script>document.forms[0].submit();</script>
The victim's browser sends the request with a valid session cookie.
-
The bank interprets it as a legitimate action by the user, and the funds are transferred.
Why It Was Dangerous:
- Attackers could drain users' bank accounts by tricking them into visiting a malicious site.
- Since it was a background request, users wouldn't even realize it happened until they saw their account balance.
- There was
, no re-confirmation of the transaction, and no CSRF token.
How ING Responded:
The issue was made public after researchers demonstrated the proof of concept. ING acknowledged the vulnerability and quickly implemented:
- CSRF token validation
- Stricter server-side request validation
- User re-authentication for sensitive operations
- Eventually, two-factor authentication (2FA) became more common for transfers.
Lessons Learned:
- CSRF in financial systems can directly lead to monetary loss.
- Relying only on session cookies for authentication is dangerous.
- Financial platforms must enforce strong protection for every state-changing request.
- Security through obscurity (e.g., assuming attackers won't find hidden parameters) never works.
Multiple choice questions (MCQs) based on CSRF (Cross-Site Request Forgery)
1. What does CSRF stand for?
A. Cross-Site Resource Falsification
B. Cross-Site Request Forgery
C. Cross-Server Request Function
D. Client-Side Request Forgery
✅ Answer: B. Cross-Site Request Forgery
2. Which of the following best describes a CSRF attack?
A. The attacker steals session cookies using JavaScript.
B. The attacker injects malicious scripts into web pages.
C. The attacker tricks the user's browser into making unauthorized requests.
D. The attacker performs SQL queries on the server.
✅ Answer: C. The attacker tricks the user's browser into making unauthorized requests.
3. Which of the following actions is most vulnerable to a CSRF attack?
A. Viewing public blog content
B. Submitting a login form
C. Changing user email address
D. Loading a CSS stylesheet
✅ Answer: C. Changing user email address
4. What is the main condition for a CSRF attack to succeed?
A. The victim must have an expired session
B. The server must use encryption
C. The victim must be authenticated and logged in
D. The attacker must have physical access to the server
✅ Answer: C. The victim must be authenticated and logged in
5. Which HTTP method is most commonly abused in CSRF attacks?
A. OPTIONS
B. GET and POST
C. PUT
D. DELETE
✅ Answer: B. GET and POST
6. Which of the following can effectively mitigate CSRF attacks?
A. Using CAPTCHAs
B. Validating input length
C. Implementing CSRF tokens
D. Obfuscating form fields
✅ Answer: C. Implementing CSRF tokens
7. What was the key vulnerability in the ING Bank CSRF case?
A. Stored XSS
B. Lack of HTTPS
C. Missing authentication
D. No CSRF protection on fund transfer
✅ Answer: D. No CSRF protection on fund transfer
8. In the YouTube CSRF case, what action was an attacker able to perform?
A. Upload unauthorized videos
B. Delete videos from any user's account
C. Hack YouTube servers
D. Access admin accounts
✅ Answer: B. Delete videos from any user's account
9. Which cookie attribute helps prevent CSRF attacks?
A. HttpOnly
B. Secure
C. Max-Age
D. SameSite
✅ Answer: D. SameSite
10. Why can't CSRF be performed using JavaScript from a different origin (by default)?
A. JavaScript is sandboxed by the Same-Origin Policy
B. Web browsers encrypt all outgoing requests
C. Cookies are blocked for JavaScript
D. CORS allows all requests to go through
✅ Answer: A. JavaScript is sandboxed by the Same-Origin Policy