aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKaren Konou <konoukaren@gmail.com>2019-02-12 23:25:09 +0100
committerKaren Konou <konoukaren@gmail.com>2019-02-13 00:01:34 +0100
commit1d727cd0691fdedcd78d5ef22c07a1b280531037 (patch)
tree9b7472cff3c272f9aa4262fea4943990fc00e1ee /lib
parentac72b578da673282b927b945bfe03cd3012444b6 (diff)
downloadpleroma-1d727cd0691fdedcd78d5ef22c07a1b280531037.tar.gz
added checks for public url and follower collections
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex23
1 files changed, 20 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 4c6e612b2..9be382972 100644
--- a/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
+++ b/lib/pleroma/web/activity_pub/mrf/hellthread_policy.ex
@@ -14,6 +14,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
|> Map.put("cc", ["https://www.w3.org/ns/activitystreams#Public"])
end
+ defp get_recipient_count(message) do
+ recipients = (message["to"] || []) ++ (message["cc"] || [])
+
+ cond do
+ Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") &&
+ Enum.find(recipients, &String.ends_with?(&1, "/followers")) ->
+ length(recipients) - 2
+
+ Enum.member?(recipients, "https://www.w3.org/ns/activitystreams#Public") ||
+ Enum.find(recipients, &String.ends_with?(&1, "/followers")) ->
+ length(recipients) - 1
+
+ true ->
+ length(recipients)
+ end
+ end
+
@impl true
def filter(%{"type" => "Create"} = message) do
delist_threshold = Pleroma.Config.get([:mrf_hellthread, :delist_threshold])
@@ -24,13 +41,13 @@ defmodule Pleroma.Web.ActivityPub.MRF.HellthreadPolicy do
Pleroma.Config.get([:mrf_hellthread, :threshold])
)
- recipients = (message["to"] || []) ++ (message["cc"] || [])
+ recipients = get_recipient_count(message)
cond do
- length(recipients) > reject_threshold and reject_threshold > 0 ->
+ recipients > reject_threshold and reject_threshold > 0 ->
{:reject, nil}
- length(recipients) > delist_threshold and delist_threshold > 0 ->
+ recipients > delist_threshold and delist_threshold > 0 ->
if Enum.member?(message["to"], "https://www.w3.org/ns/activitystreams#Public") or
Enum.member?(message["cc"], "https://www.w3.org/ns/activitystreams#Public") do
{:ok, delist_message(message)}