Cross-Site Request Forgery (CSRF)
A malicious site causes a victim’s browser to send authenticated state-changing requests they did not intend.
Overview
Because browsers attach cookies automatically, a cross-origin form or fetch can trigger actions as the logged-in victim when the server relies on cookies alone and lacks anti-CSRF tokens or SameSite protection.
How it works
Because browsers attach cookies automatically, a cross-origin form or fetch can trigger actions as the logged-in victim when the server relies on cookies alone and lacks anti-CSRF tokens or SameSite protection.
Example
Impact
Unauthorized state changes - fund transfers, email/password changes, privilege grants - performed as the victim.
Detection
Replay state-changing requests with the token removed/altered and from a foreign origin/referer; flag endpoints that still succeed.
Prevention
- Use anti-CSRF tokens (synchronizer or double-submit) on all state-changing requests.
- Set SameSite=Lax or Strict on session cookies.
- Verify Origin/Referer for sensitive actions.
- Prefer non-cookie auth (Authorization header) for APIs.