Why It Matters for AI-Coded Apps
Most AI-generated backends skip CSRF protection entirely. State-changing API endpoints (POST, PUT, DELETE) are created without CSRF tokens, especially in SPA architectures where developers assume the API is only accessed by their frontend. 52% of vibe-coded apps in our research had no CSRF protection on critical endpoints.
Real-World Example
A banking app has an endpoint POST /transfer?to=account&amount=1000. An attacker creates a page with <img src='https://bank.com/transfer?to=attacker&amount=1000'>. When a logged-in bank user visits the attacker’s page, their browser sends the request with valid session cookies, transferring money without the user’s knowledge.
How to Detect and Prevent It
Implement CSRF tokens for all state-changing requests. Use the SameSite cookie attribute (set to Lax or Strict). Verify the Origin and Referer headers on the server. For SPAs using JWT in headers (not cookies), CSRF is less of a concern since tokens aren’t sent automatically.
Frequently Asked Questions
Do SPAs need CSRF protection?
What is the SameSite cookie attribute?
Strict never sends cookies cross-site, Lax sends them for top-level navigations (GET only), and None always sends them (requires Secure flag). Lax is the recommended default.