try to always match the filename for proxy url

This commit is contained in:
Sachin Joshi 2019-07-12 22:19:30 +05:45
parent b6567c9f4e
commit f8e3ae6154
2 changed files with 17 additions and 1 deletions

View file

@ -30,10 +30,15 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
def filename_matches(has_filename, path, url) do def filename_matches(has_filename, path, url) do
filename = url |> MediaProxy.filename() filename = url |> MediaProxy.filename()
if has_filename && filename && Path.basename(path) != filename do if has_filename && filename && does_not_match(path, filename) do
{:wrong_filename, filename} {:wrong_filename, filename}
else else
:ok :ok
end end
end end
defp does_not_match(path, filename) do
basename = Path.basename(path)
basename != filename and URI.decode(basename) != filename and URI.encode(basename) != filename
end
end end

View file

@ -108,6 +108,17 @@ defmodule Pleroma.MediaProxyTest do
) == :ok ) == :ok
end end
test "encoded url are tried to match for proxy as `conn.request_path` encodes the url" do
# conn.request_path will return encoded url
request_path = "/ANALYSE-DAI-_-LE-STABLECOIN-100-D%C3%89CENTRALIS%C3%89-BQ.jpg"
assert MediaProxyController.filename_matches(
true,
request_path,
"https://mydomain.com/uploads/2019/07/ANALYSE-DAI-_-LE-STABLECOIN-100-DÉCENTRALISÉ-BQ.jpg"
) == :ok
end
test "uses the configured base_url" do test "uses the configured base_url" do
base_url = Pleroma.Config.get([:media_proxy, :base_url]) base_url = Pleroma.Config.get([:media_proxy, :base_url])