From 6a6c4d134b7564012d00e89f1236b904261ab5db Mon Sep 17 00:00:00 2001 From: Sachin Joshi Date: Fri, 12 Jul 2019 21:02:55 +0545 Subject: [PATCH] preserve the original path/filename (no encoding/decoding) for proxy --- lib/pleroma/web/media_proxy/controller.ex | 7 +------ test/media_proxy_test.exs | 16 ++++------------ 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex index c0552d89f..ea33d7685 100644 --- a/lib/pleroma/web/media_proxy/controller.ex +++ b/lib/pleroma/web/media_proxy/controller.ex @@ -28,12 +28,7 @@ def remote(conn, %{"sig" => sig64, "url" => url64} = params) do end def filename_matches(has_filename, path, url) do - filename = - url - |> MediaProxy.filename() - |> URI.decode() - - path = URI.decode(path) + filename = url |> MediaProxy.filename() if has_filename && filename && Path.basename(path) != filename do {:wrong_filename, filename} diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs index 1d6d170b7..fbf200931 100644 --- a/test/media_proxy_test.exs +++ b/test/media_proxy_test.exs @@ -88,10 +88,10 @@ test "validates signature" do assert decode_url(sig, base64) == {:error, :invalid_signature} end - test "filename_matches matches url encoded paths" do + test "filename_matches preserves the encoded or decoded path" do assert MediaProxyController.filename_matches( true, - "/Hello%20world.jpg", + "/Hello world.jpg", "http://pleroma.social/Hello world.jpg" ) == :ok @@ -100,19 +100,11 @@ test "filename_matches matches url encoded paths" do "/Hello%20world.jpg", "http://pleroma.social/Hello%20world.jpg" ) == :ok - end - - test "filename_matches matches non-url encoded paths" do - assert MediaProxyController.filename_matches( - true, - "/Hello world.jpg", - "http://pleroma.social/Hello%20world.jpg" - ) == :ok assert MediaProxyController.filename_matches( true, - "/Hello world.jpg", - "http://pleroma.social/Hello world.jpg" + "/my%2Flong%2Furl%2F2019%2F07%2FS.jpg", + "http://pleroma.social/my%2Flong%2Furl%2F2019%2F07%2FS.jpg" ) == :ok end