Find Next.js API routes anyone can call

Updated November 17, 2026

In Next.js, app/api/invoices/route.ts is reachable at /api/invoices by anyone on the internet, whether or not your UI links to it. Server actions are public endpoints too. Hiding the button protects nothing.

What a missing check looks like

// app/api/invoices/route.ts
export async function GET(req: Request) {
  const userId = new URL(req.url).searchParams.get("userId");
  const invoices = await db.invoice.findMany({ where: { userId } });
  return Response.json(invoices);
}

Two problems: no check that anyone is signed in, and it trusts userId from the URL, so any user can read any other user's invoices by changing a number.

The fix

export async function GET() {
  const session = await auth();
  if (!session) return new Response("Unauthorized", { status: 401 });
  const invoices = await db.invoice.findMany({ where: { userId: session.user.id } });
  return Response.json(invoices);
}

Take the user from the session, never from the request.

Middleware isn't enough on its own

A matcher in middleware.ts that protects /dashboard/:path* doesn't protect /api/... unless the matcher includes it, and a typo in a matcher silently exposes routes. Check auth inside each handler as well.

Server actions

A function with "use server" can be called directly with a POST request. Check the session at the top of every action that reads or writes user data.

Admin routes

Check the role on the server, inside the handler: if (session.user.role !== "admin") return 403.

Catch new ones as they're written

Periderm flags admin routes without a role check, data fetches that trust a user id from the request, and routes with no rate limit:

npm i -g periderm-cli
periderm scan

With the GitHub Action, these are flagged on the pull request that adds them.

more guides