From 0997a9dc66d877fcac191cc84700d2f20660e106 Mon Sep 17 00:00:00 2001 From: Joost de Valk Date: Tue, 15 Sep 2026 16:59:51 +0200 Subject: [PATCH] Use a shared validated client IP for exclusions and settings --- README.md | 8 +++++ simple-analytics.php | 1 + src/Settings/Blocks/Fields/IpList.php | 5 ++- src/Support/IpAddress.php | 22 +++++++++++++ src/TrackingRules.php | 8 +++-- tests/Browser/phpRegression.spec.ts | 16 ++++++++++ tests/Regression/client-ip.php | 45 +++++++++++++++++++++++++++ tests/Support/isolated-options.php | 39 +++++++++++++++++++++++ 8 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 src/Support/IpAddress.php create mode 100644 tests/Browser/phpRegression.spec.ts create mode 100644 tests/Regression/client-ip.php create mode 100644 tests/Support/isolated-options.php diff --git a/README.md b/README.md index e0b072d..f0c7930 100644 --- a/README.md +++ b/README.md @@ -10,5 +10,13 @@ You need a Simple Analytics account. Start with the [free plan](https://www.simp ## Resources +### Client IP addresses behind a proxy + +IP exclusions and **Add Current IP** both use the validated `REMOTE_ADDR` supplied by your web server. Forwarded headers are no longer trusted automatically. Configure your server's trusted proxy handling to populate the visitor's address in `REMOTE_ADDR`. + +If your deployment needs a different resolver, the `simpleanalytics_client_ip` filter receives that address (or `null` when unavailable). Return one visitor IP only after validating the connecting proxy and its headers. The plugin validates and normalizes the returned IPv4 or IPv6 address and uses it consistently for tracking and the settings UI. Never pass an untrusted `X-Forwarded-For` header directly through this filter. + +### Links + - [WordPress plugin page](https://wordpress.org/plugins/simpleanalytics/) - [Create a Simple Analytics account](https://www.simpleanalytics.com/signup) diff --git a/simple-analytics.php b/simple-analytics.php index 3c253cd..97813a0 100644 --- a/simple-analytics.php +++ b/simple-analytics.php @@ -29,6 +29,7 @@ * @note Manual loading rather than Composer to avoid potential conflict with plugins/themes that ship older autoloader. */ require __DIR__ . '/src/Support/SvgIcon.php'; +require __DIR__ . '/src/Support/IpAddress.php'; require __DIR__ . '/helpers.php'; require __DIR__ . '/src/Plugin.php'; require __DIR__ . '/src/WordPressHooks.php'; diff --git a/src/Settings/Blocks/Fields/IpList.php b/src/Settings/Blocks/Fields/IpList.php index cc671d8..fab461f 100644 --- a/src/Settings/Blocks/Fields/IpList.php +++ b/src/Settings/Blocks/Fields/IpList.php @@ -3,6 +3,7 @@ namespace SimpleAnalytics\Settings\Blocks\Fields; use SimpleAnalytics\Setting; +use SimpleAnalytics\Support\IpAddress; use SimpleAnalytics\Settings\Concerns\HasDocs; use SimpleAnalytics\Settings\Concerns\HasPlaceholder; use SimpleAnalytics\UI\LabelComponent; @@ -38,7 +39,7 @@ public function getValueType(): string public function render(): void { $value = implode("\n", Setting::array($this->getKey())); - $currentIp = $_SERVER['REMOTE_ADDR']; + $currentIp = IpAddress::current(); ?> +