Add authentication and IDOR protection to account endpoints#42
Open
saaa99999999 wants to merge 2 commits into
Open
Add authentication and IDOR protection to account endpoints#42saaa99999999 wants to merge 2 commits into
saaa99999999 wants to merge 2 commits into
Conversation
All four account CRUD endpoints (GET /accounts, GET /accounts/{id},
PATCH /accounts/{id}, DELETE /accounts) had no authentication, allowing
unauthenticated attackers to enumerate all users with their emails, modify
any user's password/email, and delete any account.
Added get_current_user dependency that validates JWT Bearer tokens
and added IDOR checks to ensure users can only access and modify
their own account data.
Author
CVE RequestThis PR fixes CWE-862 (Missing Authorization): all four account CRUD endpoints ( Could you please request a CVE via GitHub Security Advisory for this vulnerability? |
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.
Summary
All four account CRUD endpoints had no authentication or authorization checks:
GET /api/accounts— returned all users with emails and tokens to unauthenticated callersGET /api/accounts/{id}— allowed reading any user's full profile without authPATCH /api/accounts/{id}— allowed changing any user's password, email, or username without authDELETE /api/accounts?id=N— allowed deleting any user's account without authChanges
backend/src/api/dependencies/auth.pywithget_current_userdependency that validates JWT Bearer tokens and returns the authenticated userbackend/src/api/routes/account.py:Depends(get_current_user)to all four account endpointsidmatches the authenticated user'sid)GET /accountsnow returns only the current user's data instead of all usersFixed Vulnerability
Test plan
POST /api/auth/signupGET /api/accountswithout Bearer token returns 401GET /api/accountswith valid Bearer token returns only the authenticated userPATCH /api/accounts/999(different user ID) with valid token returns 403DELETE /api/accounts?id=999(different user ID) with valid token returns 403