From 19792abd416ea7ce9acd23e238ebff326aa79476 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 10 Jun 2021 11:40:54 +0200 Subject: [PATCH] Better handling of bad host-meta responses Signed-off-by: Thomas Citharel --- lib/federation/web_finger/web_finger.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/federation/web_finger/web_finger.ex b/lib/federation/web_finger/web_finger.ex index 409f67b8..1eddb189 100644 --- a/lib/federation/web_finger/web_finger.ex +++ b/lib/federation/web_finger/web_finger.ex @@ -144,7 +144,7 @@ defmodule Mobilizon.Federation.WebFinger do @spec find_webfinger_endpoint(String.t()) :: String.t() def find_webfinger_endpoint(domain) when is_binary(domain) do with {:ok, %{body: body}} <- fetch_document("http://#{domain}/.well-known/host-meta"), - link_template <- find_link_from_template(body) do + link_template when is_binary(link_template) <- find_link_from_template(body) do {:ok, link_template} end end @@ -203,6 +203,9 @@ defmodule Mobilizon.Federation.WebFinger do xpath(doc, ~x"//Link[@rel=\"lrdd\"][@type=\"application/json\"]/@template"s), res when res in [nil, ""] <- xpath(doc, ~x"//Link[@rel=\"lrdd\"]/@template"s), do: {:error, :link_not_found} + catch + :exit, _e -> + {:error, :link_not_found} end @spec fetch_document(String.t()) :: Tesla.Env.result()