← Learn

Definition

What is CSRF (Cross-Site Request Forgery)?

We scanned nearly 2,000 AI-built apps and 1 in 8 shipped a high-severity flaw. Want to check yours?Scan free →

Cross-Site Request Forgery (CSRF) is an attack where another website causes a logged-in user's browser to send a request to your app. Because the browser automatically attaches the session cookie, the forged request runs with the user's privileges. It works without stealing any credentials, using only a page the victim visits while signed in.

How the attack works

The user is logged into your app, which uses a cookie session. They visit a malicious page that contains a hidden form or request pointed at your app. The browser sends it along with the cookie, and your server, seeing a valid session, performs the action, for example changing an email or making a transfer.

How to prevent it

Two layers. Set sameSite on the session cookie so the browser will not send it on cross-site requests, and require an unguessable CSRF token on every state-changing request that the attacker's page cannot know. APIs authenticated with a bearer token in a header rather than a cookie are not vulnerable in the same way.

What this means for AI-generated code

CSRF is invisible in the path an AI tool builds: the form works and the update succeeds, so nothing signals the missing defense. Assistants ship cookie-based sessions without the token check because it is not needed for the feature to function.

Want to know if your app has this issue? Scan a public repo free, no account needed.

Scan a repo →

Related: fix missing CSRF protection

What Is CSRF (Cross-Site Request Forgery)? Plain Explanation: Prbl