From dcd862180e30b202f7a25a498466077a189118e3 Mon Sep 17 00:00:00 2001 From: SouthFox Date: Sun, 19 Mar 2023 11:48:10 +0800 Subject: [PATCH] feat/add some precheck --- app/httpsig.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/httpsig.py b/app/httpsig.py index 22975d9..b375e48 100644 --- a/app/httpsig.py +++ b/app/httpsig.py @@ -20,12 +20,17 @@ async def httpsig_checker( Check http signature """ payload = await request.json() - logger.info(f"headers={request.headers}") - logger.info(f"{payload=}") - parsec_signature = HttpSignature.parse_signature( - request.headers.get("signature") - ) + try: + logger.info(f"headers={request.headers}") + logger.info(f"{payload=}") + + parsec_signature = HttpSignature.parse_signature( + request.headers.get("signature") + ) + except KeyError: + logger.warning("Not signature headers") + raise KeyError actor_url = payload["actor"] async with httpx.AsyncClient() as client: @@ -43,6 +48,9 @@ async def httpsig_checker( pubkey = _actor["publicKey"]["publicKeyPem"] except json.JSONDecodeError: raise ValueError + except KeyError: + logger.warning("actor gone? ") + raise KeyError body = await request.body() signture_string = HttpSignature.build_signature_string(