fix(media_proxy): do not proxy data: URLs

Ported from Akkoma 7632765b4.

Co-authored-by: nopjmp <nop@unearthly.dev>
This commit is contained in:
Lain Soykaf 2026-10-31 15:37:42 +04:00
commit 542f8b2aef
No known key found for this signature in database
3 changed files with 17 additions and 2 deletions

View file

@ -45,7 +45,7 @@ defmodule Pleroma.Web.MediaProxy do
def url("/" <> _ = url), do: url
def url(url) do
if enabled?() and url_proxiable?(url) do
if enabled?() and not data_url?(url) and url_proxiable?(url) do
encode_url(url)
else
url
@ -61,7 +61,7 @@ defmodule Pleroma.Web.MediaProxy do
def preview_url("//" <> _ = url, pparams), do: preview_url("https:" <> url, pparams)
def preview_url(url, preview_params) do
if preview_enabled?() do
if preview_enabled?() and not data_url?(url) do
encode_preview_url(url, preview_params)
else
url(url)
@ -74,6 +74,8 @@ defmodule Pleroma.Web.MediaProxy do
# non-local non-whitelisted URLs through it and be sure that body size constraint is preserved.
def preview_enabled?, do: enabled?() and !!Config.get([:media_preview_proxy, :enabled])
defp data_url?(url), do: url |> String.slice(0, 5) |> String.downcase() == "data:"
def local?(url), do: String.starts_with?(url, Endpoint.url())
def whitelisted?(url) do