projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
MastoAPI StatusView: Add locality indicator.
[akkoma]
/
lib
/
pleroma
/
web
/
media_proxy
/
media_proxy.ex
diff --git
a/lib/pleroma/web/media_proxy/media_proxy.ex
b/lib/pleroma/web/media_proxy/media_proxy.ex
index 902ab1b7760015770d35c4fc2bec7edf3744789c..39a725a6941c86c61ae69d18657772ad7fb61c43 100644
(file)
--- a/
lib/pleroma/web/media_proxy/media_proxy.ex
+++ b/
lib/pleroma/web/media_proxy/media_proxy.ex
@@
-1,3
+1,7
@@
+# 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 do
@base64_opts [padding: false]
defmodule Pleroma.Web.MediaProxy do
@base64_opts [padding: false]
@@
-5,7
+9,7
@@
defmodule Pleroma.Web.MediaProxy do
def url(""), do: nil
def url(""), do: nil
- def url(
url = "/" <> _
), do: url
+ def url(
"/" <> _ = url
), do: url
def url(url) do
config = Application.get_env(:pleroma, :media_proxy, [])
def url(url) do
config = Application.get_env(:pleroma, :media_proxy, [])
@@
-15,11
+19,16
@@
defmodule Pleroma.Web.MediaProxy do
else
secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
else
secret = Application.get_env(:pleroma, Pleroma.Web.Endpoint)[:secret_key_base]
+ # Must preserve `%2F` for compatibility with S3 (https://git.pleroma.social/pleroma/pleroma/issues/580)
+ replacement = get_replacement(url, ":2F:")
+
# The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice.
base64 =
url
# The URL is url-decoded and encoded again to ensure it is correctly encoded and not twice.
base64 =
url
+ |> String.replace("%2F", replacement)
|> URI.decode()
|> URI.encode()
|> URI.decode()
|> URI.encode()
+ |> String.replace(replacement, "%2F")
|> Base.url_encode64(@base64_opts)
sig = :crypto.hmac(:sha, secret, base64)
|> Base.url_encode64(@base64_opts)
sig = :crypto.hmac(:sha, secret, base64)
@@
-56,4
+65,12
@@
defmodule Pleroma.Web.MediaProxy do
|> Enum.filter(fn value -> value end)
|> Path.join()
end
|> Enum.filter(fn value -> value end)
|> Path.join()
end
+
+ defp get_replacement(url, replacement) do
+ if String.contains?(url, replacement) do
+ get_replacement(url, replacement <> replacement)
+ else
+ replacement
+ end
+ end
end
end