Skip to content

lib/jwt.ts falls back to a hardcoded secret and a live legacy session route trusts a bearer cookie — token forgery #351

Description

@3m1n3nc3

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.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignStellar WaveIssues in the Stellar wave programauthbugSomething isn't workingjwtsecurity

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions