diff options
author | Mark Felder <feld@feld.me> | 2023-05-29 13:59:51 -0400 |
---|---|---|
committer | Mark Felder <feld@feld.me> | 2023-05-29 13:59:51 -0400 |
commit | 843fcca5b4d022e4c088d4a60839b4a286500148 (patch) | |
tree | 95acf70716457a7098537324edf008afb18a1099 /test | |
parent | 506a1c98e716754455387be9ace3ad7aec9c47a3 (diff) | |
download | pleroma-843fcca5b4d022e4c088d4a60839b4a286500148.tar.gz pleroma-843fcca5b4d022e4c088d4a60839b4a286500148.zip |
Validate Host header matches expected value before allowing access to MediaProxy
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/web/media_proxy/media_proxy_controller_test.exs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs index 9ce092fd8..3971330d4 100644 --- a/test/pleroma/web/media_proxy/media_proxy_controller_test.exs +++ b/test/pleroma/web/media_proxy/media_proxy_controller_test.exs @@ -54,6 +54,23 @@ defmodule Pleroma.Web.MediaProxy.MediaProxyControllerTest do } = get(conn, "/proxy/hhgfh/eeee/fff") end + test "it returns a 400 for invalid host", %{conn: conn} do + clear_config([:media_proxy, :base_url], "http://mp.localhost/") + + url = + MediaProxy.encode_url("https://pleroma.social/logo.jpeg") + |> URI.parse() + |> Map.put(:host, "wronghost") + |> URI.to_string() + + with_mock Pleroma.ReverseProxy, + call: fn _conn, _url, _opts -> %Conn{status: :success} end do + %{status: status} = get(conn, url) + + assert status == 400 + end + end + test "redirects to valid url when filename is invalidated", %{conn: conn, url: url} do invalid_url = String.replace(url, "test.png", "test-file.png") response = get(conn, invalid_url) |