projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tests: chase remote/local removal
[akkoma]
/
lib
/
pleroma
/
web
/
media_proxy
/
controller.ex
diff --git
a/lib/pleroma/web/media_proxy/controller.ex
b/lib/pleroma/web/media_proxy/controller.ex
index 324f752633d62d8b28f877664cdf174186b91f71..c0552d89f4bd98ea09d2ad047ba974c02f8b3846 100644
(file)
--- a/
lib/pleroma/web/media_proxy/controller.ex
+++ b/
lib/pleroma/web/media_proxy/controller.ex
@@
-1,14
+1,20
@@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.MediaProxy.MediaProxyController do
use Pleroma.Web, :controller
defmodule Pleroma.Web.MediaProxy.MediaProxyController do
use Pleroma.Web, :controller
- alias Pleroma.{Web.MediaProxy, ReverseProxy}
+ alias Pleroma.ReverseProxy
+ alias Pleroma.Web.MediaProxy
+
+ @default_proxy_opts [max_body_length: 25 * 1_048_576, http: [follow_redirect: true]]
- def remote(conn,
params = %{"sig" => sig64, "url" => url64}
) do
- with config <- Pleroma.Config.get([:media_proxy]),
+ def remote(conn,
%{"sig" => sig64, "url" => url64} = params
) do
+ with config <- Pleroma.Config.get([:media_proxy]
, []
),
true <- Keyword.get(config, :enabled, false),
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
true <- Keyword.get(config, :enabled, false),
{:ok, url} <- MediaProxy.decode_url(sig64, url64),
- filename <- Path.basename(URI.parse(url).path),
:ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do
:ok <- filename_matches(Map.has_key?(params, "filename"), conn.request_path, url) do
- ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts,
[]
))
+ ReverseProxy.call(conn, url, Keyword.get(config, :proxy_opts,
@default_proxy_opts
))
else
false ->
send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404))
else
false ->
send_resp(conn, 404, Plug.Conn.Status.reason_phrase(404))
@@
-22,11
+28,17
@@
defmodule Pleroma.Web.MediaProxy.MediaProxyController do
end
def filename_matches(has_filename, path, url) do
end
def filename_matches(has_filename, path, url) do
- filename = MediaProxy.filename(url)
+ filename =
+ url
+ |> MediaProxy.filename()
+ |> URI.decode()
- cond do
- has_filename && filename && Path.basename(path) != filename -> {:wrong_filename, filename}
- true -> :ok
+ path = URI.decode(path)
+
+ if has_filename && filename && Path.basename(path) != filename do
+ {:wrong_filename, filename}
+ else
+ :ok
end
end
end
end
end
end