From cbc3c239f21c4d68d5ce044e6dd0734edcea83c3 Mon Sep 17 00:00:00 2001 From: hackademix Date: Thu, 21 Nov 2024 01:25:29 +0100 Subject: [PATCH] Fixes naked domains with no HTTPS lock and explicit port numbers not correctly matched in mapped MV3 DNR rules (issue #387). --- src/bg/DNRPolicy.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bg/DNRPolicy.js b/src/bg/DNRPolicy.js index d153bde..86eba32 100644 --- a/src/bg/DNRPolicy.js +++ b/src/bg/DNRPolicy.js @@ -70,9 +70,14 @@ } function toUrlFilter(siteKey) { - let urlFilter = `|${siteKey.replace(/^ยง:/, '|')}`; - if (!urlFilter.replace(/^\w+:\/+/).includes("/")) { - urlFilter += "/"; + // Note: using '^' instead of '/' as a terminator + // takes explicit port numbers in account + if (Sites.isSecureDomainKey(siteKey)) { + return `||${Sites.toggleSecureDomainKey(siteKey,false)}^` + } + let urlFilter = `||${siteKey}`; + if (!urlFilter.replace(/^[\w-]+:\/+/, "").includes("/")) { + urlFilter += '^'; } return urlFilter; } @@ -93,8 +98,8 @@ if (!policy || policy.equals(_lastPolicy)) { return await updateTabs(); } - _lastPolicy = policy; } + _lastPolicy = policy; const Rules = { // Using capitalized keys to allow DRY tricks with get/update methods