Pcornel
Browse topics
Options
Recent
Favorites
Security · Technical reference

CSRF

Direct answer

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.

When to use this

Use this when protecting against forged cross-site requests.

First 30 seconds

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.

Operational verification

attacker page → forged request → token/SameSite check rejects

Context & applicabilityCommon mistakes · platform/version boundaries
Common mistakes
Common mistakes
  • 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.
Platform / version applicability
Security architecture and operations
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformSecurity architecture and operations
Scope / prerequisiteUse this when protecting against forged cross-site requests.
What next?2 suggested next steps
Evidence1
On this pageJump to a specific section
Evidence references

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.

observation · 1
Key points
  • Use anti-CSRF tokens on state-changing requests.
  • SameSite cookies block most CSRF.
  • Check the Origin header.
Key checks
  • 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:

ControlHow it helps
Anti-CSRF tokensUnpredictable token required in state-changing requests
SameSite cookiesBrowser does not send session cookie cross-site
Check Origin/RefererReject requests from other origins
No state changes via GETSafe methods stay safe
Re-authentication for critical actionsExtra 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docSecurity architecture and operations current

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%
Confirmation

Confirm action

Continue?