Use this when protecting against forged cross-site requests.
CSRF
CSRF (cross-site request forgery) makes a logged-in user's browser send unwanted requests to a site. Anti-CSRF tokens, SameSite cookies and checking the Origin header prevent it.
1. CSRF tricks browsers into sending authenticated requests.
2. Defend: anti-CSRF tokens, SameSite, Origin checks.
3. Use framework protections.
4. No state changes on GET.
5. Re-authenticate for critical actions.
attacker page → forged request → token/SameSite check rejects
Context & applicabilityCommon mistakes · platform/version boundaries
- CSRF protection disabled for APIs that still use cookie authentication.
- State-changing GET requests (
/delete?id=5). - Token checked only when present (missing token accepted).
- Same token for all users or never rotated.
Operational reference
Fast context before you go deeper.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Use anti-CSRF tokens on state-changing requests.
- SameSite cookies block most CSRF.
- Check the Origin header.
- CSRF tokens on state-changing forms — present
- SameSite cookie settings — defence
- Origin/Referer checks — server validation
ReferenceWhy it matters1 section · depth on demand
Defences
1. Anti-CSRF token in every state-changing form or request, validated server-side.
2. SameSite=Lax or Strict session cookies.
3. Check Origin/Referer headers for state-changing requests.
4. Never change state with GET requests.
APIs that use bearer tokens in headers (not cookies) are not exposed to classic CSRF.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Cross-Site Request Forgery (CSRF) tricks a logged-in user's browser into sending a request to a site where they are authenticated — changing an email address or transferring money — because the browser automatically attaches session cookies.
Defences:
| Control | How it helps |
|---|---|
| Anti-CSRF tokens | Unpredictable token required in state-changing requests |
| SameSite cookies | Browser does not send session cookie cross-site |
| Check Origin/Referer | Reject requests from other origins |
| No state changes via GET | Safe methods stay safe |
| Re-authentication for critical actions | Extra confirmation |
Most web frameworks include CSRF protection — make sure it is enabled for every state-changing endpoint. APIs using bearer tokens in headers (not cookies) are not exposed to classic CSRF.
ReferenceConfiguration & state1 section · depth on demand
Example: synchronizer token
<form method="post" action="/transfer">
<input type="hidden" name="csrf_token" value="{{ session.csrf_token }}">
...
</form>
Documented example, not captured output. The server compares the submitted token with the session value and rejects mismatches. Most frameworks (Django, Laravel, Spring Security, ASP.NET) do this automatically — do not disable it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Web Security → CSRF. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://owasp.org/www-project-application-security-verification-standard/ · confidence 94%