Skip to content
uencoder

CSRF

CSRF (cross-site request forgery) is a vulnerability where the attacker tricks a logged-in user into unknowingly sending a malicious request to the target site.

Purpose

To prevent attackers from borrowing the victim session to perform unauthorized operations.

Mechanism

The attacker hosts a malicious page containing <form> or <img> that sends a request to the target site. The browser attaches cookies automatically, and the server mistakes it for the user. Defenses: CSRF tokens (synchronizer tokens), SameSite cookies, checking Origin/Referer headers.

Use cases

  • Forged bank transfers
  • Changing account settings
  • Posting content or comments
  • Data deletion operations

Examples

  • Input
    <form action="bank.com/transfer" method="POST">
    Output
    Transfer initiated riding on cookies

    Cross-site forgery

Common errors

Relying solely on cookie authentication without a CSRF token
Add a CSRF token or SameSite=Strict

Related terms

References