Next.js Proxy Session Cookie Checks Are Not Enough to Protect Data Routes
A developer building a Next.js 16 app with Better Auth, Drizzle and Postgres found that a dashboard guarded only by a session cookie check in proxy.ts could be bypassed. Setting a fake session cookie let the page display every user's name and email, since the proxy only verifies that a cookie exists and never validates it against the database. The fix was to add a server-side session check, such as auth.api.getSession() wrapped in a cached requireUser() helper, directly in the page before querying data. The article recommends keeping the proxy as a fast optimistic filter while placing real authorization next to the data, in line with current Next.js guidance.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in