defp check_media_removal(
%{host: actor_host} = _actor_info,
- %{"type" => "Create", "object" => %{"attachment" => child_attachment}} = object
+ %{"type" => type, "object" => %{"attachment" => child_attachment}} = object
)
- when length(child_attachment) > 0 do
+ when type in ["Create", "Update"] and length(child_attachment) > 0 do
media_removal =
instance_list(:media_removal)
|> MRF.subdomains_regex()
defp check_media_nsfw(
%{host: actor_host} = _actor_info,
%{
- "type" => "Create",
+ "type" => type,
"object" => %{} = _child_object
} = object
- ) do
+ )
+ when type in ["Create", "Update"] do
media_nsfw =
instance_list(:media_nsfw)
|> MRF.subdomains_regex()
def filter(object), do: {:ok, object}
+ defp obfuscate(string) when is_binary(string) do
+ string
+ |> to_charlist()
+ |> Enum.with_index()
+ |> Enum.map(fn
+ {?., _index} ->
+ ?.
+
+ {char, index} ->
+ if 3 <= index && index < String.length(string) - 3, do: ?*, else: char
+ end)
+ |> to_string()
+ end
+
+ defp maybe_obfuscate(host, obfuscations) do
+ if MRF.subdomain_match?(obfuscations, host) do
+ obfuscate(host)
+ else
+ host
+ end
+ end
+
@impl true
def describe do
exclusions = Config.get([:mrf, :transparency_exclusions]) |> MRF.instance_list_from_tuples()
+ obfuscations =
+ Config.get([:mrf, :transparency_obfuscate_domains], []) |> MRF.subdomains_regex()
+
mrf_simple_excluded =
Config.get(:mrf_simple)
|> Enum.map(fn {rule, instances} ->
mrf_simple =
mrf_simple_excluded
|> Enum.map(fn {rule, instances} ->
- {rule, Enum.map(instances, fn {host, _} -> host end)}
+ {rule, Enum.map(instances, fn {host, _} -> maybe_obfuscate(host, obfuscations) end)}
end)
|> Map.new()
|> Enum.map(fn {rule, instances} ->
instances =
instances
- |> Enum.map(fn {host, reason} -> {host, %{"reason" => reason}} end)
+ |> Enum.map(fn {host, reason} ->
+ {maybe_obfuscate(host, obfuscations), %{"reason" => reason}}
+ end)
|> Map.new()
{rule, instances}