commit: 432e7ff53f5f5a7e207657621c75f586989f5e2f
parent 714f47c30f0d8a3a81e8bb3e656e52dda78d20ac
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 6 Mar 2023 22:21:35 +0100
MRF: Add SoftwarePolicy with blocks against Wildebeest
Note: Wildebeest is abandonned, this is only there if another more or less
proprietary implementation shows up.
Diffstat:
1 file changed, 52 insertions(+), 0 deletions(-)
diff --git a/lib/pleroma/web/activity_pub/mrf/software_policy.ex b/lib/pleroma/web/activity_pub/mrf/software_policy.ex
@@ -0,0 +1,52 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.SoftwarePolicy do
+ @moduledoc "Filter activities depending on the software used"
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
+
+ alias Pleroma.Instances.Instance
+
+ defp check_wildebeest(%URI{host: nil}, object), do: {:ok, object}
+
+ defp check_wildebeest(%URI{} = uri, object) do
+ instance_info = Instance.get_or_update_metadata(uri)
+
+ if instance_info && Map.get(instance_info, :software_name) == "wildebeest" do
+ {:reject, "[SoftwarePolicy] Cloudflare Wildebeest"}
+ else
+ {:ok, object}
+ end
+ end
+
+ @impl true
+ def filter(%{"id" => actor} = object) do
+ uri = URI.parse(actor)
+
+ with {:ok, object} <- check_wildebeest(uri, object) do
+ {:ok, object}
+ else
+ {:reject, nil} -> {:reject, "[SoftwarePolicy]"}
+ {:reject, _} = e -> e
+ _ -> {:reject, "[SoftwarePolicy]"}
+ end
+ end
+
+ def filter(object) when is_binary(object) do
+ uri = URI.parse(object)
+
+ with {:ok, object} <- check_wildebeest(uri, object) do
+ {:ok, object}
+ else
+ {:reject, nil} -> {:reject, "[SoftwarePolicy]"}
+ {:reject, _} = e -> e
+ _ -> {:reject, "[SoftwarePolicy]"}
+ end
+ end
+
+ def filter(object), do: {:ok, object}
+
+ @impl true
+ def describe, do: {:ok, %{}}
+end