Description
app/lib/jwt.ts signs and verifies tokens with a publicly known constant whenever NEXTAUTH_SECRET is unset:
const secret = new TextEncoder().encode(
process.env.NEXTAUTH_SECRET || "your-secret-key-change-in-production",
);
This is a parallel token system to the NextAuth session the UI actually uses. The deprecated-but-still-live GET /api/.../(auth)/session route verifies a token taken from the Authorization header or a token/auth-token cookie via this module and returns full user data. In any deployment missing NEXTAUTH_SECRET, an attacker can forge a token for any user and read their data through this route. (Note: lib/auth-config.ts was already fixed to use process.env.NEXTAUTH_SECRET with no fallback — lib/jwt.ts still has the footgun.)
More info
- File:
app/lib/jwt.ts (approx. lines 3-5)
- File:
app/app/(auth)/session/route.ts (cookie/bearer token path, approx. line 18)
- Remove the hardcoded fallback and fail fast at startup if
NEXTAUTH_SECRET is missing.
- Remove the legacy
session route and the token/auth-token cookie path, or reconcile it with the NextAuth session model.
- Add a CI check ensuring
NEXTAUTH_SECRET is present in production config.
Description
app/lib/jwt.tssigns and verifies tokens with a publicly known constant wheneverNEXTAUTH_SECRETis unset:This is a parallel token system to the NextAuth session the UI actually uses. The deprecated-but-still-live
GET /api/.../(auth)/sessionroute verifies a token taken from theAuthorizationheader or atoken/auth-tokencookie via this module and returns full user data. In any deployment missingNEXTAUTH_SECRET, an attacker can forge a token for any user and read their data through this route. (Note:lib/auth-config.tswas already fixed to useprocess.env.NEXTAUTH_SECRETwith no fallback —lib/jwt.tsstill has the footgun.)More info
app/lib/jwt.ts(approx. lines 3-5)app/app/(auth)/session/route.ts(cookie/bearer token path, approx. line 18)NEXTAUTH_SECRETis missing.sessionroute and thetoken/auth-tokencookie path, or reconcile it with the NextAuth session model.NEXTAUTH_SECRETis present in production config.