Skip to content

Commit

Permalink
Improve domain matching to reduce false positives (browserpass#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximbaz authored Sep 26, 2019
1 parent 913af66 commit 2d1b19b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 2d1b19b

Please sign in to comment.