Cross-Site Request Forgery (CSRF)
Why CSRF Matters
CSRF exploits the fact that browsers automatically include cookies with every request to a domain, regardless of which page initiated the request. If your application performs state-changing actions (transfers, settings changes, account deletion) based solely on cookie authentication, it is vulnerable to CSRF.
Modern defenses include SameSite cookies (which prevent cookies from being sent with cross-origin requests), CSRF tokens (unique per-session or per-request tokens that the attacker cannot predict), and checking the Origin/Referer header. SameSite=Lax or SameSite=Strict on session cookies is the simplest and most effective defense.
APIs that use bearer tokens (like JWT in Authorization headers) instead of cookies are inherently immune to CSRF because the token is not automatically included in cross-origin requests. This is one reason token-based authentication has become popular for single-page applications.
How to Check
A security audit checks for SameSite cookie attributes and other CSRF defenses. Verify your session cookies have SameSite=Lax or SameSite=Strict. For applications using cookie-based authentication, also implement CSRF tokens for state-changing endpoints.