From c5cc65a736606a6906a2e17adcfbceb33ddfedb6 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Tue, 20 Sep 2022 15:34:03 +0300 Subject: [PATCH] Fix/admin extension exception (#984) * check if wallet exists * check wallet existence in key check * return FORBIDDEN for LNBITS_ADMIN_USERS --- lnbits/decorators.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lnbits/decorators.py b/lnbits/decorators.py index 8b8ebd55b..d4aa63aea 100644 --- a/lnbits/decorators.py +++ b/lnbits/decorators.py @@ -153,14 +153,18 @@ async def get_key_type( LNBITS_ADMIN_USERS and wallet.wallet.user not in LNBITS_ADMIN_USERS ) and (LNBITS_ADMIN_EXTENSIONS and pathname in LNBITS_ADMIN_EXTENSIONS): raise HTTPException( - status_code=HTTPStatus.UNAUTHORIZED, detail="User not authorized." + status_code=HTTPStatus.FORBIDDEN, + detail="User not authorized for this extension.", ) return wallet except HTTPException as e: if e.status_code == HTTPStatus.BAD_REQUEST: raise - if e.status_code == HTTPStatus.UNAUTHORIZED: + elif e.status_code == HTTPStatus.UNAUTHORIZED: + # we pass this in case it is not an invoice key, nor an admin key, and then return NOT_FOUND at the end of this block pass + else: + raise except: raise raise HTTPException(