From 259be5bcefee4ac62eb5ecfef1be5280e47ab32b Mon Sep 17 00:00:00 2001 From: Mayel de Borniol Date: Wed, 16 Feb 2022 18:25:52 +1300 Subject: [PATCH] MRF --- docs/MRF.md | 21 ++++++++++----------- flavours/classic/config/activity_pub.exs | 23 +++++++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/docs/MRF.md b/docs/MRF.md index f4f8eca9a0..dac0597b54 100755 --- a/docs/MRF.md +++ b/docs/MRF.md @@ -39,17 +39,17 @@ Servers should be configured as lists. ### Example -This example will enable `SimplePolicy`, block media from `illegalporn.biz`, mark media as NSFW from `porn.biz` and `porn.business`, reject messages from `spam.com`and block reports (flags) from `whiny.whiner`: +This example will enable `SimplePolicy`, block media from `illegalporn.biz`, mark media as NSFW from `porn.biz` and `porn.business`, reject messages from `spam.com` and block reports (flags) from `troll.mob`: ``` -config :bonfire, :instance, +config :activity_pub, :instance, rewrite_policy: [ActivityPub.MRF.SimplePolicy] -config :bonfire, :mrf_simple, +config :activity_pub, :mrf_simple, media_removal: ["illegalporn.biz"], media_nsfw: ["porn.biz", "porn.business"], reject: ["spam.com"], - report_removal: ["whiny.whiner"] + report_removal: ["troll.mob"] ``` @@ -71,15 +71,15 @@ defmodule Site.RewritePolicy do # Catch messages which contain Note objects with actual data to filter. # Capture the object as `object`, the message content as `content` and the - # message itself as `message`. + # entire activity itself as `activity`. @impl true - def filter(%{"type" => Create", "object" => {"type" => "Note", "content" => content} = object} = message) + def filter(%{"type" => "Create", "object" => %{"type" => "Note", "content" => content} = object} = message) when is_binary(content) do # Subject / CW is stored as summary instead of `name` like other AS2 objects # because of Mastodon doing it that way. summary = object["summary"] - # Message edits go here. + # edits go here. content = "new message content" # Assemble the mutated object. @@ -88,9 +88,8 @@ defmodule Site.RewritePolicy do |> Map.put("content", content) |> Map.put("summary", summary) - # Assemble the mutated message. - message = Map.put(message, "object", object) - {:ok, message} + # Assemble the mutated activity. + {:ok, Map.put(activity, "object", object)} end # Let all other messages through without modifying them. @@ -102,7 +101,7 @@ end If you save this file as `lib/site/mrf/rewrite_policy.ex`, it will be included when you next rebuild Bonfire. You can enable it in the configuration like so: ``` -config :bonfire, :instance, +config :activity_pub, :instance, rewrite_policy: [ ActivityPub.MRF.SimplePolicy, Site.RewritePolicy diff --git a/flavours/classic/config/activity_pub.exs b/flavours/classic/config/activity_pub.exs index d74b7115d4..fe09309670 100755 --- a/flavours/classic/config/activity_pub.exs +++ b/flavours/classic/config/activity_pub.exs @@ -5,22 +5,29 @@ config :activity_pub, :repo, Bonfire.Repo config :nodeinfo, :adapter, Bonfire.Federate.ActivityPub.NodeinfoAdapter -config :activity_pub, :mrf_simple, - media_removal: [], - media_nsfw: [], - report_removal: [], - accept: [], - avatar_removal: [], - banner_removal: [] config :activity_pub, :instance, hostname: "localhost", federation_publisher_modules: [ActivityPubWeb.Publisher], federation_reachability_timeout_days: 7, federating: true, - rewrite_policy: [], + rewrite_policy: [Bonfire.Federate.ActivityPub.BoundariesMRF], handle_unknown_activities: true +config :activity_pub, :boundaries, + block: [], + mute: [], + deafen: [] + +config :activity_pub, :mrf_simple, + reject: [], + accept: [], + media_removal: [], + media_nsfw: [], + report_removal: [], + avatar_removal: [], + banner_removal: [] + config :activity_pub, :http, proxy_url: nil, send_user_agent: true,