logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 35ee759e74d0737598311d8e4245168f981812d3
parent 241f7cb1ed91a8d6855dbd03517e85c98c08edb7
Author: Mark Felder <feld@FreeBSD.org>
Date:   Mon,  5 Oct 2020 11:48:41 -0500

Add helper function to convert single IPs into CIDR format if they were not provided that way

Diffstat:

Mlib/pleroma/plugs/remote_ip.ex13++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lib/pleroma/plugs/remote_ip.ex b/lib/pleroma/plugs/remote_ip.ex @@ -47,8 +47,19 @@ defmodule Pleroma.Plugs.RemoteIp do config |> Keyword.get(:proxies, []) |> Enum.concat(reserved) - |> Enum.map(&InetCidr.parse/1) + |> Enum.map(&maybe_add_cidr/1) {headers, proxies} end + + defp maybe_add_cidr(proxy) when is_binary(proxy) do + proxy = + cond do + "/" in String.codepoints(proxy) -> proxy + InetCidr.v4?(InetCidr.parse_address!(proxy)) -> proxy <> "/32" + InetCidr.v6?(InetCidr.parse_address!(proxy)) -> proxy <> "/128" + end + + InetCidr.parse(proxy) + end end