From 6ad4acea50ab0ac682f0f207d60a640a819c7748 Mon Sep 17 00:00:00 2001 From: Kaede Fujisaki Date: Sat, 2 Mar 2024 18:09:08 +0900 Subject: [PATCH 1/7] Consider a case when inbox is nil --- lib/pleroma/web/activity_pub/publisher.ex | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index 9e7d00519..6267d0760 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -159,17 +159,20 @@ defmodule Pleroma.Web.ActivityPub.Publisher do end defp should_federate?(inbox, public) do - if public do - true - else - %{host: host} = URI.parse(inbox) + cond do + inbox == nil -> + false + public -> + true + true -> + %{host: host} = URI.parse(inbox) - quarantined_instances = - Config.get([:instance, :quarantined_instances], []) - |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() - |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() + quarantined_instances = + Config.get([:instance, :quarantined_instances], []) + |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() + |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() - !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) + !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) end end From 2e548c31d4756bcd97d52f9b55dd9d700656b832 Mon Sep 17 00:00:00 2001 From: Kaede Fujisaki Date: Sat, 2 Mar 2024 18:13:36 +0900 Subject: [PATCH 2/7] Add changelog --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 063d51d4c..cc994348e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] + +### Fixed +- Federation: Do not tend to send activities when user's inbox is nil. + ## 2.6.2 ### Security From fb1873b6ec05cb7a0f4fb39267d493d2e2d9d0b1 Mon Sep 17 00:00:00 2001 From: Kaede Fujisaki Date: Sat, 2 Mar 2024 18:23:56 +0900 Subject: [PATCH 3/7] add changelog.d --- CHANGELOG.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc994348e..063d51d4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,6 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). -## [Unreleased] - -### Fixed -- Federation: Do not tend to send activities when user's inbox is nil. - ## 2.6.2 ### Security From 1311f8314e90753bf8a8f781f81f89317657b727 Mon Sep 17 00:00:00 2001 From: Kaede Fujisaki Date: Sat, 2 Mar 2024 18:24:39 +0900 Subject: [PATCH 4/7] add changelog.d --- changelog.d/issue-3241.fix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/issue-3241.fix diff --git a/changelog.d/issue-3241.fix b/changelog.d/issue-3241.fix new file mode 100644 index 000000000..d46db9805 --- /dev/null +++ b/changelog.d/issue-3241.fix @@ -0,0 +1 @@ +Handle cases when users.inbox is nil. From 0242c1f691fffd6c45a2b33763a4a7c25f02e65f Mon Sep 17 00:00:00 2001 From: Kaede Fujisaki Date: Sat, 2 Mar 2024 18:34:12 +0900 Subject: [PATCH 5/7] fmt --- lib/pleroma/web/activity_pub/publisher.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index 6267d0760..f4665275c 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -162,8 +162,10 @@ defmodule Pleroma.Web.ActivityPub.Publisher do cond do inbox == nil -> false + public -> true + true -> %{host: host} = URI.parse(inbox) From 1422082bf238b09927e036f4de9deebb164e0653 Mon Sep 17 00:00:00 2001 From: tusooa Date: Thu, 7 Mar 2024 04:43:56 +0000 Subject: [PATCH 6/7] Apply ledyba's suggestion(s) to 1 file(s) --- lib/pleroma/web/activity_pub/publisher.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index f4665275c..792c6a1c5 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -160,7 +160,7 @@ defmodule Pleroma.Web.ActivityPub.Publisher do defp should_federate?(inbox, public) do cond do - inbox == nil -> + is_nil(inbox) -> false public -> From caf855cf9cb9a5cadd2519237c9e7916007f4850 Mon Sep 17 00:00:00 2001 From: Lain Soykaf Date: Sun, 17 Mar 2024 16:57:45 +0400 Subject: [PATCH 7/7] ActivityPub.Publisher: Don't try federating if a user doesn't have an inbox. --- lib/pleroma/web/activity_pub/publisher.ex | 24 +++++++------------ .../web/activity_pub/publisher_test.exs | 12 ++++++++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index 792c6a1c5..a42b4844e 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -158,24 +158,18 @@ defmodule Pleroma.Web.ActivityPub.Publisher do end end - defp should_federate?(inbox, public) do - cond do - is_nil(inbox) -> - false + def should_federate?(nil, _), do: false + def should_federate?(_, true), do: true - public -> - true + def should_federate?(inbox, _) do + %{host: host} = URI.parse(inbox) - true -> - %{host: host} = URI.parse(inbox) + quarantined_instances = + Config.get([:instance, :quarantined_instances], []) + |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() + |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() - quarantined_instances = - Config.get([:instance, :quarantined_instances], []) - |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() - |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() - - !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) - end + !Pleroma.Web.ActivityPub.MRF.subdomain_match?(quarantined_instances, host) end @spec recipients(User.t(), Activity.t()) :: [[User.t()]] diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 7aa06a5c4..870f1f77a 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -25,6 +25,17 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do setup_all do: clear_config([:instance, :federating], true) + describe "should_federate?/1" do + test "it returns false when the inbox is nil" do + refute Publisher.should_federate?(nil, false) + refute Publisher.should_federate?(nil, true) + end + + test "it returns true when public is true" do + assert Publisher.should_federate?(false, true) + end + end + describe "gather_webfinger_links/1" do test "it returns links" do user = insert(:user) @@ -205,6 +216,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do refute called(Instances.set_reachable(inbox)) end + @tag capture_log: true test_with_mock "calls `Instances.set_unreachable` on target inbox on non-2xx HTTP response code", Instances, [:passthrough],