What changed, and why it matters
This commit changes the order of checks when an admin deletes a user account. Previously, the code deleted the user's wallets before checking whether the target was the super-user or another admin. Now it performs those permission checks first. The change prevents an admin from partially deleting wallets belonging to the super-user or another admin before the operation is rejected. It is a hardening fix, but the commit message gives no security context.
Treat as a minor security hardening fix. Review whether delete_wallet_by_id has other side effects (e.g., balance transfers, webhook events) that could still be triggered by an admin against protected accounts, and confirm that check_admin is enforced on all callers. No urgent patch action is required beyond merging.
Security signals we found
Authorization check reordered before destructive operation
Admin-only endpoint with destructive wallet deletion
Potential partial-state mutation before guard clause (pre-patch)
No explicit security disclosure in commit message
Evidence from the diff
In lnbits/core/views/user_api.py, api_users_delete_user originally called get_wallets(user_id, deleted=False) and iterated delete_wallet_by_id(wallet.id) before verifying if user_id == settings.super_user or if the target user had admin privileges. The patch moves those two HTTPException guard clauses above the wallet-deletion loop, so the request fails fast. This closes a window where an authenticated admin could trigger destructive side effects (wallet soft-deletion) on protected accounts even though the final delete_account call would be blocked. The change is small and does not add new authorization logic; it only reorders existing logic.
Changed components
lnbits/core/views/user_api.pyapi_users_delete_user endpointwallet deletion flowadmin/super-user authorization checksInspect captured patch +5 / −4
diff --git a/lnbits/core/views/user_api.py b/lnbits/core/views/user_api.py
index dd50076..a9d6146 100644
--- a/lnbits/core/views/user_api.py
+++ b/lnbits/core/views/user_api.py
@@ -158,10 +158,6 @@ async def api_update_user(
async def api_users_delete_user(
user_id: str, account: Account = Depends(check_admin)
) -> SimpleStatus:
- wallets = await get_wallets(user_id, deleted=False)
- for wallet in wallets:
- await delete_wallet_by_id(wallet.id)
-
if user_id == settings.super_user:
raise HTTPException(
status_code=HTTPStatus.BAD_REQUEST,
@@ -173,6 +169,11 @@ async def api_users_delete_user(
status_code=HTTPStatus.BAD_REQUEST,
detail="Only super_user can delete admin user.",
)
+
+ wallets = await get_wallets(user_id, deleted=False)
+ for wallet in wallets:
+ await delete_wallet_by_id(wallet.id)
+
await delete_account(user_id)
return SimpleStatus(success=True, message="User deleted.")
Why this scored 57/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.