mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-03-13 07:02:41 +00:00
Fix missing check for domain presence in rich media ignore_host configuration
This commit is contained in:
parent
31e3b98641
commit
f26509bf16
3 changed files with 30 additions and 4 deletions
1
changelog.d/rich-media-ignore-host.fix
Normal file
1
changelog.d/rich-media-ignore-host.fix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Fix missing check for domain presence in rich media ignore_host configuration
|
|
@ -54,7 +54,10 @@ defmodule Pleroma.Web.RichMedia.Card do
|
||||||
|
|
||||||
@spec get_by_url(String.t() | nil) :: t() | nil | :error
|
@spec get_by_url(String.t() | nil) :: t() | nil | :error
|
||||||
def get_by_url(url) when is_binary(url) do
|
def get_by_url(url) when is_binary(url) do
|
||||||
if @config_impl.get([:rich_media, :enabled]) do
|
host = URI.parse(url).host
|
||||||
|
|
||||||
|
with true <- @config_impl.get([:rich_media, :enabled]),
|
||||||
|
true <- host not in @config_impl.get([:rich_media, :ignore_hosts], []) do
|
||||||
url_hash = url_to_hash(url)
|
url_hash = url_to_hash(url)
|
||||||
|
|
||||||
@cachex.fetch!(:rich_media_cache, url_hash, fn _ ->
|
@cachex.fetch!(:rich_media_cache, url_hash, fn _ ->
|
||||||
|
@ -69,7 +72,7 @@ defmodule Pleroma.Web.RichMedia.Card do
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
:error
|
false -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,7 +80,10 @@ defmodule Pleroma.Web.RichMedia.Card do
|
||||||
|
|
||||||
@spec get_or_backfill_by_url(String.t(), keyword()) :: t() | nil
|
@spec get_or_backfill_by_url(String.t(), keyword()) :: t() | nil
|
||||||
def get_or_backfill_by_url(url, opts \\ []) do
|
def get_or_backfill_by_url(url, opts \\ []) do
|
||||||
if @config_impl.get([:rich_media, :enabled]) do
|
host = URI.parse(url).host
|
||||||
|
|
||||||
|
with true <- @config_impl.get([:rich_media, :enabled]),
|
||||||
|
true <- host not in @config_impl.get([:rich_media, :ignore_hosts], []) do
|
||||||
case get_by_url(url) do
|
case get_by_url(url) do
|
||||||
%__MODULE__{} = card ->
|
%__MODULE__{} = card ->
|
||||||
card
|
card
|
||||||
|
@ -94,7 +100,7 @@ defmodule Pleroma.Web.RichMedia.Card do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
nil
|
false -> nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -83,4 +83,23 @@ defmodule Pleroma.Web.RichMedia.CardTest do
|
||||||
Card.get_by_activity(activity)
|
Card.get_by_activity(activity)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "refuses to crawl URL in activity from ignored host/domain" do
|
||||||
|
clear_config([:rich_media, :ignore_hosts], ["example.com"])
|
||||||
|
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
url = "https://example.com/ogp"
|
||||||
|
|
||||||
|
{:ok, activity} =
|
||||||
|
CommonAPI.post(user, %{
|
||||||
|
status: "[test](#{url})",
|
||||||
|
content_type: "text/markdown"
|
||||||
|
})
|
||||||
|
|
||||||
|
refute_enqueued(
|
||||||
|
worker: RichMediaWorker,
|
||||||
|
args: %{"url" => url, "activity_id" => activity.id}
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue