logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: a8701b59c33526d89054e7eb142cc3ccb3ad1180
parent b43c7afde686f0a46d1983f57024d6f91f15a056
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:

Alib/pleroma/web/activity_pub/mrf/software_policy.ex52++++++++++++++++++++++++++++++++++++++++++++++++++++
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