Feat/secure wallet endpoints#156
Open
davedumto wants to merge 7 commits intoHarmonia-Development:mainfrom
Open
Feat/secure wallet endpoints#156davedumto wants to merge 7 commits intoHarmonia-Development:mainfrom
davedumto wants to merge 7 commits intoHarmonia-Development:mainfrom
Conversation
Contributor
|
Hey @davedumto , please resolve the workflow errors |
Contributor
Author
|
Okay on it! |
Merge branch 'feat/secure-wallet-endpoints' of https://github.com/davedumto/harmonia-dappOD into feat/secure-wallet-endpoints
Contributor
Author
|
some other tests are failing and causing the last ci to fail, and the failing tests are not from my code |
Contributor
All merged pull requests pass the workflows. So if the changes you made are causing the workflow to fail, perhaps merging from main is where the workflow failed. |
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 #136
Summary
This PR implements JWT authentication middleware to secure all wallet-related API endpoints in the Stellar wallet service. The implementation ensures only users with valid JWTs can access sensitive wallet operations like account creation and management.
Changes Made
🔧 Core Implementation
JWT Middleware: Created comprehensive JWT authentication middleware in
src/auth/jwt.tsAuthorization: Bearer <token>header formatUser Authorization: Added
requireMatchingUserIdmiddleware to prevent cross-user accessuser_idmatches request bodyuser_id🛡️ Security Implementation
Route Protection: Applied JWT middleware to all
/wallet/*endpointssrc/index.tsfor consistent protectionError Handling: Implemented proper HTTP status codes and JSON error responses
401 Unauthorized- Missing or invalid JWT tokens403 Forbidden- Valid JWT but mismatched user_id500 Internal Server Error- Missing JWT secret configuration🧪 Testing
Comprehensive Test Suite: Created full test coverage with bun compatibility
tests/auth/jwt.test.ts) - 8 test casestests/routes/wallet.test.ts) - 6 test casesTest Scenarios:
📚 Documentation
JWT_INTEGRATION.mdwith practical examplesTechnical Details
Authentication Flow
Authorization: Bearer <jwt_token>headerjwtMiddlewarevalidates token format and signaturerequireMatchingUserIdensures user can only access their own resourcesSecurity Features
Code Quality
Testing Results
Breaking Changes
None - this is purely additive security enhancement.
Migration
Existing API consumers need to:
Authorization: Bearer <token>header in wallet API requestsuser_idin JWT matchesuser_idin request bodySee
JWT_INTEGRATION.mdfor detailed integration examples.Files Changed
src/auth/jwt.ts- JWT middleware implementationsrc/index.ts- Applied middleware to all wallet routessrc/routes/wallet.ts- Added user authorization to wallet endpointstests/auth/jwt.test.ts- JWT middleware test suitetests/routes/wallet.test.ts- Wallet integration testsJWT_INTEGRATION.md- Integration documentation🔒 Security Impact: This PR significantly enhances the security posture of the wallet service by implementing industry-standard JWT authentication with proper user authorization controls.