hard: role-gated endpoints trust stale JWT role claims - #128
Open
Godfrey-Delight wants to merge 1 commit into
Open
hard: role-gated endpoints trust stale JWT role claims#128Godfrey-Delight wants to merge 1 commit into
Godfrey-Delight wants to merge 1 commit into
Conversation
EmeditWeb
reviewed
Aug 26, 2026
EmeditWeb
left a comment
Member
There was a problem hiding this comment.
⚠️ Automated Audit: partial
@Godfrey-Delight Good start — please look into the gaps identified below.
The PR genuinely addresses the root cause of Issue #122: RolesGuard now resolves live user roles from the datastore via UserStatusService (30s cached) instead of trusting JWT claims, admin role reset endpoint exists with audit logging, cache invalidation is wired into role changes, and regression tests cover the stale-token attack path. However, context/progress-tracker.md contains unresolved merge conflict markers (<<<<<<< Updated upstream / ======= / >>>>>>> Stashed changes) which is a blockable defect and indicates the change was not properly landed.
Gaps identified:
- Unresolved git merge conflict markers in context/progress-tracker.md (<<<<<<< Updated upstream / ======= / >>>>>>> Stashed changes) — must be resolved before merge
CI checks: ✅ PASSED: build-test
Audited by stepfi-audit-bot 🤖
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.
🔗 Related Issue
Closes #122
🔖 Title
feat(auth): enforce server-truth role authorization and add audited admin role reset
📝 Description
Centralized role-based authorization on server truth rather than un-enforced JWT role claims.
RolesGuardnow resolves live user roles from the datastore viaUserStatusService(cached in-memory with a documented 30-second staleness bound), preventing stale-token attacks where a downgraded user retains role access until token expiration. Added an admin-only role-management endpoint (POST /admin/users/:wallet/role/reset) allowing role resets and overrides with full audit logging viaAuditInterceptor. Role changes automatically invalidate the server-side status cache for immediate effect.🔄 Changes Made
UserStatusServiceto cache status and role (getUserState,getRole). UpdatedRolesGuardto enforce datastore roles rather than trusting JWT claims.UserStatusServiceintoUsersServiceand wireduserStatusService.invalidate(wallet)intosetRole()so role selection updates immediately.AdminRolesControllerexposingPOST /admin/users/:wallet/role/reset, guarded byJwtAuthGuard&AdminGuard, and audited via@AuditAction('admin_users', 'RESET_USER_ROLE')andAuditInterceptor.UsersRepository.forceSetRole(wallet, role)to allow admin role overrides and resets.RolesGuardandUserStatusServicefromAuthModuleand importedAuthModuleinUsersModule,VouchingModule, andAdminModule.RolesGuard(roles.guard.spec.ts),AdminRolesController(admin-roles.controller.spec.ts), and updatedusers.service.spec.ts&vendors.service.spec.ts.context/progress-tracker.md.📸 Screenshots (if applicable)
N/A (Backend API logic change)
🗒️ Additional Notes
npm run buildpassed cleanly with 0 TypeScript compilation errors.npm testpassed with 34/34 test suites green (388/388 total tests passing).USER_STATUS_CACHE_TTL_MS = 30_000), matching account blocking enforcement.