Home / patterns

Auth checked only in Next.js middleware (proxy)

Quick answer: Many AI-built Next.js apps protect pages with one middleware.ts (now proxy.ts) redirect and never check the session again in API routes, server actions or data fetching. If that single gate is skipped or misconfigured, as it was in the 2025 CVE-2025-29927 bypass, every protected route and its data is exposed.

Last updated October 20, 2026

Steps

  1. Check your Next.js version (npm ls next). CVE-2025-29927 is fixed in 12.3.5, 13.5.9, 14.2.25 and 15.2.3. If you're on an older release in those lines, upgrade.
  2. Open middleware.ts or proxy.ts and list the routes it protects. Read the matcher closely: a common pattern excludes /api, so your API routes may never pass through it at all.
  3. For every protected page, route handler and server action, confirm it checks the session itself (for example a verifySession() helper in a data access layer) and that the user is allowed to touch that record.
  4. Test it while logged out: call each API route and server action directly (curl, or your browser's network tab) and make sure you get 401 or 403, not data.
  5. Self-hosting outside Vercel and can't upgrade yet? The advisory's workaround is to block outside requests that carry the x-middleware-subrequest header before they reach the app.
  6. Keep middleware or proxy for fast redirects only. Treat it as a convenience, not your security boundary.

Why it matters

The Next.js authentication guide says Proxy "should not be your only line of defense" and that most security checks should run as close to your data source as possible. It recommends a data access layer and says to treat server actions and route handlers like public API endpoints. Next.js also notes that the middleware file convention is deprecated and has been renamed to proxy.

GitHub advisory GHSA-f82v-jwr5-mffw (CVE-2025-29927, rated critical, CVSS 9.1) showed it was possible to bypass authorization in a Next.js app when the check happens in middleware. The advisory says deployments hosted on Vercel were automatically protected; self-hosted apps needed the patch.

Sources

GitHub Security Advisory GHSA-f82v-jwr5-mffw: Authorization Bypass in Next.js Middleware — https://github.com/vercel/next.js/security/advisories/GHSA-f82v-jwr5-mffw

NVD: CVE-2025-29927 — https://nvd.nist.gov/vuln/detail/CVE-2025-29927

Next.js Docs: Authentication guide — https://nextjs.org/docs/app/guides/authentication

Next.js Docs: proxy.js file convention — https://nextjs.org/docs/app/api-reference/file-conventions/proxy

Related patterns

Found a problem you'd rather not fix yourself?

Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.

Get it fixed by StorenTech

Vibe Security Weekly

One email a week with new failure patterns and how to fix them.

By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.