fix: enforce current database role and reject deleted users - #429
Open
7-hello007 wants to merge 6 commits into
Open
fix: enforce current database role and reject deleted users#4297-hello007 wants to merge 6 commits into
7-hello007 wants to merge 6 commits into
Conversation
- auth.js now queries DB for current user (isDeleted, role) - loadUser.js syncs req.user.role with DB role - Rejects soft-deleted users → 401 'User account is no longer active.' - Rejects non-existent users → 401 'User account is no longer available.' - Uses current DB role instead of JWT role - Added 6 automated security tests (tests/auth.staleRole.test.js) Security rationale: - Database is the source of truth for user state and role - Role changes take effect immediately - Soft deletion immediately revokes access - No sensitive fields attached to req.user Evidence: - All 6 security tests passed - Before/after evidence captured in toProveProblem/
- tests/auth.staleRole.test.js now requires MONGO_TEST_URI - Fails safely when MONGO_TEST_URI is not set
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.
fix: enforce current database role and reject deleted users
Summary
This PR hardens the authentication middleware (
auth.js) to ensure every protected request validates the current database user and current stored role, rather than trusting stale JWT claims.Changes
auth.jsnow queries DB for current user (isDeleted,role)loadUser.jssyncsreq.user.rolewith DB role401 'User account is no longer active.'401 'User account is no longer available.'tests/auth.staleRole.test.js)Security Rationale
req.userEvidence
Before changing:


After changing:
Changes:
Reason: Running authentication tests on the development database (secureshift_local) could corrupt test data or produce unreliable results.
tests/auth.staleRole.test.jsnow requires the MONGO_TEST_URI environment variable to be set before runningThe tests now require MONGO_TEST_URI to be set before running, or they will fail safely with a clear error message.
