Skip to content
StackDecode
System Design
13. Security ArchitectureAnimated

Cross-Site Request Forgery (CSRF)

Tricking a logged-in browser into sending a request.

The idea

A malicious site makes the browser send a request with the user's cookies.

Watch it work

Press play, pause, or step through. Some animations have settings you can change.

Victim browserBankEvil sitelogged in (cookie set)
  • current message
  • earlier
  • failure or attack

The victim is signed in to the bank in another tab.

step:
1/5
from:
Victim browser
to:
Bank
1/5

Time runs downward. Solid arrows are requests, dashed arrows are replies.

Step by step

  1. 1Use CSRF tokens
  2. 2Set SameSite cookies
  3. 3Require re-auth for sensitive actions
  4. 4Check Origin headers

Where it is used

Cookie-based apps.

Watch out for

APIs using bearer tokens are less exposed.

Related