Skip to content

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

Remove Firewall plug; redundant at infra level (#2730)

Adam4b21b4e6d04a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cd29b4264d..763b288b3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,7 @@ All notable changes to this project will be documented in this file.
- Device type is now determined from the User-Agent instead of window.innerWidth plausible/analytics#2711
### Removed
+- Remove Firewall plug and `IP_BLOCKLIST` environment variable
- Remove the ability to collapse the main graph plausible/analytics#2627
## v1.5.1 - 2022-12-06
diff --git a/config/runtime.exs b/config/runtime.exs
index bbbb8d3ee7..5cc3882baa 100644
--- a/config/runtime.exs
+++ b/config/runtime.exs
@@ -356,12 +356,6 @@ case mailer_adapter do
"""
end
-config :plausible, PlausibleWeb.Firewall,
- blocklist:
- get_var_from_path_or_env(config_dir, "IP_BLOCKLIST", "")
- |> String.split(",")
- |> Enum.map(&String.trim/1)
-
base_cron = [
# Daily at midnight
{"0 0 * * *", Plausible.Workers.RotateSalts},
diff --git a/lib/plausible_web/plugs/firewall.ex b/lib/plausible_web/plugs/firewall.ex
deleted file mode 100644
index 266a109283..0000000000
--- a/lib/plausible_web/plugs/firewall.ex
+++ /dev/null
@@ -1,17 +0,0 @@
-defmodule PlausibleWeb.Firewall do
- import Plug.Conn
-
- def init(opts) do
- opts
- end
-
- 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
- end
- end
-end
diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex
index fa9839e869..cd7e66e776 100644
--- a/lib/plausible_web/router.ex
+++ b/lib/plausible_web/router.ex
@@ -4,7 +4,6 @@ defmodule PlausibleWeb.Router do
pipeline :browser do
plug :accepts, ["html"]
- plug PlausibleWeb.Firewall
plug :fetch_session
plug :fetch_flash
plug :put_secure_browser_headers
@@ -25,21 +24,18 @@ defmodule PlausibleWeb.Router do
pipeline :api do
plug :accepts, ["json"]
- plug PlausibleWeb.Firewall
plug :fetch_session
plug PlausibleWeb.AuthPlug
end
pipeline :internal_stats_api do
plug :accepts, ["json"]
- plug PlausibleWeb.Firewall
plug :fetch_session
plug PlausibleWeb.AuthorizeSiteAccess
end
pipeline :public_api do
plug :accepts, ["json"]
- plug PlausibleWeb.Firewall
end
pipeline :flags do
diff --git a/test/plausible_web/plugs/firewall_test.exs b/test/plausible_web/plugs/firewall_test.exs
deleted file mode 100644
index ef73547eb0..0000000000
--- a/test/plausible_web/plugs/firewall_test.exs
+++ /dev/null
@@ -1,29 +0,0 @@
-defmodule PlausibleWeb.FirewallTest do
- use Plausible.DataCase
- use Plug.Test
- alias PlausibleWeb.Firewall
-
- @allowed_ip "127.0.0.1"
- @blocked_ip "127.0.0.2"
- @opts [blocklist: [@blocked_ip]]
-
- setup_patch_env(PlausibleWeb.Firewall, blocklist: [@blocked_ip])
-
- test "ignores request if IP is allowed" do
- conn =
- conn(:get, "/")
- |> put_req_header("x-forwarded-for", @allowed_ip)
- |> Firewall.call(@opts)
-
- assert conn.status == nil
- end
-
- test "responds with 404 if IP is blocked" do
- conn =
- conn(:get, "/")
- |> put_req_header("x-forwarded-for", @blocked_ip)
- |> Firewall.call(@opts)
-
- assert conn.status == 404
- end
-end