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
Fix fetch options (#6789)
Artur Pata0d3dbbfc242a
diff --git a/lib/plausible/ssrf.ex b/lib/plausible/ssrf.exindex a0585879bf..1bc14353dc 100644--- a/lib/plausible/ssrf.ex+++ b/lib/plausible/ssrf.ex@@ -15,10 +15,10 @@ defmodule Plausible.SSRF do@default_max_redirects 4@dns_timeout 1_000- # Every distinct `connect_options: [hostname: ...]` value we pass below+ # Every distinct `finch: [conn_opts: [hostname: ...]]` value we pass below# makes Req start a brand new, dedicated Finch instance under the hood# (Req can't vary `conn_opts` per-request on a shared pool, so it forks one- # per connect_options fingerprint) - and since these hostnames are+ # per pool options fingerprint) - and since these hostnames are# customer-controlled, that's an unbounded number of them over time.@default_pool_max_idle_time :timer.minutes(5)@@ -76,13 +76,11 @@ defmodule Plausible.SSRF dopinned_url = %{uri | host: ip |> :inet.ntoa() |> to_string()}request_opts =- opts- |> Keyword.put_new(:pool_max_idle_time, @default_pool_max_idle_time)- |> Keyword.merge(+ Keyword.merge(opts,method: :get,url: pinned_url,headers: [{"host", host}],- connect_options: [hostname: host],+ finch: [pool_max_idle_time: @default_pool_max_idle_time, conn_opts: [hostname: host]],redirect: false)diff --git a/test/plausible/ssrf_test.exs b/test/plausible/ssrf_test.exsindex e86fa8c6b8..412531dc99 100644--- a/test/plausible/ssrf_test.exs+++ b/test/plausible/ssrf_test.exs@@ -161,7 +161,7 @@ defmodule Plausible.SSRFTest dodescribe "pool_max_idle_time" dotest "an idle Finch pool is reaped after pool_max_idle_time, instead of lingering forever" do- # This exercises the same connect_options/pool_max_idle_time shape+ # This exercises the same finch pool options shape# SSRF.do_request/3 builds, via a real Finch pool - it can't be driven# through SSRF.get/2 itself because the only network target reachable# from a test is loopback, which SSRF.resolve_host/1 correctly (and@@ -188,8 +188,7 @@ defmodule Plausible.SSRFTest doReq.request(method: :get,url: "http://localhost:#{bypass.port}/",- connect_options: [hostname: "localhost"],- pool_max_idle_time: 50+ finch: [conn_opts: [hostname: "localhost"], pool_max_idle_time: 50])assert_receive :pool_reaped, 2000