Pular para o conteúdo

// Security by tool

Security for Next.js apps

7 minUpdated July 25, 2026By Ler em português

Quick answer

The incident that defined 2025 for Next.js was CVE-2025-29927 (CVSS 9.1): the framework trusted the internal x-middleware-subrequest header, which existed only to prevent middleware loops. An attacker sending that header skipped the whole middleware, and with it every authentication and authorization gate living there. An unauthenticated request reached the protected route directly.

It affects Next.js below 15.2.3, 14.2.25 and 13.5.9. Apps on Vercel and Netlify were not hit (the platform strips the header), but anyone self-hosting, or putting auth logic only in middleware, needed to update and block the header at the edge. If your product uses middleware to protect routes, that is the first thing to check.

It got worse: in December 2025, React2Shell (CVE-2025-55182, CVSS 10.0, and the corresponding CVE-2025-66478 in Next.js) brought unauthenticated RCE in React Server Components via insecure deserialization. A default app created with create-next-app and built for production was exploitable with no code changes, with real in-the-wild exploitation (coin miners) from December 2025. Keeping React and Next.js updated stopped being optional.

What usually breaks in a Next.js app

CVE-2025-29927 was the wake-up call, but it exposed a broader pattern: concentrating authorization in middleware (a layer the framework can skip) instead of checking at the data boundary. In AI-built products, middleware becomes the only gate, and it is fragile.

Recurring holes in Next.js apps
HoleWhy it happensImpact
Auth only in middlewareSpoofed header (CVE-2025-29927) skips the layerAccess to a protected route with no login
RCE in React Server ComponentsInsecure deserialization (CVE-2025-55182/66478)Unauthenticated RCE; default create-next-app vulnerable
Secret in NEXT_PUBLIC_Public prefix ships the variable to the bundleSecret key visible to any visitor
Server Action with no checkIt is a public POST endpoint, treated as internalAction/data exposed without authorization
Route Handler with no ownershipFetches by received id without an owner checkIDOR: another customer’s data

How RET reviews a Next.js app

The review confirms authorization lives at the data boundary (in the Route Handler, the Server Action, the query), not just in middleware that can be skipped. It tests each Server Action as the public endpoint it is, looks for NEXT_PUBLIC_ secrets in the bundle, and checks ownership on routes that return data.

For the first pass, the Promptbook has prompts to audit middleware, Server Actions and NEXT_PUBLIC_ with AI. When access is critical, Risk Review reads the flows and says where authorization is in the wrong place.

  • Authorization at the data boundary, not just in middleware.
  • Every Server Action treated as a public POST (origin, rate limit, validation).
  • Hunt for NEXT_PUBLIC_ secrets and ownership in Route Handlers.

You may already be exposed if

Some signals call for an immediate review in a Next.js app.

  • Your route protection lives only in middleware and you run Next.js off Vercel/Netlify on an old version.
  • You have a NEXT_PUBLIC_ variable with a value that should be secret.
  • You use Server Actions and never checked origin, rate limit or authorization on them.
  • A route returns a resource by id without checking the logged-in user owns it.

Want to know whether this happens in your system?

Manual pentest for web applications, APIs and apps, from R$9,500, with the Sprint run within 7 business days. We refund 50% if we find no flaw.

See price and timeline for my case

Frequently asked questions

Does CVE-2025-29927 affect me on Vercel?

No. Vercel (and Netlify) strip the x-middleware-subrequest header at the edge, so apps hosted there were not hit. The risk is for self-hosting on a vulnerable version (below 15.2.3/14.2.25/13.5.9). Even so, do not rely on middleware alone for authorization.

Is updating Next.js enough?

Updating closes the specific CVE, but the lesson is architectural: do not concentrate authorization in a layer the framework can skip. Check access at the data boundary (Route Handler, Server Action, query). That way, even a middleware bypass does not hand over the data.

Is a Server Action safe because it is "server"?

Not automatically. A Server Action is a public POST endpoint: anyone can call it. It needs origin checks, rate limiting and authorization like any route. Treating it as "internal" is a common mistake.

Who runs the review at RET?

Gabriel Lima Ferreira, founder and lead pentester, with a verified domain, accepted terms and an authorized scope, returning reproducible evidence.

Keep reading