Abbi Labs

Guides

Does Next.js middleware protect your API routes? The matcher that skips /api, proxy.ts and CVE-2025-29927

By Abbi Labs · Last updated 4 December 2026

Scan your app free and see what your live site exposes.

Abbi Labs checks common admin URLs reachable without signing in, secret keys in your JavaScript, Supabase tables readable with your public key, served /.env or /.git, source maps, security headers, CORS, cookie flags and TLS. Read-only. No sign-up for the quick check.

No app handy?

Example result · our deliberately broken demo app

6 issues found: 3 critical, 1 high, 1 medium, 1 low

  • Critical: Stripe live secret key in public JavaScript
  • Critical: /.env file readable by anyone
  • High: Git repository exposed (/.git/HEAD)

The demo's problems are planted on purpose. Paste your own URL above to see yours.

No sign-up. Read-only public-resource and protocol metadata checks. No model prompts or tool execution. Scan only sites you own or are allowed to test.

Run on every deploy or use from Cursor / Claude Code via MCP →

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.

You asked your AI tool to "protect the dashboard", and it wrote a middleware.ts that sends signed-out visitors to /login. You tried it in a private window, got redirected, and moved on. The pages are covered. Whether your /api routes and Server Actions are covered is a different question, and often the answer is no.

Sources for the facts below: Next.js docs on Proxy (formerly middleware) and its matcher, the authentication guide, the data security guide, and the CVE-2025-29927 advisory.

Why middleware often doesn't cover /api

What can go wrong

Check yours in 3 minutes

  1. Find the file. middleware.ts or proxy.ts in the project root or src/. Read export const config = { matcher }. If it contains (?!api, or lists only page paths, your API routes are not covered.
  2. List your routes. find app src/app pages -name 'route.ts' -o -name 'route.js' 2>/dev/null for App Router handlers, and pages/api for older ones. Then grep -rln "use server" app src for Server Actions.
  3. Look for a check inside each one. Every handler and action that reads or changes user data should start by getting the user (for example auth(), getServerSession() or supabase.auth.getUser()) and returning 401 or 403 if there isn't one or it's the wrong user.
  4. Test signed out, on your own app. curl -i https://your-app.com/api/your-route with no cookie, or open it in a private window. A 401 or 403 is good. Real data, or a 200 with JSON that should be private, means it's open. Try one POST route the same way with a harmless body if it only changes your own test data.
  5. Check your Next.js version. npm ls next. If you self-host on a version older than the fixed releases above, update.

The fix: check the user where the data is

Keep middleware for redirects and quick checks. Put the real check in each route handler and Server Action, ideally through one helper (Next.js calls this a Data Access Layer) so nobody forgets it:

// lib/auth.ts
import "server-only";
import { auth } from "@/auth"; // or your auth library / Supabase server client

export async function requireUser() {
  const session = await auth();
  if (!session?.user) throw new Response("Unauthorized", { status: 401 });
  return session.user;
}

// app/api/projects/route.ts
import { requireUser } from "@/lib/auth";

export async function GET() {
  try {
    const user = await requireUser();
    const projects = await db.project.findMany({ where: { ownerId: user.id } });
    return Response.json(projects);
  } catch (res) {
    if (res instanceof Response) return res;
    throw res;
  }
}

// app/actions.ts
"use server";
import { requireUser } from "@/lib/auth";

export async function deleteProject(id: string) {
  const user = await requireUser();
  await db.project.deleteMany({ where: { id, ownerId: user.id } });
}

Paste this into your AI builder

Audit auth in this Next.js app. Don't change behaviour for signed-in users.
1. Show me config.matcher in middleware.ts / proxy.ts and list
   which routes it does NOT run on (especially /api).
2. List every route handler (route.ts, pages/api) and every
   "use server" function. For each, say whether it verifies the
   session itself before reading or changing data.
3. Add a server-only requireUser() helper and call it at the top
   of every handler and Server Action that touches user data.
   Return 401 when signed out, 403 for the wrong user.
4. Make queries filter by the signed-in user's id, not an id
   from the request alone.
5. Leave middleware for redirects only. Tell me the Next.js
   version and whether it is older than 15.2.3 / 14.2.25.

What Abbi Labs checks

Honest scope: Abbi Labs scans your live site from outside, signed out, so it can't read your middleware or prove every API route checks the user. Use the curl test above for that. What the free quick check (no sign-up) does here: it sends an anonymous GET to a short list of common admin paths (like /admin, /api/admin and /api/users) and flags responses that look like an admin panel or user list instead of a login redirect, and it sends OPTIONS preflights (never GET or POST) to /api routes found in your JavaScript to check CORS. It also flags secret keys in your home page JavaScript and Supabase tables readable with your public key, which is often what an open route would have exposed anyway.

Scan your app free

FAQ

Does Next.js middleware run on API routes?

Only if its matcher includes them. With no matcher it runs on every request. But many projects copy a matcher like '/((?!api|_next/static|_next/image|.*\.png$).*)', which is the example in Next.js's authentication guide, and the (?!api ...) part means it never runs on anything under /api. Read config.matcher in your middleware.ts or proxy.ts to see which one you have.

Is middleware enough for authentication in Next.js?

No. Next.js's authentication guide says Proxy (the new name for middleware) can be useful for initial checks but should not be your only line of defense, and that most security checks should happen as close to your data as possible. It also says to treat Route Handlers and Server Actions like public-facing API endpoints and verify the user inside them.

What is proxy.ts? Is it different from middleware.ts?

Same feature, new name. In Next.js 16 the middleware file convention is deprecated and renamed to proxy (proxy.ts, exporting a proxy function), and Next.js provides a codemod to rename it. The matcher works the same way, so the same gap applies.

What was CVE-2025-29927?

A critical Next.js bug published in March 2025 where a request carrying the internal x-middleware-subrequest header could skip middleware, so auth checks done only in middleware could be bypassed. It's fixed in 12.3.5, 13.5.9, 14.2.25 and 15.2.3. The advisory says apps hosted on Vercel were automatically protected; self-hosted apps on older versions were exposed. Keep Next.js updated either way.

My page redirects to /login when I'm signed out. Doesn't that protect its Server Actions?

No. Next.js's data security guide says a page-level auth check doesn't extend to the Server Actions defined in it, and that actions are reachable by a direct POST request. Check the session inside each action.

Does this apply to Supabase apps?

Yes, if your Next.js API routes or Server Actions use a Supabase client with the service_role or secret key, because that bypasses RLS. If they only use the signed-in user's session with RLS on your tables, the database still blocks rows the user can't see. Supabase's Next.js middleware example mainly keeps the session cookie fresh (and can redirect signed-out visitors), so still check the user inside each route.

Can Abbi Labs tell me if my API routes are open?

Partly. The free quick check (no sign-up) sends an anonymous GET to a short list of common admin paths, such as /admin, /api/admin and /api/users, and flags responses that look like an admin panel or user list rather than a login redirect. It sends only OPTIONS preflights (for CORS) to other /api routes it finds in your JavaScript, so it can't tell whether those check the user. The curl test below can.

Related guides

Weekly AI-app security checklist

One short email a week: a practical check for apps built with Supabase, Next.js and AI tools (RLS, leaked keys, headers and more). Unsubscribe anytime.