mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2025-01-10 01:26:14 +00:00
Merge pull request 'Only proxy HTTP and HTTP urls via Media Proxy' (#860) from nopjmp/akkoma:media-proxy-only-http into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/860
This commit is contained in:
commit
67cdc38296
|
@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
|
## UNRELEASED
|
||||||
|
|
||||||
|
## Fixed
|
||||||
|
- Media proxy no longer attempts to proxy embedded images
|
||||||
|
|
||||||
## 3.13.3
|
## 3.13.3
|
||||||
|
|
||||||
## BREAKING
|
## BREAKING
|
||||||
|
|
|
@ -52,11 +52,11 @@ defmodule Pleroma.Web.MediaProxy do
|
||||||
|
|
||||||
@spec url_proxiable?(String.t()) :: boolean()
|
@spec url_proxiable?(String.t()) :: boolean()
|
||||||
def url_proxiable?(url) do
|
def url_proxiable?(url) do
|
||||||
not local?(url) and not whitelisted?(url) and not blocked?(url)
|
not local?(url) and not whitelisted?(url) and not blocked?(url) and http_scheme?(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
def preview_url(url, preview_params \\ []) do
|
def preview_url(url, preview_params \\ []) do
|
||||||
if preview_enabled?() do
|
if preview_enabled?() and url_proxiable?(url) do
|
||||||
encode_preview_url(url, preview_params)
|
encode_preview_url(url, preview_params)
|
||||||
else
|
else
|
||||||
url(url)
|
url(url)
|
||||||
|
@ -71,6 +71,8 @@ defmodule Pleroma.Web.MediaProxy do
|
||||||
|
|
||||||
def local?(url), do: String.starts_with?(url, Endpoint.url())
|
def local?(url), do: String.starts_with?(url, Endpoint.url())
|
||||||
|
|
||||||
|
def http_scheme?(url), do: String.starts_with?(url, ["http:", "https:"])
|
||||||
|
|
||||||
def whitelisted?(url) do
|
def whitelisted?(url) do
|
||||||
%{host: domain} = URI.parse(url)
|
%{host: domain} = URI.parse(url)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,10 @@ defmodule Pleroma.Web.MediaProxyTest do
|
||||||
assert MediaProxy.url(local_root) == local_root
|
assert MediaProxy.url(local_root) == local_root
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "ignores data url" do
|
||||||
|
assert MediaProxy.url("data:image/png;base64,") == "data:image/png;base64,"
|
||||||
|
end
|
||||||
|
|
||||||
test "encodes and decodes URL" do
|
test "encodes and decodes URL" do
|
||||||
url = "https://pleroma.soykaf.com/static/logo.png"
|
url = "https://pleroma.soykaf.com/static/logo.png"
|
||||||
encoded = MediaProxy.url(url)
|
encoded = MediaProxy.url(url)
|
||||||
|
|
Loading…
Reference in a new issue