Auth checked only in Next.js middleware (proxy)
Last updated October 20, 2026
Steps
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
- API routes with no auth check
- RLS or auth present, but no ownership check (IDOR)
- Mass assignment: users can set fields like role or is_admin
- Server Actions with no auth check inside them
- JWTs decoded but never verified
- Sessions that stay valid after logout, password change or timeout
- IDOR in vibe-coded apps: changing an ID in the URL to see someone else's data
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 StorenTechVibe 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.