Problem
The delete_user() function in app/utils/delete.py has NO authorization check. It accepts a username and immediately deletes the user without verifying:
- Whether the calling user is an admin
- Whether the calling user is deleting themselves
- Whether the user being deleted is an admin
The perpetrator_role variable is assigned but never checked. While admin_panel_users.py and account_settings.py currently check admin role before calling delete_user(), this is fragile — any new caller could bypass authorization.
Requirements
-
Add authorization check inside delete_user() itself:
- Non-admin users should only be allowed to delete their own account
- Admins should not be able to delete themselves
- Return a boolean or appropriate response on failure (matching the pattern in
delete_post() and delete_comment())
-
Add logging for unauthorized deletion attempts
-
Add unit tests covering:
- Admin deleting another admin
- Non-admin trying to delete another user
- Successful self-deletion by non-admin
- Successful deletion by admin (non-self)
Problem
The
delete_user()function inapp/utils/delete.pyhas NO authorization check. It accepts a username and immediately deletes the user without verifying:The
perpetrator_rolevariable is assigned but never checked. Whileadmin_panel_users.pyandaccount_settings.pycurrently check admin role before callingdelete_user(), this is fragile — any new caller could bypass authorization.Requirements
Add authorization check inside
delete_user()itself:delete_post()anddelete_comment())Add logging for unauthorized deletion attempts
Add unit tests covering: