add domain whitelist

This commit is contained in:
Moon Man 2020-03-23 01:01:30 +00:00
parent 596bf5882d
commit 5925f1b00f
1 changed files with 13 additions and 5 deletions

View File

@ -10,15 +10,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
length(result) == 1
end
defp local_actor(actor) do
host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
prefix = "https://" <> host <> "/"
String.starts_with?(actor, prefix)
defp is_remote(host) do
my_host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
my_host != host
end
# if whitelist is not defined, everything is "whitelisted"
defp is_whitelisted(domain) do
whitelist = Pleroma.Config.get([:emoji_stealer, :whitelist])
whitelist == nil || Enum.member?(whitelist, domain)
end
@impl true
def filter(%{"object" => %{"emoji" => foreign_emoji, "actor" => actor}} = object) do
unless local_actor(actor) do
host = URI.parse(actor).host
if is_remote(host) && is_whitelisted(host) do
num_foreign_emoji = Kernel.map_size(foreign_emoji)
if num_foreign_emoji > 0 do