From 1f44e93518a50ee0d0684a805dd2e10312986e18 Mon Sep 17 00:00:00 2001 From: Michael Manfre Date: Sat, 14 Jan 2023 16:19:47 -0500 Subject: [PATCH] Handle servers that return wrong webfinger payload (#415) --- users/models/identity.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/users/models/identity.py b/users/models/identity.py index c3333c0..d38dbaf 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -683,14 +683,18 @@ class Identity(StatorModel): "JSON parse error fetching webfinger", response.content, ) - if data["subject"].startswith("acct:"): - data["subject"] = data["subject"][5:] - for link in data["links"]: - if ( - link.get("type") == "application/activity+json" - and link.get("rel") == "self" - ): - return link["href"], data["subject"] + try: + if data["subject"].startswith("acct:"): + data["subject"] = data["subject"][5:] + for link in data["links"]: + if ( + link.get("type") == "application/activity+json" + and link.get("rel") == "self" + ): + return link["href"], data["subject"] + except KeyError: + # Server returning wrong payload structure + pass return None, None async def fetch_actor(self) -> bool: