CSRF in AI-built apps: can another website make your logged-in users do things? (a 5-minute test)
CSRF stands for cross-site request forgery. A visitor is logged in to your app. They open another website, and that site quietly makes their browser send a request to your app, such as "change email", "delete project" or
CSRF stands for cross-site request forgery. A visitor is logged in to your app. They open another website, and that site quietly makes their browser send a request to your app, such as "change email", "delete project" or "transfer credits". The browser attaches the visitor's cookie, so your app thinks the request is real. AI-built apps with cookie logins often have no protection against this.
1. Who is at risk
Only apps that log users in with cookies. If your app sends a token in an Authorization header that your own frontend code adds, a foreign site cannot make the browser add it, so classic CSRF does not apply. Check which one you use before you spend time on this.
2. Signs your app may be open
- State-changing routes accept
GETrequests (/api/delete?id=5) - Cookies have no
SameSitesetting, orSameSite=None - Forms and
POSTroutes have no CSRF token - The API accepts
application/x-www-form-urlencodedortext/plainbodies as well as JSON - CORS allows any origin and credentials together
3. A 5-minute test on your own app
- Log in to your app in one browser tab with a test account.
- Make a local HTML file with a form that posts to one of your own state-changing routes, with a harmless value, for example a profile name change.
- Open that file in the same browser, in a new tab, and submit the form.
- If the change happens in your app, the route has no CSRF protection.
Use your own app and a test account only.
4. Fixes that hold up
- Set session cookies with
SameSite=LaxorStrict,HttpOnlyandSecure. - Never change data on
GETrequests. - Add a CSRF token to forms and non-GET routes, or use your framework's built-in protection.
- Check the
Originheader on state-changing requests and reject unexpected origins. - Require a custom header such as
X-Requested-Withor a JSON content type on API routes. - Ask for the password again before sensitive actions like changing email or deleting an account.
What an outside scan can and cannot tell you
An outside scan can read your cookie flags and headers on public pages. It cannot log in, so it cannot prove a logged-in route is safe from CSRF. Run the test above on your most sensitive routes.
Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.