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

* Remove Firewall plug; redundant at infra level

* Update changelog
pull/2731/head
Adam 4 years ago committed by GitHub
parent 8b0f0cabc2
commit 4b21b4e6d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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},

@ -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

@ -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

@ -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
Loading…
Cancel
Save