fix: replace mock JWT with cryptographically signed tokens#852
Open
Sughter99 wants to merge 2 commits into
Open
fix: replace mock JWT with cryptographically signed tokens#852Sughter99 wants to merge 2 commits into
Sughter99 wants to merge 2 commits into
Conversation
- 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
|
@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! 🚀 |
Contributor
|
Kindly fix workflow |
Author
|
@RUKAYAT-CODER |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 anyoneknowing the timestamp, and middleware only checked for the string
prefix — providing zero security.
Changes
src/lib/auth/jwt.ts(new) —signToken()andverifyToken()helpers using
josewith HS256 cryptographic signingsrc/app/api/auth/login/route.ts— replaced mock tokens withproperly signed JWTs carrying userId, role, and 7-day expiry
src/lib/authMiddleware.ts— now verifies JWT signature on everyrequest, returns HTTP 401 for invalid, tampered, or expired tokens
.env.example— documents requiredJWT_SECRETenvironment variableAcceptance Criteria
verifyToken()throws if signature is invalid or token is expiredJWT_SECRETis documented in.env.exampleSecurity Note
Ensure
JWT_SECRETis set to a strong random value in production.Generate one with:
openssl rand -base64 32