Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Fix configuration for firewall

Uku Taht74b74a271e99
diff --git a/config/config.exs b/config/config.exs
index a668be1133..afc21c649a 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 89a9b99d3c..c750b514bd 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 2e6cfc724c..24b449a821 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