From 14302e9362b7be7ded6159249e65097f5b19b5b6 Mon Sep 17 00:00:00 2001 From: Maxim Baz Date: Thu, 26 Sep 2019 23:22:20 +0200 Subject: [PATCH] Improve domain matching to reduce false positives (#172) --- src/helpers.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/helpers.js b/src/helpers.js index 05dd43a..2a6d265 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -31,11 +31,15 @@ function pathToDomain(path, currentHost) { continue; } var t = TldJS.parse(parts[key]); + + // Part is considered to be a domain component in one of the following cases: + // - it is a valid domain with well-known TLD (github.com, login.github.com) + // - it is a valid domain with unknown TLD but the current host is it's subdomain (login.pi.hole) + // - it is or isnt a valid domain but the current host matches it EXACTLY (localhost, pi.hole) if ( t.isValid && - ((t.tldExists && t.domain !== null) || - t.hostname === currentHost || - currentHost.endsWith(`.${t.hostname}`)) + ((t.domain !== null && (t.tldExists || currentHost.endsWith(`.${t.hostname}`))) || + currentHost === t.hostname) ) { return t.hostname; }