MediaProxy: Fix 424 caused by inconsistent %-encoding from remote instances

Notably this would fail to redirect to original proxied file when
preview generation criteria haven't been met.
This commit is contained in:
Phantasm 2025-09-23 22:55:54 +02:00
commit 004ea90b29
No known key found for this signature in database
GPG key ID: 2669E588BCC634C8

View file

@ -5,6 +5,7 @@
defmodule Pleroma.Web.MediaProxy do
alias Pleroma.Config
alias Pleroma.Helpers.UriHelper
alias Pleroma.HTTP
alias Pleroma.Upload
alias Pleroma.Web.Endpoint
alias Pleroma.Web.MediaProxy.Invalidation
@ -99,13 +100,20 @@ defmodule Pleroma.Web.MediaProxy do
{base64, sig64}
end
# The URL coming into MediaProxy from the outside might have wrong %-encoding
# (like older Pleroma versions)
# This would cause an inconsistency with the encoded URL here and the requested
# URL fixed with Pleroma.Tesla.Middleware.EncodeUrl.
# End result is a failing HEAD request in Pleroma.Web.MediaProxy.MediaProxyController.handle_preview/2
def encode_url(url) do
url = HTTP.encode_url(url)
{base64, sig64} = base64_sig64(url)
build_url(sig64, base64, filename(url))
end
def encode_preview_url(url, preview_params \\ []) do
url = HTTP.encode_url(url)
{base64, sig64} = base64_sig64(url)
build_preview_url(sig64, base64, filename(url), preview_params)