Cross-Site Request Forgery (CSRF) is a dangerous web application security vulnerability that tricks authenticated users into performing unintended actions on a trusted website. Because the victim is already logged in, the malicious request appears legitimate to the application, making CSRF attacks difficult to detect.
This article explains what CSRF is, how it works, common attack scenarios, and best practices for prevention.
Cross-Site Request Forgery (CSRF) is an attack that forces a user’s browser to send unauthorized requests to a web application in which the user is currently authenticated.
The application processes the request as if it were intentionally made by the user, potentially resulting in unauthorized actions.
Because the browser automatically includes session cookies, the request appears valid.
CSRF attacks typically target actions that rely solely on session cookies for authentication.
CSRF vulnerabilities can result in:
CSRF remains a major concern in web application security.
| Feature | CSRF | XSS |
|---|---|---|
| Attack Focus | Exploits authenticated sessions | Injects malicious scripts |
| Victim | Web application | End users |
| Dependency | User must be logged in | User must view malicious content |
| Prevention | CSRF tokens, same-site cookies | Input validation, encoding |
Although different, both attacks often coexist in vulnerable applications.
With the rise of single-page applications (SPAs), APIs, and cloud-based services, CSRF protection has become more critical than ever. Modern frameworks now provide built-in defenses, but misconfigurations can still leave applications vulnerable.
CSRF continues to be listed in major security frameworks, including the OWASP Top 10.
Cross-Site Request Forgery (CSRF) is a serious web application vulnerability that exploits user trust and authenticated sessions. By implementing anti-CSRF tokens, secure cookie attributes, and proper request validation, organizations can effectively defend against CSRF attacks.
In today’s web-driven world, CSRF prevention is a critical part of application security.