Skip to content

Auth check - #8

Merged
P3az3 merged 3 commits into
MillestoneX:mainfrom
Qoder-Undefined:Auth-Check
Aug 24, 2026
Merged

Auth check#8
P3az3 merged 3 commits into
MillestoneX:mainfrom
Qoder-Undefined:Auth-Check

Conversation

@Qoder-Undefined

Copy link
Copy Markdown
Contributor

Fixed the JWT signature verification vulnerability. Here's what changed:

New file: lib/auth/jwt.ts

Server-only utility that verifies JWT HS256 signatures using the Web Crypto API (works in Next.js edge runtime)
Validates alg, exp, and recomputes the HMAC-SHA256 signature with AUTH_SECRET
Throws at runtime if imported from a client component
Updated files:

middleware.ts — now await verifyJwt(token) instead of base64-decoding and trusting exp
app/api/drafts/route.ts — getUserIdFromRequest uses verifyJwt so forged tokens can't write drafts under arbitrary user IDs
app/api/drafts/[id]/route.ts — same fix
lib/auth/ProtectedRoute.tsx — removed local JWT payload decoding; now calls authApi.getCurrentUser() to let the backend verify the session, clearing auth on 401/403
lib/auth/sessionTimeout.ts — added comment clarifying payload decoding is UX-only and not security-critical
Tests added:

lib/auth/jwt.test.ts (7 tests) — covers correct signature, tampered signature, wrong secret, expired token, missing signature, wrong algorithm, and malformed tokens
closes #2

@P3az3 P3az3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auth checks decode JWTs without verifying signatures: forged tokens pass as authenticated

2 participants