-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
onlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week
Description
π Secure Wallet Endpoints with JWT Authentication π οΈ
π Description
Secure wallet-related API endpoints in the Stellar wallet service by applying JWT authentication middleware. This will ensure that only users with valid JWTs, issued after successful WebAuthn authentication, can access sensitive wallet operations such as account creation and management. The implementation will protect the /wallet/* endpoints to enhance the security of the service.
π― Objective
Apply the JWT middleware from src/auth/jwt.js to secure the /wallet/* endpoints in services/stellar-wallet/src/routes/wallet.js, with a unit test to verify access control.
π Structure
- Directory:
services/stellar-wallet - Files:
src/routes/wallet.js(updated)tests/routes/wallet.test.js(updated)
- Expected structure:
services/stellar-wallet βββ src β βββ index.js β βββ stellar β β βββ client.js β β βββ keys.js β β βββ fund.js β βββ db β β βββ kyc.js β βββ routes β β βββ kyc.js β β βββ kyc-verify.js β β βββ kyc-status.js β β βββ auth-register.js β β βββ auth-verify.js β β βββ auth-login.js β β βββ wallet.js β βββ kyc β β βββ validate.js β βββ soroban β β βββ client.js β β βββ kyc-contract.rs β β βββ deploy.js β βββ auth β βββ webauthn.js β βββ jwt.js βββ config β βββ db.sqlite βββ tests β βββ stellar β β βββ client.test.js β β βββ keys.test.js β β βββ fund.test.js β βββ db β β βββ kyc.test.js β βββ routes β β βββ kyc.test.js β β βββ kyc-verify.test.js β β βββ kyc-status.test.js β β βββ auth-register.test.js β β βββ auth-verify.test.js β β βββ auth-login.test.js β β βββ wallet.test.js β βββ kyc β β βββ validate.test.js β βββ soroban β β βββ client.test.js β β βββ deploy.test.js β βββ auth β βββ jwt.test.js βββ package.json βββ .env.example βββ .eslintrc.json βββ .eslintignore βββ .prettierrc.json βββ .prettierignore βββ .gitignore
β Requirements
- Create a branch named
feat/secure-wallet-endpointsfor this task. - Update
src/routes/wallet.jsto apply thejwtMiddlewarefromsrc/auth/jwt.js(Issue 20) to thePOST /wallet/createendpoint. - Ensure the middleware checks for a valid JWT in the
Authorization: Bearer <token>header. - Return HTTP 401 with a JSON error message (e.g.,
{ error: "Unauthorized" }) if the JWT is missing or invalid. - Return HTTP 403 with a JSON error message (e.g.,
{ error: "Forbidden" }) if theuser_idin the JWT does not match theuser_idin the request body. - Update
src/index.jsto applyjwtMiddlewareto all/wallet/*routes for consistency. - Update the unit test in
tests/routes/wallet.test.jsto verify:- Requests with a valid JWT and matching
user_idsucceed (HTTP 201 forPOST /wallet/create). - Requests without a JWT return HTTP 401.
- Requests with a valid JWT but mismatched
user_idreturn HTTP 403.
- Requests with a valid JWT and matching
- Mock the JWT middleware and SQLite database in the unit test to avoid external dependencies.
- Ensure the code adheres to ESLint and Prettier rules (from Issue 3).
- Commit changes to the
feat/secure-wallet-endpointsbranch with a message likefeat: secure wallet endpoints. - Verify that the CI pipeline (from Issue 1) passes, with linting and test jobs succeeding.
π Expected Outcomes
src/routes/wallet.jsappliesjwtMiddlewareto thePOST /wallet/createendpoint./wallet/*routes are protected byjwtMiddlewareinsrc/index.js.- Valid JWTs with matching
user_idallow access to thePOST /wallet/createendpoint. - Missing or invalid JWTs return HTTP 401 with a JSON error message.
- Mismatched
user_idreturns HTTP 403 with a JSON error message. - Updated unit test in
tests/routes/wallet.test.jsconfirms access control behavior. - Code passes ESLint and Prettier checks.
- Changes are committed to the
feat/secure-wallet-endpointsbranch with a descriptive lowercase commit message. - CI pipeline runs successfully, with linting passing for updated
src/routes/wallet.jsandtests/routes/wallet.test.js, and the unit test passing.
π References
π Notes
- The
jwtMiddlewareshould extract and validate the JWT from theAuthorization: Bearer <token>header. - The
user_idin the JWT payload must match theuser_idin the request body to prevent unauthorized access. - Mocking the JWT middleware and SQLite database in tests ensures reliable CI execution.
- Ensure error messages are consistent with other endpoints (e.g., JSON format
{ error: "message" }). - Commit messages must be in lowercase and start with
feat,change,fix,chore, orrefactor. - The CI pipeline should validate the updated code, ensuring ESLint passes and the unit test executes successfully.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
onlydust-waveContribute to awesome OSS repos during OnlyDust's open source weekContribute to awesome OSS repos during OnlyDust's open source week