Skip to content

// Concept and defense

CSRF in SaaS: what it is and how to prevent it

5 minUpdated July 28, 2026By Ler em português

What CSRF is

CSRF (Cross-Site Request Forgery) is when a malicious site makes your already-logged-in user’s browser fire an action in your SaaS they did not request, taking advantage of the session cookie riding along automatically. The victim visits a trap page, and their browser, with your app’s valid session, runs "change email", "transfer", "delete" without them noticing. The attacker does not steal the session; they use it remotely.

The key point: CSRF exploits your app’s trust in the session cookie. If any authenticated request changes state just by carrying the cookie, it is a CSRF candidate.

Where it shows up in AI-built SaaS

AI-built products tend to protect the login and forget the origin boundary of the state-changing requests.

  • A form or endpoint that changes data accepting only the cookie, with no origin check.
  • A session cookie with no SameSite (rides on cross-site requests).
  • A sensitive action (change email, password, plan) via GET or plain POST with no token.
  • An API that trusts the cookie and checks neither Origin/Referer nor an anti-CSRF token.

How to prevent it

The modern defense is cheap and layered. A session cookie with SameSite (Lax or Strict) already cuts most classic CSRF; a per-request anti-CSRF token on state-changing actions closes the rest; and checking Origin/Referer on the server is the safety net.

  • Session cookie with SameSite=Lax (or Strict), Secure and HttpOnly.
  • Anti-CSRF token on every state-changing action (your framework’s standard).
  • Check Origin/Referer on the server for sensitive requests.
  • Never change state via GET; use POST/PUT/DELETE with protection.

Where RET fits

The Promptbook has the playbook to check SameSite, the anti-CSRF token and origin verification on the state-changing flows. When the flow is critical (email change, billing, admin), Risk Review confirms whether the origin boundary holds before it becomes action hijacking.

Want to know whether this happens in your system?

Manual pentest for web applications, APIs and apps, from R$9,500, with the Sprint run within 7 business days. We refund 50% if we find no flaw.

See price and timeline for my case

Frequently asked questions

Does SameSite alone solve CSRF?

SameSite=Lax/Strict cuts most classic CSRF and is the cheapest defense to turn on. But for very sensitive actions, combine it with an anti-CSRF token and a server-side Origin check: layered defense is the secure standard.

Are CSRF and XSS the same?

No. XSS injects a script into your page (runs code in the victim’s browser). CSRF injects nothing; it makes the victim’s browser fire a legitimate request using their session. Different defenses.

Does an API with a header token need CSRF protection?

If authentication is by a header token (not an automatic cookie), classic CSRF does not apply, because the browser does not attach the token by itself. CSRF lives where the session rides on an automatic cookie.

How do I test it?

Build a test page that fires your app’s sensitive action and open it logged in on another tab. If the action happens with no token/origin check, it is CSRF. The Promptbook guides that check.

Keep reading