From f5b412b4c8abe993a855c2b9bbfc2d14a1ee3165 Mon Sep 17 00:00:00 2001 From: Martin Packman Date: Thu, 22 Jul 2021 06:23:05 +0100 Subject: [PATCH] Fix IPv6 localhost detection in tracker script (#1200) IPv6 literals in url hostnames follow RFC 2732 so are enclosed in brackets. Browsers normalise so matching zeros is not required. Allow `::` unspecified address as well as `::1` loopback address. Non-capturing groups not required when using `/.../.test()` method. --- tracker/src/plausible.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js index 7c7d960fd..f1a58cb92 100644 --- a/tracker/src/plausible.js +++ b/tracker/src/plausible.js @@ -33,7 +33,7 @@ function trigger(eventName, options) { - if (/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(location.hostname) || location.protocol === 'file:') return warn('localhost'); + if (/^localhost$|^127(\.[0-9]+){0,2}\.[0-9]+$|^\[::1?\]$/.test(location.hostname) || location.protocol === 'file:') return warn('localhost'); if (window.phantom || window._phantom || window.__nightmare || window.navigator.webdriver || window.Cypress) return; if (plausible_ignore=="true") return warn('localStorage flag') {{#if exclusions}}