← All advisories
Advisory VV-008medium2025-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

The weekly email

One email a week. Only what changed.

New advisories, CVEs and fixes for Lovable, Bolt, v0, Replit, Base44 and Cursor apps. No roundups of things you already read.