Short answer
Cross-site request forgery (CSRF) is an attack where another website makes the user’s browser send a request to your app, and your app accepts it because the browser attached the user’s cookies. It only works when cookies alone prove who the user is. A typical Lovable or Vite app that sends the Supabase token in a header is not exposed in the classic way; server-rendered apps and APIs with cookie sessions need CSRF defenses.
Ask an AI about this page:ChatGPTClaude
On this page
Cross-site request forgery (CSRF) is an attack where a page on another website makes the user’s browser send a request to your app, and your app carries out a state-changing action because the request arrived with the user’s credentials. The user never meant to send it. MITRE files it as CWE-352 (opens in a new tab).
MDN lists the conditions: the app changes state through HTTP requests, it uses only cookies to recognise the signed-in user, and the request has no value an attacker cannot predict. Browsers attach cookies to requests automatically, even when another site triggers them. That is the whole trick.
CSRF in an AI-built app
A standard Lovable or Bolt app is a React single-page app that talks to Supabase with supabase-js. The client keeps the session in browser storage (with persistSession on, it saves the session into local storage) and sends the user’s token itself with every request. A foreign site cannot make the browser add that token, so the classic CSRF attack has nothing to ride on.
The picture changes when cookies carry the session:
- a server-rendered app or API route that reads the Supabase session from a cookie,
- your own backend with a session cookie, for example an Express or Next.js API,
- an endpoint that accepts state changes through
GET, such as/api/unsubscribe?user=…, combined with a cookie session.
A related trap is a loose CORS setup. MDN points out that a site is exposed if its state-changing responses allow the attacker’s origin together with credentials.
How to check your app
- Find out how your server recognises users: a header with a bearer token, or a cookie? Search for
cookies,Set-Cookieand your session library. - For every cookie-authenticated endpoint that changes data, check for a CSRF token, a custom header the server requires, or a check of the
Sec-Fetch-SiteorOriginheader. - Make sure no
GETrequest changes anything. - Check the
SameSiteattribute of your session cookie in the browser’s developer tools.
How to fix or prevent it
If you use cookie sessions, follow the OWASP cheat sheet: use your framework’s CSRF tokens, or require a custom request header on API calls (cross-site requests with custom headers need a CORS preflight, which your server can refuse), and reject cross-site requests based on Fetch Metadata. Set session cookies to SameSite=Lax or Strict as an extra layer. Keep CORS strict, as explained in CORS explained for vibe coders, and fix any XSS first, because script running inside your app gets around every CSRF defense.
Frequently asked questions
Is my Supabase app vulnerable to CSRF?
It depends on how the session travels. If the app sends the access token itself in a request header, another site cannot make the browser attach it, so classic CSRF does not apply. If your server reads the session from cookies, for example in a server-rendered setup, you need CSRF defenses.
Do SameSite cookies solve CSRF?
They help, but OWASP calls SameSite a defense-in-depth control, not a replacement for a real CSRF defense. Lax cookies are still sent on top-level GET navigations, which is one reason state changes should never use GET.
What is the difference between CSRF and XSS?
With CSRF the attacker’s code runs on another site and can only send requests. With XSS it runs inside your app and can read responses too. OWASP notes that XSS can defeat all CSRF defenses, so fixing XSS comes first.
Sources
- 1.Cross-site request forgery (CSRF) — MDN Web Docs
- 2.Cross-Site Request Forgery Prevention Cheat Sheet — OWASP Cheat Sheet Series
- 3.CWE-352: Cross-Site Request Forgery — MITRE
- 4.Initializing the JavaScript client — Supabase Docs