React framework

Next.js security checklist

The Next.js footguns AI tools ship: NEXT_PUBLIC_ secret leaks, the CVE-2025-29927 middleware auth bypass, and unguarded Server Actions. Scan your app free.

Next.js is the most popular React framework, powering App Router pages, Server Components, Server Actions, route handlers, and edge/Node middleware from one codebase. It blurs the client/server line on purpose — which is exactly what makes it fast to build with and easy to get wrong. Most AI-generated ‘full-stack’ apps you see today are Next.js under the hood.

Client-exposed env: NEXT_PUBLIC_

Why Next.js apps get shipped insecure

The same file can run on the server or ship to the browser, so a single misplaced variable or missing auth check turns into a real exposure. AI coding tools happily add NEXT_PUBLIC_ to make a value ‘just work’ in a client component, and they scaffold Server Actions and route handlers without the auth checks the docs insist you add yourself. The framework’s power surface — middleware, actions, handlers — is also its attack surface.

The Next.js-specific footguns

Scan your Next.js app — live routes + repo, free

Trust's framework-aware scan reaches your real routes and endpoints, then checks your code for leaked secrets and vulnerable deps. No signup, about a minute.

Run a free scan →

Next.js security checklist

  1. Grep every NEXT_PUBLIC_ var and confirm none are secrets — anything sensitive must drop the prefix and stay server-side; rotate any key that was ever public.
  2. Upgrade Next.js past the CVE-2025-29927 patch (15.2.3 / 14.2.25+) and strip the x-middleware-subrequest header at your proxy/edge as defense in depth.
  3. Re-check auth and authorization inside every ‘use server’ action and every app/api route handler — never rely on the page or middleware alone.
  4. Enforce object-level ownership on any handler that takes an id (params, query, or body) so users can’t read or mutate records they don’t own.
  5. Add the ‘server-only’ package to modules holding secrets/server logic so a client import fails the build instead of leaking silently.
  6. Run a free Trust scan — its Next.js route-extractor reaches your actual App Router pages, actions, and API handlers, plus a repo scan for leaked NEXT_PUBLIC_ keys and vulnerable deps.

Bottom line

Next.js gives you a server and a browser in one file, and AI tools blur that line to make things ‘work’. The wins are quick: keep secrets off NEXT_PUBLIC_, patch the middleware CVE, and put a real auth check inside every action and route handler. Trust’s Next.js-aware scan finds the leaks and unguarded routes before someone else does — free, no signup for the URL scan.

Deeper dive: the full Next.js security checklist →

Scan another framework

Keep your app safe