From 23f08f027460b5d0c0436357f866d6c48b8df701 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 21 Aug 2020 11:57:20 -0400 Subject: [PATCH] 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. --- assets/assets.json | 8 ++++++++ src/js/background.js | 1 + src/js/storage.js | 39 ++++++++++++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/assets/assets.json b/assets/assets.json index fff3902ad..d7f137827 100644 --- a/assets/assets.json +++ b/assets/assets.json @@ -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", diff --git a/src/js/background.js b/src/js/background.js index 158bad813..73a0bcb6d 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -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. diff --git a/src/js/storage.js b/src/js/storage.js index c47db98ab..a13e47930 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -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',