Skip to content

Commit

Permalink
Add concept of "really bad list" to badlists infrastructure
Browse files Browse the repository at this point in the history
This commit adds concept of "really bad list" to the
badlists infrastructure. Really bad lists won't be
fetched from a remote server, while plain bad list
will be fetched but won't be compiled.

A really bad list is denoted by the `nofetch` token
following the URL.

Really bad lists can cause more serious issues such
as causing undue launch delays because the remote
server where a really bad list is hosted fails to
respond properly and times out.

Such an example of really bad list is hpHosts which
original server no longer exist.
  • Loading branch information
gorhill committed Aug 22, 2020
1 parent 3d048c9 commit 4150c17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ const µBlock = (( ) => { // jshint ignore:line

selectedFilterLists: [],
availableFilterLists: {},
badLists: new Set(),
badLists: new Map(),

// https://github.com/uBlockOrigin/uBlock-issues/issues/974
// This can be used to defer filtering decision-making.
Expand Down
41 changes: 26 additions & 15 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,6 @@ 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 Down Expand Up @@ -538,12 +529,24 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
this.saveSelectedFilterLists([ listURL ], true);
};

// Load previously saved available lists -- these contains data
// computed at run-time, we will reuse this data if possible.
const [ bin, entries ] = await Promise.all([
const promises = [
vAPI.storage.get('availableFilterLists'),
this.assets.metadata(),
]);
this.badLists.size === 0 ? this.assets.get('ublock-badlists') : false,
];

// Load previously saved available lists -- these contains data
// computed at run-time, we will reuse this data if possible.
const [ bin, entries, badlists ] = await Promise.all(promises);

if ( badlists instanceof Object ) {
for ( const line of badlists.content.split(/\s*[\n\r]+\s*/) ) {
if ( line === '' || line.startsWith('#') ) { continue; }
const fields = line.split(/\s+/);
const remove = fields.length === 2 && fields[1] === 'nofetch';
this.badLists.set(fields[0], remove);
}
}

oldAvailableLists = bin && bin.availableFilterLists || {};

Expand Down Expand Up @@ -725,6 +728,11 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
}
}

// Skip downloading really bad lists.
if ( this.badLists.get(assetKey) ) {
return { assetKey, content: '' };
}

const rawDetails = await this.assets.get(assetKey);
// Compiling an empty string results in an empty string.
if ( rawDetails.content === '' ) {
Expand Down Expand Up @@ -1331,11 +1339,14 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {

µBlock.assetObserver = function(topic, details) {
// Do not update filter list if not in use.
// Also, ignore really bad lists, i.e. those which should not even be
// fetched from a remote server.
if ( topic === 'before-asset-updated' ) {
if ( details.type === 'filters' ) {
if (
this.availableFilterLists.hasOwnProperty(details.assetKey) === false ||
this.selectedFilterLists.indexOf(details.assetKey) === -1
this.selectedFilterLists.indexOf(details.assetKey) === -1 ||
this.badLists.get(details.assetKey)
) {
return;
}
Expand Down Expand Up @@ -1374,7 +1385,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
this.compilePublicSuffixList(details.content);
}
} else if ( details.assetKey === 'ublock-badlists' ) {
this.badLists = new Set();
this.badLists = new Map();
}
vAPI.messaging.broadcast({
what: 'assetUpdated',
Expand Down

0 comments on commit 4150c17

Please sign in to comment.