don't allow a nil inbox to obliterate federation

This commit is contained in:
Floatingghost 2025-01-06 11:43:41 +00:00
parent 2e049037de
commit 1ffbaa2924
3 changed files with 9 additions and 1 deletions

View file

@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Unreleased ## Unreleased
## 2025.01.01
Hotfix: Federation could break if a null value found its way into `should_federate?\1`
## 2025.01 ## 2025.01

View file

@ -112,7 +112,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
Config.get([:mrf_simple, :accept]) Config.get([:mrf_simple, :accept])
end end
def should_federate?(url) do def should_federate?(url) when is_binary(url) do
%{host: host} = URI.parse(url) %{host: host} = URI.parse(url)
with {nil, false} <- {nil, is_nil(host)}, with {nil, false} <- {nil, is_nil(host)},
@ -137,6 +137,8 @@ defmodule Pleroma.Web.ActivityPub.Publisher do
end end
end end
def should_federate?(_), do: false
@spec recipients(User.t(), Activity.t()) :: list(User.t()) | [] @spec recipients(User.t(), Activity.t()) :: list(User.t()) | []
defp recipients(actor, activity) do defp recipients(actor, activity) do
followers = followers =

View file

@ -519,6 +519,9 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do
test "should not obliterate itself if the inbox URL is bad" do test "should not obliterate itself if the inbox URL is bad" do
url = "/inbox" url = "/inbox"
refute Pleroma.Web.ActivityPub.Publisher.should_federate?(url) refute Pleroma.Web.ActivityPub.Publisher.should_federate?(url)
url = nil
refute Pleroma.Web.ActivityPub.Publisher.should_federate?(url)
end end
end end
end end