diff --git a/config/config.exs b/config/config.exs index a668be113..afc21c649 100644 --- a/config/config.exs +++ b/config/config.exs @@ -182,7 +182,7 @@ config :plausible, :custom_domain_server, ip: System.get_env("CUSTOM_DOMAIN_SERVER_IP") config :plausible, PlausibleWeb.Firewall, - blocklist: System.get_env("IP_BLOCKLIST", "") + blocklist: System.get_env("IP_BLOCKLIST", "") |> String.split(",") |> Enum.map(&String.trim/1) config :geolix, databases: [ diff --git a/config/releases.exs b/config/releases.exs index 89a9b99d3..c750b514b 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -148,7 +148,7 @@ config :plausible, :custom_domain_server, ip: custom_domain_server_ip config :plausible, PlausibleWeb.Firewall, - blocklist: System.get_env("IP_BLOCKLIST", "") + blocklist: System.get_env("IP_BLOCKLIST", "") |> String.split(",") |> Enum.map(&String.trim/1) base_cron = [ # Daily at midnight diff --git a/lib/plausible_web/plugs/firewall.ex b/lib/plausible_web/plugs/firewall.ex index 2e6cfc724..24b449a82 100644 --- a/lib/plausible_web/plugs/firewall.ex +++ b/lib/plausible_web/plugs/firewall.ex @@ -1,16 +1,13 @@ defmodule PlausibleWeb.Firewall do import Plug.Conn - def init(options) do - blocklist = Keyword.fetch!(Application.get_env(:plausible, __MODULE__), :blocklist) - |> String.split(",") - |> Enum.map(&String.trim/1) - - Keyword.merge(options, blocklist: blocklist) + def init(opts) do + opts end - def call(conn, opts) do - if PlausibleWeb.RemoteIp.get(conn) in opts[:blocklist] do + def call(conn, _opts) do + blocklist = Keyword.fetch!(Application.get_env(:plausible, __MODULE__), :blocklist) + if PlausibleWeb.RemoteIp.get(conn) in blocklist do send_resp(conn, 404, "Not found") |> halt else conn