try to always match the filename for proxy url
authorSachin Joshi <satchin.joshi@gmail.com>
Fri, 12 Jul 2019 16:34:30 +0000 (22:19 +0545)
committerSachin Joshi <satchin.joshi@gmail.com>
Fri, 12 Jul 2019 17:11:14 +0000 (22:56 +0545)
lib/pleroma/web/media_proxy/controller.ex
test/media_proxy_test.exs

index ea33d7685752fd05edcc64c5e91e556a088e97c0..a711b54e944633c4032a10c6bd5dc6d1abf777e3 100644 (file)
@@ -30,10 +30,15 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
   def filename_matches(has_filename, path, url) do
     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}
     else
       :ok
     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
index fbf2009310382a3f4cd70da33b0b5166006689a2..176b099148889dd707171b73135632e0c3cd797e 100644 (file)
@@ -108,6 +108,17 @@ defmodule Pleroma.MediaProxyTest do
              ) == :ok
     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
       base_url = Pleroma.Config.get([:media_proxy, :base_url])