Skip to content

CRITICAL: Add authorization checks to delete_user() function #259

Description

@DogukanUrker

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

  1. 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())
  2. Add logging for unauthorized deletion attempts

  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    securitySecurity-related issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions