← All advisories

VV-008mediumBroken access control2025-03

Protecting routes only in middleware

Vercel recommends against middleware being the sole method of protecting routes. Check auth again where data is read or changed.

01.

What it is

Vercel’s postmortem: "We do not recommend Middleware to be the sole method of protecting routes in your application." Middleware cookie checks are an optimistic early redirect, not the final authorization.

02.

How to check

  1. Find server actions, route handlers and data-fetching functions that read user data. Each should verify the session itself.
03.

How to fix

  1. Add a session/role check inside each server action and route handler (defense in depth).
'use server';
export async function deleteProject(id: string) {
  const user = await requireUser();            // don't trust middleware alone
  const project = await db.project.findUnique({ where: { id } });
  if (project?.ownerId !== user.id) throw new Error('Forbidden');
  await db.project.delete({ where: { id } });
}
04.

Sources

More advisories for this tool
The weekly email

One email a week. Only what changed.

Every new security hole in AI coding tools, MCP servers, app builders and the stacks they generate (Next.js, Supabase, Node, PHP), each with how to check your app and the fix. No roundups of things you already read.

Free, one email a week. Read the latest issue first if you like. One-click unsubscribe in every email. We never sell or share addresses.