← Lab /Security & privacy

Adversaries can forge Next.js auth cookies using only NEXTAUTH_SECRET

Possessing the NEXTAUTH_SECRET is sufficient to mint valid authentication cookies for any user in Next.js applications that use next-auth.

Security & privacy Embrace The Red 15 Jan 2026 Attack Prototype evidence

Published as “Minting Next.js Authentication Cookies”

Why it matters

If the NEXTAUTH_SECRET is not rotated, an attacker who obtains it can maintain unlimited access to the application.

Summary

The author shows that the secret stored in NEXTAUTH_SECRET (or AUTH_SECRET) is the sole secret required to derive encryption keys for next-auth session cookies. By calling next-auth library functions, they built a cookie encoder/decoder that can create and decode JWT cookies for any user. A demonstration video confirms that an attacker who obtains the secret can impersonate any user and retain persistent access. The evidence consists of a proof-of-concept tool and a walkthrough, but no large-scale testing.

What they found 2

  1. The NEXTAUTH_SECRET is sufficient to mint authentication cookies.

    “The NEXTAUTH_SECRET is all you need”

  2. Only the secret and the cookie name (used as salt) are required to derive encryption keys.

    “The only input needed should be the NEXTAUTH_SECRET , and then cycle through a couple of default salt values that next-auth uses”

Caveats 1

  • If you see multiple cookies with numbers at the end, concatenate their values in order (token0 + token1) and pass that single long string to this decoder utility (that should work).

What’s new here 4

  • Identifies that the NEXTAUTH_SECRET alone enables cookie forgery in next-auth applications.
  • Provides a publicly released cookie encoder/decoder tool built with AI assistance.
  • Shows a full exploitation chain from React2Shell code execution to persistent user impersonation.
  • Offers detection recommendations such as logging JWT IDs and monitoring impossible travel.