diff options
author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2023-12-16 18:56:46 +0100 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2023-12-16 19:25:51 +0100 |
commit | 086ba59d0346be870dc7df2660fbb55666bf0af7 (patch) | |
tree | f3989b2ef5334f578759c44cb1e1500440b854c1 /lib | |
parent | f271ea6e432d685c113582e5944d79e12c153016 (diff) | |
download | pleroma-086ba59d0346be870dc7df2660fbb55666bf0af7.tar.gz pleroma-086ba59d0346be870dc7df2660fbb55666bf0af7.zip |
HTTPSignaturePlug: Add :authorized_fetch_mode_exceptions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/plugs/http_signature_plug.ex | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/pleroma/web/plugs/http_signature_plug.ex b/lib/pleroma/web/plugs/http_signature_plug.ex index e814efc2c..7ec202662 100644 --- a/lib/pleroma/web/plugs/http_signature_plug.ex +++ b/lib/pleroma/web/plugs/http_signature_plug.ex @@ -3,6 +3,8 @@ # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do + alias Pleroma.Helpers.InetHelper + import Plug.Conn import Phoenix.Controller, only: [get_format: 1, text: 2] require Logger @@ -89,12 +91,20 @@ defmodule Pleroma.Web.Plugs.HTTPSignaturePlug do defp maybe_require_signature(%{assigns: %{valid_signature: true}} = conn), do: conn - defp maybe_require_signature(conn) do + defp maybe_require_signature(%{remote_ip: remote_ip} = conn) do if Pleroma.Config.get([:activitypub, :authorized_fetch_mode], false) do - conn - |> put_status(:unauthorized) - |> text("Request not signed") - |> halt() + exceptions = + Pleroma.Config.get([:activitypub, :authorized_fetch_mode_exceptions], []) + |> Enum.map(&InetHelper.parse_cidr/1) + + if Enum.any?(exceptions, fn x -> InetCidr.contains?(x, remote_ip) end) do + conn + else + conn + |> put_status(:unauthorized) + |> text("Request not signed") + |> halt() + end else conn end |