Remove vapidPublicKey from Nodeinfo
[akkoma] / lib / pleroma / plugs / remote_ip.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Plugs.RemoteIp do
6 @moduledoc """
7 This is a shim to call [`RemoteIp`](https://git.pleroma.social/pleroma/remote_ip) but with runtime configuration.
8 """
9
10 import Plug.Conn
11
12 @behaviour Plug
13
14 @headers ~w[
15 x-forwarded-for
16 ]
17
18 # https://en.wikipedia.org/wiki/Localhost
19 # https://en.wikipedia.org/wiki/Private_network
20 @reserved ~w[
21 127.0.0.0/8
22 ::1/128
23 fc00::/7
24 10.0.0.0/8
25 172.16.0.0/12
26 192.168.0.0/16
27 ]
28
29 def init(_), do: nil
30
31 def call(%{remote_ip: original_remote_ip} = conn, _) do
32 config = Pleroma.Config.get(__MODULE__, [])
33
34 if Keyword.get(config, :enabled, false) do
35 %{remote_ip: new_remote_ip} = conn = RemoteIp.call(conn, remote_ip_opts(config))
36 assign(conn, :remote_ip_found, original_remote_ip != new_remote_ip)
37 else
38 conn
39 end
40 end
41
42 defp remote_ip_opts(config) do
43 headers = config |> Keyword.get(:headers, @headers) |> MapSet.new()
44 reserved = Keyword.get(config, :reserved, @reserved)
45
46 proxies =
47 config
48 |> Keyword.get(:proxies, [])
49 |> Enum.concat(reserved)
50 |> Enum.map(&InetCidr.parse/1)
51
52 {headers, proxies}
53 end
54 end