From 7d8a18896742f65f2d5d4aeb4383ab7273900b05 Mon Sep 17 00:00:00 2001 From: Phantasm Date: Mon, 27 Oct 2025 18:49:34 +0100 Subject: [PATCH] Disable Hackney URL encoding function Hackney interferes with out URI encoding and implements older RFC 2396 instead of RFC 3986 which we and Elixir implement. As an example "'" and "!" will get encoded by it and cause problems with our MediaProxy making unexpected 302 redirects. If an admin supplies a different function via *.secret.exs, we don't override it. https://github.com/benoitc/hackney/issues/399 --- lib/pleroma/http/adapter_helper/hackney.ex | 5 +++++ lib/pleroma/reverse_proxy/client/hackney.ex | 5 +++++ test/pleroma/reverse_proxy_test.exs | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/http/adapter_helper/hackney.ex b/lib/pleroma/http/adapter_helper/hackney.ex index f3be1f3d0..f3451cf9c 100644 --- a/lib/pleroma/http/adapter_helper/hackney.ex +++ b/lib/pleroma/http/adapter_helper/hackney.ex @@ -16,7 +16,12 @@ defmodule Pleroma.HTTP.AdapterHelper.Hackney do config_opts = Pleroma.Config.get([:http, :adapter], []) + url_encoding = + Keyword.new() + |> Keyword.put(:path_encode_fun, fn path -> path end) + @defaults + |> Keyword.merge(url_encoding) |> Keyword.merge(config_opts) |> Keyword.merge(connection_opts) |> add_scheme_opts(uri) diff --git a/lib/pleroma/reverse_proxy/client/hackney.ex b/lib/pleroma/reverse_proxy/client/hackney.ex index d3e986912..0aa5f5715 100644 --- a/lib/pleroma/reverse_proxy/client/hackney.ex +++ b/lib/pleroma/reverse_proxy/client/hackney.ex @@ -7,6 +7,11 @@ defmodule Pleroma.ReverseProxy.Client.Hackney do @impl true def request(method, url, headers, body, opts \\ []) do + opts = + Keyword.put_new(opts, :path_encode_fun, fn path -> + path + end) + :hackney.request(method, url, headers, body, opts) end diff --git a/test/pleroma/reverse_proxy_test.exs b/test/pleroma/reverse_proxy_test.exs index 3595568cf..8dbe9c6bf 100644 --- a/test/pleroma/reverse_proxy_test.exs +++ b/test/pleroma/reverse_proxy_test.exs @@ -396,7 +396,7 @@ defmodule Pleroma.ReverseProxyTest do end end - # Hackey is used for Reverse Proxy when Hackney or Finch is the Tesla Adapter + # Hackney is used for Reverse Proxy when Hackney or Finch is the Tesla Adapter # Gun is able to proxy through Tesla, so it does not need testing as the # test cases in the Pleroma.HTTPTest module are sufficient describe "Hackney URL encoding:" do