summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSachin Joshi <satchin.joshi@gmail.com>2019-07-12 22:19:30 +0545
committerAriadne Conill <ariadne@dereferenced.org>2019-07-28 22:36:42 +0000
commitccafecf9be46bc11e3080d531146d05e18f493d4 (patch)
tree837015cc798780dc9cde262a63c6d59b86bee0da
parent9e88ab2cad3684bc9740171fa525c78d3a7d37b8 (diff)
try to always match the filename for proxy url
-rw-r--r--lib/pleroma/web/media_proxy/controller.ex7
-rw-r--r--test/media_proxy_test.exs11
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/pleroma/web/media_proxy/controller.ex b/lib/pleroma/web/media_proxy/controller.ex
index c0552d89f..f7772e9b0 100644
--- a/lib/pleroma/web/media_proxy/controller.ex
+++ b/lib/pleroma/web/media_proxy/controller.ex
@@ -35,10 +35,15 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyController do
path = URI.decode(path)
- 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
diff --git a/test/media_proxy_test.exs b/test/media_proxy_test.exs
index b23aeb88b..9c363dea8 100644
--- a/test/media_proxy_test.exs
+++ b/test/media_proxy_test.exs
@@ -124,6 +124,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])