add domain whitelist
This commit is contained in:
parent
596bf5882d
commit
5925f1b00f
|
@ -10,15 +10,23 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
||||||
length(result) == 1
|
length(result) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
defp local_actor(actor) do
|
defp is_remote(host) do
|
||||||
host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
|
my_host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||||
prefix = "https://" <> host <> "/"
|
my_host != host
|
||||||
String.starts_with?(actor, prefix)
|
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
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def filter(%{"object" => %{"emoji" => foreign_emoji, "actor" => actor}} = object) do
|
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)
|
num_foreign_emoji = Kernel.map_size(foreign_emoji)
|
||||||
|
|
||||||
if num_foreign_emoji > 0 do
|
if num_foreign_emoji > 0 do
|
||||||
|
|
Loading…
Reference in New Issue