Next.js Security Checklist: 25 Essential Steps
Next.js blurs the line between client and server in ways that create new security surfaces. Server Components can accidentally expose secrets, API routes can forget auth checks, and middleware can be bypassed with crafted requests. This checklist covers the security concerns specific to Next.js so you can ship without leaving doors open.
Security Headers & Transport
Configure HTTP headers that protect against common web attacks at the transport level.
Authentication & Authorization
Implement authentication that can't be bypassed through Next.js-specific attack vectors.
Server Components & Data Safety
Prevent sensitive data from leaking across the server-client boundary in Next.js App Router.
API Routes & Server Actions
Harden your Next.js API surface against injection, forgery, and abuse.
Dependencies & Deployment
Secure your supply chain and production environment configuration.
Pro Tips
- -Use Next.js middleware's `matcher` config to protect entire route groups instead of checking auth in each page. Pattern like `matcher: ['/dashboard/:path*', '/api/admin/:path*']` covers all nested routes automatically.
- -Test your security headers at securityheaders.com — it grades your site and tells you exactly which headers are missing. Aim for an A+ rating before launch.
- -Install the `server-only` and `client-only` packages on day one. They cost nothing at runtime and prevent the most dangerous class of Next.js bugs: accidentally importing server code into the client bundle.
- -When debugging Server Action security, remember they're just POST endpoints. Use curl to call them directly without your UI to verify that auth and validation work independently of the frontend.