If your AI-built Next.js app protects pages with middleware only, one 2025 vulnerability shows why that is not enough. CVE-2025-29927 let an attacker skip Next.js middleware entirely by sending a crafted header. Anything that relied only on middleware to check a login was open.

What happened

The advisory (rated critical) says it was possible to bypass authorization checks in a Next.js app if the check happened in middleware. Patched versions are 12.3.5, 13.5.9, 14.2.25 and 15.2.3. Sources are listed at the end.

Why AI-built apps are exposed to this pattern

Generated Next.js code often puts "redirect to /login if no session" in middleware.ts and then trusts it. The page, the route handler and the database query run with no second check. When middleware is skipped, misconfigured or does not match a path, nothing else stands in the way.

The 6 checks

  1. Upgrade Next.js to a patched version for your major line. Check npm ls next.
  2. Check authentication again inside every route handler and server action, not only in middleware. Read the session there and return 401 if it is missing.
  3. Check it again at the data layer. Use row level security or an ownership filter, so a missing session cannot return rows.
  4. Review your middleware matcher. Paths it does not match, such as /api or static-looking routes, get no protection at all.
  5. Do not use middleware as the only gate for admin pages. Check the user's role on the server where the data is loaded.
  6. Test it. Request a protected route with no cookie, and with a made-up one, and confirm you get a 401 or a redirect and no data.
// app/api/orders/route.ts export async function GET() { const session = await getSession(); if (!session) return new Response("Unauthorized", { status: 401 }); // query only this user's rows } 

Self-hosted versus hosted

The advisory notes that apps hosted on Vercel and Netlify were not affected, and self-hosted apps using next start with output: standalone were. Do not take comfort in that. The fix for a single point of failure is a second check, not a host.

What an outside scan can and cannot tell you

ProofForge checks your live site from the outside, the way a stranger would. It can see open API endpoints that answer without a login, exposed files and secret-shaped strings in shipped code. It cannot read your middleware or confirm your server-side checks are right, and it will say inconclusive when it cannot know.

Sources

Check your own app from the outside, free. Run the free ProofForge scan on your live URL. No account needed for the first scan. It looks at your public site the way a stranger would and says pass, fail or inconclusive, so you know what is confirmed and what it could not see. One-time reports start at $9: see pricing. Building with an AI agent? There is an MCP server so it can check before it deploys.