Cookie dan sesi for Next.js

high5 checks

Session cookies are the keys to an account. Missing attributes turn a single XSS bug into full account takeover.

What Next.js must have

  • Secure attribute on every cookie
  • HttpOnly on session cookies
  • SameSite=Lax or Strict on session cookies
  • No session identifier in URLs or localStorage
  • Session rotation after login and logout invalidation

How to fix it

  1. 1Set cookie attributes at the framework level so every cookie inherits them
  2. 2Move tokens out of localStorage to HttpOnly cookies

Next.js context

React framework with server-side rendering, routing and API routes, usually deployed on Vercel or Node.

Server components and middleware carry the auth boundary. Middleware-only auth was bypassable via CVE-2025-29927 — enforce authorisation in the route itself.