Skip to content

fix: replace mock JWT with cryptographically signed tokens#852

Open
Sughter99 wants to merge 2 commits into
rinafcode:mainfrom
Sughter99:fix/proper-jwt-signing
Open

fix: replace mock JWT with cryptographically signed tokens#852
Sughter99 wants to merge 2 commits into
rinafcode:mainfrom
Sughter99:fix/proper-jwt-signing

Conversation

@Sughter99

Copy link
Copy Markdown

Closes #704

Summary

Fixes a critical auth vulnerability where session tokens were plain
timestamp strings that could be trivially forged by any client.

Problem

mock-jwt-token-${Date.now()} tokens could be crafted by anyone
knowing the timestamp, and middleware only checked for the string
prefix — providing zero security.

Changes

  • src/lib/auth/jwt.ts (new) — signToken() and verifyToken()
    helpers using jose with HS256 cryptographic signing
  • src/app/api/auth/login/route.ts — replaced mock tokens with
    properly signed JWTs carrying userId, role, and 7-day expiry
  • src/lib/authMiddleware.ts — now verifies JWT signature on every
    request, returns HTTP 401 for invalid, tampered, or expired tokens
  • .env.example — documents required JWT_SECRET environment variable

Acceptance Criteria

  • verifyToken() throws if signature is invalid or token is expired
  • Forged or tampered tokens return HTTP 401
  • JWT_SECRET is documented in .env.example

Security Note

Ensure JWT_SECRET is set to a strong random value in production.
Generate one with: openssl rand -base64 32

- Add signToken/verifyToken helpers in src/lib/auth/jwt.ts

- Replace mock-jwt-token- prefix with signed HS256 JWT in login route

- Update authMiddleware to verify JWT signature instead of string prefix

- Document JWT_SECRET in .env.example
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Sughter99 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Kindly fix workflow

@Sughter99

Copy link
Copy Markdown
Author

@RUKAYAT-CODER
I've made adjustments kindly review pr

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

kindly resolve conflict

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.

[Bug] Mock JWT token is a plain timestamp string with no cryptographic signature

3 participants