Middleware is not an authorisation layer
CVE-2025-29927 (CVSS 9.1, March 2025) let a client skip Next.js middleware entirely by sending the internal x-middleware-subrequest header. Apps that put their only auth check in middleware.ts served protected pages to anyone. It was patched in 14.2.25 and 15.2.3, with backports to 13.5.9 and 12.3.5, but the lesson outlives the patch: every route handler, server action and server component that reads private data should check the session itself.
Server actions and React Server Components
- Server actions are public POST endpoints. Anyone who finds the action ID can call it with arbitrary arguments, so each action needs its own authorisation and input validation.
- CVE-2024-34351: on self-hosted Next.js 13.4 to before 14.1.1, a server action redirecting to a relative path built the URL from the attacker-controlled Host header, giving SSRF.
- CVE-2025-55182 (React2Shell, December 2025, CVSS 10.0): pre-authentication remote code execution in how React Server Components decode payloads sent to Server Function endpoints. It affected Next.js apps using the App Router; the Next.js tracking ID CVE-2025-66478 was later merged into it.
Route handlers, image optimisation and data leaks
- Route handlers in app/api often return whole database rows. Look for excessive data exposure and for IDs you can swap (BOLA).
- An over-broad images.remotePatterns entry (wildcard hosts) lets /_next/image fetch from hosts you did not intend; test whether internal or metadata addresses are reachable through it.
- NEXT_PUBLIC_ variables are compiled into client JavaScript. Secrets that end up there are public, whatever the variable is called.
- Self-hosted deployments behind a CDN can be exposed to cache poisoning if responses vary on headers the cache does not key on.
Testing a Next.js app with Pentest-Swarm
Pentest-Swarm is a black-box tester: it sends HTTP requests to a deployed Next.js app and works from the responses. Point it at a preview or staging deployment you are authorised to test, not at your source tree.
- Run the owasp-top10 playbook against the staging URL, with scope set to that host only; scope is enforced in code and fails closed.
- Use
--browserfor headless-browser recon so the swarm renders client components and harvests the API and server-action calls the frontend makes. - Pass a test user's session with
--cookieor--headerso it can reach auth-gated routes and try cross-user access (BOLA/BFLA). - Add
--verifyso SSRF and injection findings are confirmed by non-LLM oracles such as an out-of-band callback, not by model judgement. - Use the ci-cd-security playbook with SARIF output to gate preview deployments in your pipeline.
Where it falls short
A black-box test cannot see your source, so it will not tell you which server action is missing a check until it finds and calls it, and it cannot flag a vulnerable dependency that is never reachable over HTTP. Pair it with dependency auditing (npm audit or similar) for advisories like the ones above, and with SAST or code review for authorisation logic. The free edition of Pentest-Swarm also deliberately limits its most powerful exploitation capabilities.
Questions
Is upgrading Next.js enough to fix CVE-2025-29927?
Upgrading closes the header bypass, but if middleware was your only authorisation check you still have a single point of failure. Add session checks in route handlers, server actions and data-access code, then retest.
Can a black-box test find vulnerable server actions?
Yes, if the action is reachable from the UI or its ID can be observed. Rendering the app in a headless browser helps, because server action calls appear in the network traffic the frontend generates.
Should I test on Vercel or self-hosted?
Test the deployment you actually run. Several Next.js advisories only affected self-hosted setups because hosting platforms route on the Host header or add their own firewall rules.