Sovra Recon·Glossary · CSRF

CSRF (Cross-Site Request Forgery): Definition, Example, and Protection

By Solan Barlet, co-founder of Sovra Recon
Updated October 29, 2026

In short

A CSRF (Cross-Site Request Forgery) vulnerability allows a malicious site to trick a user logged into another application into performing an action without their knowledge—such as changing their email address, authorizing a bank transfer, or creating an administrator account. It works because the browser automatically includes session cookies in the request, even when the request originates from another site. The standard protection is an unpredictable anti-CSRF token, which the server verifies with every sensitive action.

How a CSRF Attack Works

The victim is logged into an application, such as a website’s administration interface. They then visit a booby-trapped page, received via email or hidden within a link. This page contains an invisible form that is automatically submitted to the targeted application—for example, to the page that changes the account’s email address.

The browser sends the request with the victim’s cookies: to the server, it appears authentic. The attacker does not see the response, but the action is executed. Three conditions must be met for a successful attack: an action that has value, a session that relies solely on cookies, and parameters that the attacker can know in advance.

How to Protect Against It

  • Anti-CSRF token: a random value associated with the session, included in every form and verified on the server side. Most frameworks support this natively.
  • SameSite Cookies: The SameSite=Lax or Strict attribute prevents the session cookie from being sent with most requests originating from another site. This is a supplementary defense; it is not sufficient protection on its own.
  • Origin verification: Check the Origin or Sec-Fetch-Site headers to reject modification requests originating from another site.
  • No sensitive actions via GET: a GET request must never modify data.
  • Enhanced verification: Require the password or a second factor for critical operations (changing an email address, making a bank transfer).

Frequently asked questions

Is an API authenticated by a token in the Authorization header vulnerable to CSRF?

Generally not: the browser does not automatically add this token, unlike cookies. The risk reemerges as soon as authentication relies, even partially, on a cookie.

What is the difference between CSRF and XSS?

An XSS attack executes the attacker’s code within the application’s page; a CSRF attack causes a request to be sent from another site. An XSS attack can bypass anti-CSRF protections, since the injected script can read the token present on the page.

Sources

Find out where an attacker would get in.

Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.