Skip to content

Commit

Permalink
Add support for blocklist of filter lists
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gorhill committed Aug 21, 2020
1 parent 57330d9 commit 23f08f0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
8 changes: 8 additions & 0 deletions assets/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 30 additions & 9 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -498,7 +507,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
external: true,
group: 'custom',
submitter: 'user',
title: ''
title: '',
};
newAvailableLists[listKey] = entry;
this.assets.registerAssetSource(listKey, entry);
Expand Down Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -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',
Expand Down

0 comments on commit 23f08f0

Please sign in to comment.