Skip to content
ShankarStack
MediumCSRF

Cross-Site Request Forgery (CSRF)

A victim's browser is tricked into sending an authenticated, state-changing request the user didn't intend.

CSRF abuses the fact that browsers automatically attach cookies to requests. If a state-changing endpoint relies only on an ambient session cookie, a malicious page can cause the victim's browser to submit it.

Root cause

State-changing requests are authenticated only by an automatically-sent credential (cookie) with no proof the request was intentional.

Impact

Attacker-chosen state changes performed as the victim — settings changes, transfers, or other sensitive actions within their privileges.

Detection methodology

Review state-changing endpoints for anti-CSRF tokens and/or SameSite cookie protections; confirm safe methods are side-effect free.

Remediation

Use anti-CSRF tokens tied to the session, set SameSite=Lax/Strict on session cookies, and require re-authentication for high-value actions. Prefer framework-provided protections.

Secure coding guidance

Never perform state changes on GET; combine SameSite cookies with per-request tokens; verify Origin/Referer for sensitive operations.