Preparing your workspace
CSRF tricks an authenticated browser into sending an unwanted request to a trusted application.
When authentication is based on cookies, browsers automatically include those cookies with requests to the relevant site. An attacker may try to cause a victim's browser to make a state-changing request without the victim intentionally performing that action. CSRF defenses can include appropriate SameSite cookie settings, anti-CSRF tokens, checking request origins where appropriate, and designing APIs so state-changing requests require intentional protections. The exact defense depends on the authentication model.
A cookie-authenticated account settings page should prevent another website from silently triggering an email or password change.
POST /api/profile/email
Content-Type: application/json
X-CSRF-Token: secure-token
{
"email": "new@example.com"
}The server checks the CSRF protection mechanism before accepting a sensitive state-changing request.