From 92362e1e22a3debfaf3275822519417ee8755a7a Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 22 Dec 2018 23:18:31 +0100 Subject: [PATCH 1/5] Implement large thread filter --- config/config.exs | 2 ++ .../web/activity_pub/mrf/hellthread_policy.ex | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex diff --git a/config/config.exs b/config/config.exs index 65d7346de..de834e03a 100644 --- a/config/config.exs +++ b/config/config.exs @@ -163,6 +163,8 @@ allow_followersonly: false, allow_direct: false +config :pleroma, :mrf_hellthreadmitigation, threshold: 10 + config :pleroma, :mrf_simple, media_removal: [], media_nsfw: [], diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex new file mode 100644 index 000000000..0e0918126 --- /dev/null +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -0,0 +1,15 @@ +defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do + @behaviour Pleroma.Web.ActivityPub.MRF + + @impl true + def filter(object) do + + policy = Pleroma.Config.get(:mrf_hellthreadmitigation) + + if (length(object["to"]) + length(object["cc"])) > Keyword.get(policy, :threshold) do + {:reject, nil} + else + {:ok, object} + end + end +end \ No newline at end of file From 409ff60bf87d40919ec8cfcbe054cb66b87ca972 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sat, 22 Dec 2018 23:32:38 +0100 Subject: [PATCH 2/5] Fix formatting --- config/config.exs | 2 +- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/config/config.exs b/config/config.exs index de834e03a..5e1006f50 100644 --- a/config/config.exs +++ b/config/config.exs @@ -163,7 +163,7 @@ allow_followersonly: false, allow_direct: false -config :pleroma, :mrf_hellthreadmitigation, threshold: 10 +config :pleroma, :mrf_hellthreadmitigation, threshold: 10 config :pleroma, :mrf_simple, media_removal: [], diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index 0e0918126..edcbc5219 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -3,13 +3,12 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @impl true def filter(object) do - policy = Pleroma.Config.get(:mrf_hellthreadmitigation) - if (length(object["to"]) + length(object["cc"])) > Keyword.get(policy, :threshold) do + if length(object["to"]) + length(object["cc"]) > Keyword.get(policy, :threshold) do {:reject, nil} else {:ok, object} end end -end \ No newline at end of file +end From c92f91ffebd848b7b9840b238d72455db285d564 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 23 Dec 2018 10:41:56 +0100 Subject: [PATCH 3/5] Add documentation --- docs/config.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/config.md b/docs/config.md index c35769f21..819ac91f8 100644 --- a/docs/config.md +++ b/docs/config.md @@ -121,6 +121,9 @@ This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:i * `allow_followersonly`: whether to allow followers-only posts * `allow_direct`: whether to allow direct messages +## :mrf_hellthreadmitigation +* `threshold`: Number of mentioned users after which the message gets discarded as spam + ## :media_proxy * `enabled`: Enables proxying of remote media to the instance’s proxy * `base_url`: The base URL to access a user-uploaded file. Useful when you want to proxy the media files via another host/CDN fronts. From c76179419d5d4bb2423496856ad931974b56d6d5 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 23 Dec 2018 11:14:29 +0100 Subject: [PATCH 4/5] Renamed the things --- config/config.exs | 2 +- docs/config.md | 2 +- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/config.exs b/config/config.exs index 5e1006f50..4b8762761 100644 --- a/config/config.exs +++ b/config/config.exs @@ -163,7 +163,7 @@ allow_followersonly: false, allow_direct: false -config :pleroma, :mrf_hellthreadmitigation, threshold: 10 +config :pleroma, :mrf_hellthread, threshold: 10 config :pleroma, :mrf_simple, media_removal: [], diff --git a/docs/config.md b/docs/config.md index 819ac91f8..728916f82 100644 --- a/docs/config.md +++ b/docs/config.md @@ -121,7 +121,7 @@ This section is used to configure Pleroma-FE, unless ``:managed_config`` in ``:i * `allow_followersonly`: whether to allow followers-only posts * `allow_direct`: whether to allow direct messages -## :mrf_hellthreadmitigation +## :mrf_hellthread * `threshold`: Number of mentioned users after which the message gets discarded as spam ## :media_proxy diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index edcbc5219..d5aa2b988 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -3,7 +3,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @impl true def filter(object) do - policy = Pleroma.Config.get(:mrf_hellthreadmitigation) + policy = Pleroma.Config.get(:mrf_hellthread) if length(object["to"]) + length(object["cc"]) > Keyword.get(policy, :threshold) do {:reject, nil} From a7f07bb6e56ad5173b9c2063d7f920cd102b4f2d Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Sun, 23 Dec 2018 12:24:53 +0100 Subject: [PATCH 5/5] Implement kaniini's tweaks --- lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex index d5aa2b988..55d6ff3f0 100644 --- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex +++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex @@ -2,13 +2,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do @behaviour Pleroma.Web.ActivityPub.MRF @impl true - def filter(object) do - policy = Pleroma.Config.get(:mrf_hellthread) + def filter(%{"type" => "Create"} = object) do + threshold = Pleroma.Config.get([:mrf_hellthread, :threshold]) + recipients = (object["to"] || []) ++ (object["cc"] || []) - if length(object["to"]) + length(object["cc"]) > Keyword.get(policy, :threshold) do + if length(recipients) > threshold do {:reject, nil} else {:ok, object} end end + + @impl true + def filter(object), do: {:ok, object} end