projects
/
akkoma
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
241f7cb
)
Add helper function to convert single IPs into CIDR format if they were not provided...
author
Mark Felder
<feld@FreeBSD.org>
Mon, 5 Oct 2020 16:48:41 +0000
(11:48 -0500)
committer
Mark Felder
<feld@FreeBSD.org>
Mon, 5 Oct 2020 16:49:56 +0000
(11:49 -0500)
lib/pleroma/plugs/remote_ip.ex
patch
|
blob
|
history
diff --git
a/lib/pleroma/plugs/remote_ip.ex
b/lib/pleroma/plugs/remote_ip.ex
index 0ac9050d0764149e2361811016179f1282b20c82..d1b1f793ac8c6a66bf86621c53b7f8656c2fc09c 100644
(file)
--- 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