From ca000f8301a1ed08fbc6cdb3712b82c4cdb4b78c Mon Sep 17 00:00:00 2001 From: floatingghost Date: Tue, 2 Aug 2022 14:19:24 +0000 Subject: [PATCH] Merge mrf_simple-reject with quarantine (#137) Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/137 --- CHANGELOG.md | 1 + config/config.exs | 1 - config/description.exs | 2 +- docs/docs/configuration/cheatsheet.md | 4 +-- lib/pleroma/config/deprecation_warnings.ex | 6 ++-- lib/pleroma/web/activity_pub/publisher.ex | 7 ++++- .../web/activity_pub/publisher_test.exs | 30 ++++++++++++++++++- 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6010744dd..c658af460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - quarantining is now considered absolutely; public activities are no longer an exception. +- also merged quarantine and mrf reject - quarantine is now deprecated - flavours: - amd64 is built for debian stable. Compatible with ubuntu 20. - ubuntu-jammy is built for... well, ubuntu 22 (LTS) diff --git a/config/config.exs b/config/config.exs index d14c4e3d7..947ff0ecc 100644 --- a/config/config.exs +++ b/config/config.exs @@ -215,7 +215,6 @@ config :pleroma, :instance, ], allow_relay: true, public: true, - quarantined_instances: [], static_dir: "instance/static/", allowed_post_formats: [ "text/plain", diff --git a/config/description.exs b/config/description.exs index e864f090c..9cbd0024d 100644 --- a/config/description.exs +++ b/config/description.exs @@ -691,7 +691,7 @@ config :pleroma, :config_description, [ key_placeholder: "instance", value_placeholder: "reason", description: - "List of ActivityPub instances where activities will not be sent, and the reason for doing so", + "(Deprecated, will be removed in next release) List of ActivityPub instances where activities will not be sent, and the reason for doing so", suggestions: [ {"quarantined.com", "Reason"}, {"*.quarantined.com", "Reason"} diff --git a/docs/docs/configuration/cheatsheet.md b/docs/docs/configuration/cheatsheet.md index bac20070f..83d943c51 100644 --- a/docs/docs/configuration/cheatsheet.md +++ b/docs/docs/configuration/cheatsheet.md @@ -34,7 +34,7 @@ To add configuration to your config file, you can copy it from the base config. * `federation_reachability_timeout_days`: Timeout (in days) of each external federation target being unreachable prior to pausing federating to it. * `allow_relay`: Permits remote instances to subscribe to all public posts of your instance. This may increase the visibility of your instance. * `public`: Makes the client API in authenticated mode-only except for user-profiles. Useful for disabling the Local Timeline and The Whole Known Network. Note that there is a dependent setting restricting or allowing unauthenticated access to specific resources, see `restrict_unauthenticated` for more details. -* `quarantined_instances`: ActivityPub instances where activities will not be sent. They can still reach there via other means, we just won't send them. +* `quarantined_instances`: *DEPRECATED* ActivityPub instances where activities will not be sent. They can still reach there via other means, we just won't send them. * `allowed_post_formats`: MIME-type list of formats allowed to be posted (transformed into HTML). * `extended_nickname_format`: Set to `true` to use extended local nicknames format (allows underscores/dashes). This will break federation with older software for theses nicknames. @@ -131,7 +131,7 @@ To add configuration to your config file, you can copy it from the base config. * `media_removal`: List of instances to strip media attachments from and the reason for doing so. * `media_nsfw`: List of instances to tag all media as NSFW (sensitive) from and the reason for doing so. * `federated_timeline_removal`: List of instances to remove from the Federated Timeline (aka The Whole Known Network) and the reason for doing so. -* `reject`: List of instances to reject activities (except deletes) from and the reason for doing so. +* `reject`: List of instances to reject activities (except deletes) from and the reason for doing so. Additionally prevents activities from being sent to that instance. * `accept`: List of instances to only accept activities (except deletes) from and the reason for doing so. * `followers_only`: Force posts from the given instances to be visible by followers only and the reason for doing so. * `report_removal`: List of instances to reject reports from and the reason for doing so. diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index 3675c5e4a..8a336c35a 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -17,7 +17,9 @@ defmodule Pleroma.Config.DeprecationWarnings do {[:instance, :mrf_transparency], [:mrf, :transparency], "\n* `config :pleroma, :instance, mrf_transparency` is now `config :pleroma, :mrf, transparency`"}, {[:instance, :mrf_transparency_exclusions], [:mrf, :transparency_exclusions], - "\n* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`"} + "\n* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`"}, + {[:instance, :quarantined_instances], [:mrf_simple, :reject], + "\n* `config :pleroma, :instance, :quarantined_instances` is now covered by `:pleroma, :mrf_simple, :reject`"} ] def check_simple_policy_tuples do @@ -81,7 +83,7 @@ defmodule Pleroma.Config.DeprecationWarnings do end def check_quarantined_instances_tuples do - has_strings = Config.get([:instance, :quarantined_instances]) |> Enum.any?(&is_binary/1) + has_strings = Config.get([:instance, :quarantined_instances], []) |> Enum.any?(&is_binary/1) if has_strings do Logger.warn(""" diff --git a/lib/pleroma/web/activity_pub/publisher.ex b/lib/pleroma/web/activity_pub/publisher.ex index cd820fa3d..ed67a060d 100644 --- a/lib/pleroma/web/activity_pub/publisher.ex +++ b/lib/pleroma/web/activity_pub/publisher.ex @@ -103,11 +103,16 @@ defmodule Pleroma.Web.ActivityPub.Publisher do end end + defp blocked_instances do + Config.get([:instance, :quarantined_instances], []) ++ + Config.get([:mrf_simple, :reject], []) + end + defp should_federate?(inbox) do %{host: host} = URI.parse(inbox) quarantined_instances = - Config.get([:instance, :quarantined_instances], []) + blocked_instances() |> Pleroma.Web.ActivityPub.MRF.instance_list_from_tuples() |> Pleroma.Web.ActivityPub.MRF.subdomains_regex() diff --git a/test/pleroma/web/activity_pub/publisher_test.exs b/test/pleroma/web/activity_pub/publisher_test.exs index 95f12de2d..0f1d621b1 100644 --- a/test/pleroma/web/activity_pub/publisher_test.exs +++ b/test/pleroma/web/activity_pub/publisher_test.exs @@ -26,6 +26,7 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do setup_all do clear_config([:instance, :federating], true) clear_config([:instance, :quarantined_instances], []) + clear_config([:mrf_simple, :reject], []) end describe "gather_webfinger_links/1" do @@ -270,12 +271,14 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do end describe "publish/2" do - test_with_mock "doesn't publish any activity to quarantined instances.", + test_with_mock "doesn't publish any activity to quarantined or rejected instances.", Pleroma.Web.Federator.Publisher, [:passthrough], [] do Config.put([:instance, :quarantined_instances], [{"domain.com", "some reason"}]) + Config.put([:mrf_simple, :reject], [{"rejected.com", "some reason"}]) + follower = insert(:user, %{ local: false, @@ -283,9 +286,18 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do ap_enabled: true }) + another_follower = + insert(:user, %{ + local: false, + inbox: "https://rejected.com/users/nick2/inbox", + ap_enabled: true + }) + actor = insert(:user, follower_address: follower.ap_id) {:ok, follower, actor} = Pleroma.User.follow(follower, actor) + {:ok, _another_follower, actor} = Pleroma.User.follow(another_follower, actor) + actor = refresh_record(actor) note_activity = @@ -321,6 +333,22 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do id: public_note_activity.data["id"] }) ) + + assert not called( + Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{ + inbox: "https://rejected.com/users/nick2/inbox", + actor_id: actor.id, + id: note_activity.data["id"] + }) + ) + + assert not called( + Pleroma.Web.Federator.Publisher.enqueue_one(Publisher, %{ + inbox: "https://rejected.com/users/nick1/inbox", + actor_id: actor.id, + id: public_note_activity.data["id"] + }) + ) end test_with_mock "Publishes a non-public activity to non-quarantined instances.",