[mv3] Fix flaw breaking scriptlets injection in optimal/basic mode

Not all matching scriptlets were injected on a given site in Optimal
or Complete mode when default mode was set to Basic or less.

A high profile manifestation of this bug was that Youtube ads were
not being blocked when using Optimal on Youtube while default mode
was Basic.
This commit is contained in:
Raymond Hill 2024-11-20 09:04:52 -05:00
parent 8ae33afb76
commit 6355a17187
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 16 additions and 2 deletions

View File

@ -450,8 +450,8 @@ function registerScriptlet(context, scriptletDetails) {
targetHostnames = permissionGrantedHostnames;
} else {
targetHostnames = ut.intersectHostnameIters(
permissionGrantedHostnames,
scriptletHostnames
scriptletHostnames,
permissionGrantedHostnames
);
}
}

View File

@ -47,6 +47,13 @@ const isDescendantHostname = (hna, hnb) => {
return hna.charCodeAt(hna.length - hnb.length - 1) === 0x2E /* '.' */;
};
/**
* Returns whether a hostname is part of a collection, or is descendant of an
* item in the collection.
* @param hna - the hostname representing the needle.
* @param iterb - an iterable representing the haystack of hostnames.
*/
const isDescendantHostnameOfIter = (hna, iterb) => {
const setb = iterb instanceof Set ? iterb : new Set(iterb);
if ( setb.has('all-urls') || setb.has('*') ) { return true; }
@ -60,6 +67,13 @@ const isDescendantHostnameOfIter = (hna, iterb) => {
return false;
};
/**
* Returns all hostnames in the first collection which are equal or descendant
* of hostnames in the second collection.
* @param itera - an iterable which hostnames must be filtered out.
* @param iterb - an iterable which hostnames must be matched.
*/
const intersectHostnameIters = (itera, iterb) => {
const setb = iterb instanceof Set ? iterb : new Set(iterb);
if ( setb.has('all-urls') || setb.has('*') ) { return Array.from(itera); }