Add support for blocklist of filter lists

Many filter lists are known to cause serious filtering
issues in uBO and are not meant to be used in uBO.

Unfortunately, unwitting users keep importing these
filter lists and as a result this ends up causing
filtering issues for which the resolution is always
to remove the incompatible filter list.

Example of inconpatible filter lists:
- Reek's Anti-Adblock Killer
- AdBlock Warning Removal List
- ABP anti-circumvention filter list

uBO will use the following resource to know
which filter lists are incompatible:
- https://github.com/uBlockOrigin/uAssets/blob/master/filters/badlists.txt

Incompatible filter lists can still be imported into
uBO, useful for asset-viewing purpose, but their content
will be discarded at compile time.
This commit is contained in:
Raymond Hill 2020-08-21 11:57:20 -04:00
parent 57330d9c5d
commit 23f08f0274
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
3 changed files with 39 additions and 9 deletions

View file

@ -16,6 +16,14 @@
"assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat"
]
},
"ublock-badlists": {
"content": "internal",
"updateAfter": 13,
"contentURL": [
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badlists.txt",
"assets/ublock/badlists.txt"
]
},
"ublock-filters": {
"content": "filters",
"group": "default",

View file

@ -171,6 +171,7 @@ const µBlock = (( ) => { // jshint ignore:line
selectedFilterLists: [],
availableFilterLists: {},
badLists: new Set(),
// https://github.com/uBlockOrigin/uBlock-issues/issues/974
// This can be used to defer filtering decision-making.

View file

@ -481,6 +481,15 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
let oldAvailableLists = {},
newAvailableLists = {};
if ( this.badLists.size === 0 ) {
const details = await this.assets.get('ublock-badlists');
this.badLists = new Set(
details.content.split(/\s*[\n\r]+\s*/).filter(a => {
return a !== '' && a.startsWith('#') === false;
})
);
}
// User filter list.
newAvailableLists[this.userFiltersPath] = {
group: 'user',
@ -498,7 +507,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
external: true,
group: 'custom',
submitter: 'user',
title: ''
title: '',
};
newAvailableLists[listKey] = entry;
this.assets.registerAssetSource(listKey, entry);
@ -705,7 +714,10 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
µBlock.getCompiledFilterList = async function(assetKey) {
const compiledPath = 'compiled/' + assetKey;
if ( this.compiledFormatChanged === false ) {
if (
this.compiledFormatChanged === false &&
this.badLists.has(assetKey) === false
) {
let compiledDetails = await this.assets.get(compiledPath);
if ( compiledDetails.content !== '' ) {
compiledDetails.assetKey = assetKey;
@ -722,6 +734,11 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
this.extractFilterListMetadata(assetKey, rawDetails.content);
// Skip compiling bad lists.
if ( this.badLists.has(assetKey) ) {
return { assetKey, content: '' };
}
// Fetching the raw content may cause the compiled content to be
// generated somewhere else in uBO, hence we try one last time to
// fetch the compiled content in case it has become available.
@ -1339,13 +1356,15 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
details.assetKey,
details.content
);
this.assets.put(
'compiled/' + details.assetKey,
this.compileFilters(
details.content,
{ assetKey: details.assetKey }
)
);
if ( this.badLists.has(details.assetKey) === false ) {
this.assets.put(
'compiled/' + details.assetKey,
this.compileFilters(
details.content,
{ assetKey: details.assetKey }
)
);
}
}
} else {
this.removeCompiledFilterList(details.assetKey);
@ -1354,6 +1373,8 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
if ( cached ) {
this.compilePublicSuffixList(details.content);
}
} else if ( details.assetKey === 'ublock-badlists' ) {
this.badLists = new Set();
}
vAPI.messaging.broadcast({
what: 'assetUpdated',