Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Add threat_ip drop reason (#5773)
Cenk Kücüka237dfc76113
diff --git a/lib/plausible/ingestion/event.ex b/lib/plausible/ingestion/event.exindex 2af01f58e1..5f2f7385b8 100644--- a/lib/plausible/ingestion/event.ex+++ b/lib/plausible/ingestion/event.ex@@ -27,6 +27,7 @@ defmodule Plausible.Ingestion.Event do| GateKeeper.policy()| :invalid| :dc_ip+ | :threat_ip| :site_ip_blocklist| :site_country_blocklist| :site_page_blocklist@@ -130,6 +131,7 @@ defmodule Plausible.Ingestion.Event do[drop_verification_agent: &drop_verification_agent/2,drop_datacenter_ip: &drop_datacenter_ip/2,+ drop_threat_ip: &drop_threat_ip/2,drop_shield_rule_hostname: &drop_shield_rule_hostname/2,drop_shield_rule_page: &drop_shield_rule_page/2,drop_shield_rule_ip: &drop_shield_rule_ip/2,@@ -217,6 +219,16 @@ defmodule Plausible.Ingestion.Event doendend+ defp drop_threat_ip(%__MODULE__{} = event, _context) do+ case event.request.ip_classification do+ "threat_ip" ->+ drop(event, :threat_ip)++ _any ->+ event+ end+ end+defp drop_shield_rule_ip(%__MODULE__{} = event, _context) doif Plausible.Shields.ip_blocked?(event.domain, event.request.remote_ip) dodrop(event, :site_ip_blocklist)diff --git a/test/plausible/ingestion/event_test.exs b/test/plausible/ingestion/event_test.exsindex 609b845d7d..e4ced7d96a 100644--- a/test/plausible/ingestion/event_test.exs+++ b/test/plausible/ingestion/event_test.exs@@ -197,6 +197,23 @@ defmodule Plausible.Ingestion.EventTest doassert dropped.drop_reason == :dc_ipend+ test "drops a request when header x-plausible-ip-type is threat_ip" do+ site = new_site()++ payload = %{+ name: "pageview",+ url: "http://dummy.site",+ domain: site.domain+ }++ conn = build_conn(:post, "/api/events", payload)+ conn = Plug.Conn.put_req_header(conn, "x-plausible-ip-type", "threat_ip")+ assert {:ok, request} = Request.build(conn)++ assert {:ok, %{buffered: [], dropped: [dropped]}} = Event.build_and_buffer(request)+ assert dropped.drop_reason == :threat_ip+ end+test "drops a request when ip is on blocklist" dosite = new_site()