SecureStartKit
SecurityFeaturesPricingDocsBlogChangelog
Sign inBuy Now
Home/Glossary/CSRF
Vulnerability Patterns

CSRF(Cross-Site Request Forgery)

Also known as: Cross-Site Request Forgery, XSRF, session riding

Definition

CSRF (Cross-Site Request Forgery) is an attack where a malicious site causes the victim's browser to send a request to a target site using the victim's existing session cookies. In Next.js App Router, Server Actions defend against CSRF by checking the Origin header against the Host on every POST.

What is CSRF?

The user is logged into yourapp.com with a session cookie. They visit attacker.com, which contains JavaScript that submits a form to yourapp.com/api/delete-account. The browser attaches the session cookie to the request automatically. Without defense, the request succeeds and the account is deleted.

How does Next.js defend against CSRF?

Server Actions in Next.js 14+ enforce an Origin-vs-Host check on every POST request. If the Origin header is missing or differs from the request's host, the action rejects with a 403. Combined with SameSite=Lax cookies (the modern default), CSRF against Server Actions is structurally blocked.

What about Route Handlers?

Route Handlers do not get the Origin check automatically. If you implement a custom POST endpoint, add the check yourself or use a token-based CSRF defense. The CVE-2026-27978 advisory describes a null-Origin bypass that affected older middleware configurations; the fix is to reject empty Origin headers explicitly.

Learn more

  • CSRF, XSS, SQL Injection Prevention in Next.js

Related terms

  • XSSXSS (Cross-Site Scripting) is a vulnerability where attacker-controlled content reaches a page and executes as JavaScript in the victim's browser. React mitigates XSS by default through JSX escaping, but the raw-HTML escape-hatch prop, raw HTML in MDX, and trusted-data assumptions still create injection paths.
  • CORSCORS (Cross-Origin Resource Sharing) is the browser mechanism that controls which origins can call which API endpoints. The server declares allowed origins via Access-Control-Allow-Origin headers, and the browser blocks cross-origin requests that fail the check.
  • Server ActionsServer Actions are Next.js functions marked with the 'use server' directive that run on the server and can be called from client components. Every Server Action is a public HTTP endpoint and must validate inputs with Zod, authorize identity from the session, and never trust user IDs from the request payload.
← Back to full glossary
SecureStartKit

The security-first Next.js SaaS template. Auth, payments, and everything you need to launch - with backend-only data access, Zod validation on every input, and built-in optimization for AI coding agents.

Summarize with AI

Product

  • Security
  • Features
  • Pricing
  • FAQ
  • Docs
  • About

Use Cases

  • For Indie Hackers
  • For Solo Developers
  • Fintech SaaS
  • Internal Tools
  • Healthtech SaaS

Free Tools

  • All Tools
  • RLS Policy Generator
  • Security Checklist
  • Security Headers
  • JWT Decoder
  • JWT Generator
  • CORS Config Generator
  • JSON to Zod Converter
  • API Key Generator
  • Stripe Webhook Verifier
  • Stripe Fee Calculator
  • SaaS Pricing Calculator
  • Tech Stack Costs
  • OG Image Preview

Compare

  • All comparisons
  • vs ShipFast
  • vs Makerkit
  • vs Supastarter
  • vs Divjoy
  • vs Nextbase
  • One-time vs subscription

Resources

  • Blog
  • Glossary
  • Security Patterns
  • Changelog
  • Contact
  • Privacy
  • Terms

More from the same maker

  • AppScreenshotStudio
  • QueryScope
  • FrictionScope
  • MCP Hunter
  • BookIllustrationAI
  • MyCVCraft
  • StyleMyFade

© 2026 SecureStartKit. All rights reserved.

Built with SecureStartKit