← Back to Dictionary

Cross-Site Request Forgery (CSRF)

Introduction

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.

What Is Cross-Site Request Forgery (CSRF)?

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.

How CSRF Works

  1. A user logs into a trusted website.
  2. The user visits a malicious website or clicks a crafted link.
  3. The malicious site sends a forged request to the trusted application.
  4. The application executes the request using the user’s active session.

Because the browser automatically includes session cookies, the request appears valid.

Common CSRF Attack Examples

  • Changing account passwords or email addresses
  • Performing unauthorized financial transactions
  • Modifying user settings
  • Submitting forms without user consent

CSRF attacks typically target actions that rely solely on session cookies for authentication.

Risks and Impacts of CSRF Attacks

CSRF vulnerabilities can result in:

  • Account manipulation and privilege abuse
  • Financial fraud and data loss
  • Loss of user trust and reputational damage
  • Compliance violations
  • Increased risk when combined with XSS attacks

CSRF remains a major concern in web application security.

CSRF vs XSS

FeatureCSRFXSS
Attack FocusExploits authenticated sessionsInjects malicious scripts
VictimWeb applicationEnd users
DependencyUser must be logged inUser must view malicious content
PreventionCSRF tokens, same-site cookiesInput validation, encoding

Although different, both attacks often coexist in vulnerable applications.

How to Prevent Cross-Site Request Forgery

CSRF Prevention Best Practices

  • Implement anti-CSRF tokens in forms and requests
  • Use SameSite cookies to restrict cross-site requests
  • Require re-authentication for sensitive actions
  • Use custom request headers for APIs
  • Avoid using GET requests for state-changing operations
  • Implement proper session management
  • Conduct regular security testing

CSRF in Modern Cybersecurity

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.

Conclusion

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.