← Back to Blog

CSRF Protection: How Cross-Site Request Forgery Works

CSRF attacks explained: how they work, CSRF tokens, SameSite cookies, double-submit pattern, and framework protection.

How CSRF Works

An attacker tricks a logged-in user into making a request to your site. The browser automatically includes cookies, so the server thinks it is a legitimate request.

Prevention Methods

  • CSRF tokens: Unique token per session, verified on every state-changing request
  • SameSite cookies: SameSite=Strict or SameSite=Lax prevents cross-origin cookie sending
  • Check Origin/Referer headers

Try It Free

Use our free online tool — 100% client-side, no data leaves your browser.

Open Hash Generator

Related Tools & Articles