CSRF (Cross-Site Request Forgery) is an attack where a malicious site tricks your browser into making an unwanted request to a site you're logged into—like transferring money, changing email, or deleting data. Works because browsers auto-send cookies with requests. Prevent with CSRF tokens (random secret in forms) and SameSite cookies (block third-party requests).
Protect all state-changing actions (POST, PUT, DELETE requests) with CSRF tokens. Use SameSite=Lax or Strict on session cookies to block cross-site requests. Most frameworks have CSRF protection built-in (Django, Rails, Laravel)—enable it. For APIs consumed by your own frontend, use SameSite cookies. For public APIs, use token-based auth (JWT, API keys) instead of cookies.
Cybersecurity
Cross-Site Request Forgery