1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

Enable CNAME uncloaking by default

Advanced setting `cnameAliasList` has been removed.

New advanced settings:

cnameUncloak:
  Boolean
Default value:
  true
Description:
  Whether to CNAME-uncloak hostnames.

cnameIgnoreExceptions:
  Boolean
Default value:
  true
Description:
  Whether to bypass the uncloaking of network requests
  which were excepted by filters/rules. This is
  necessary so as to avoid undue breakage by having
  exception filters being rendered useless as a result
  of CNAME-uncloaking.
  For example, `google-analytics.com` uncloaks to
  `www-google-analytics.l.google.com` and both hostnames
  appear in Peter Lowe's list, which means exception
  filters for `google-analytics.com` (to fix site
  breakage) would be rendered useless as the uncloaking
  would cause the network request to be ultimately
  blocked.
This commit is contained in:
Raymond Hill 2019-12-01 12:05:49 -05:00
parent 8a1a8b103f
commit 91e702cebb
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 26 additions and 14 deletions

View File

@ -61,19 +61,21 @@
super(); super();
this.pendingRequests = []; this.pendingRequests = [];
this.cnames = new Map([ [ '', '' ] ]); this.cnames = new Map([ [ '', '' ] ]);
this.cnameAliasList = null;
this.cnameIgnoreList = null; this.cnameIgnoreList = null;
this.cnameIgnore1stParty = true; this.cnameIgnore1stParty = true;
this.cnameIgnoreExceptions = true;
this.cnameIgnoreRootDocument = true; this.cnameIgnoreRootDocument = true;
this.cnameMaxTTL = 60; this.cnameMaxTTL = 60;
this.cnameReplayFullURL = false; this.cnameReplayFullURL = false;
this.cnameTimer = undefined; this.cnameTimer = undefined;
this.cnameUncloak = true;
} }
setOptions(options) { setOptions(options) {
super.setOptions(options); super.setOptions(options);
this.cnameAliasList = this.regexFromStrList(options.cnameAliasList); this.cnameUncloak = options.cnameUncloak !== false;
this.cnameIgnoreList = this.regexFromStrList(options.cnameIgnoreList); this.cnameIgnoreList = this.regexFromStrList(options.cnameIgnoreList);
this.cnameIgnore1stParty = options.cnameIgnore1stParty !== false; this.cnameIgnore1stParty = options.cnameIgnore1stParty !== false;
this.cnameIgnoreExceptions = options.cnameIgnoreExceptions !== false;
this.cnameIgnoreRootDocument = options.cnameIgnoreRootDocument !== false; this.cnameIgnoreRootDocument = options.cnameIgnoreRootDocument !== false;
this.cnameMaxTTL = options.cnameMaxTTL || 120; this.cnameMaxTTL = options.cnameMaxTTL || 120;
this.cnameReplayFullURL = options.cnameReplayFullURL === true; this.cnameReplayFullURL = options.cnameReplayFullURL === true;
@ -199,22 +201,29 @@
); );
} }
onBeforeSuspendableRequest(details) { onBeforeSuspendableRequest(details) {
let r = super.onBeforeSuspendableRequest(details); const r = super.onBeforeSuspendableRequest(details);
if ( r !== undefined ) { return r; } if ( r !== undefined ) {
if ( this.cnameAliasList === null ) { return; } if (
if ( details.type === 'main_frame' && this.cnameIgnoreRootDocument ) { r.cancel === true ||
r.redirectUrl !== undefined ||
this.cnameIgnoreExceptions
) {
return r;
}
}
if (
details.type === 'main_frame' &&
this.cnameIgnoreRootDocument
) {
return; return;
} }
if ( this.cnameUncloak === false ) { return; }
const hn = vAPI.hostnameFromNetworkURL(details.url); const hn = vAPI.hostnameFromNetworkURL(details.url);
let cname = this.cnames.get(hn); let cname = this.cnames.get(hn);
if ( cname === '' ) { return; } if ( cname === '' ) { return; }
if ( cname !== undefined ) { if ( cname !== undefined ) {
return this.processCanonicalName(hn, cname, details); return this.processCanonicalName(hn, cname, details);
} }
if ( this.cnameAliasList.test(hn) === false ) {
this.cnames.set(hn, '');
return;
}
return browser.dns.resolve(hn, [ 'canonical_name' ]).then( return browser.dns.resolve(hn, [ 'canonical_name' ]).then(
rec => { rec => {
const cname = this.recordCanonicalName(hn, rec); const cname = this.recordCanonicalName(hn, rec);

View File

@ -46,12 +46,13 @@ const µBlock = (( ) => { // jshint ignore:line
cacheStorageAPI: 'unset', cacheStorageAPI: 'unset',
cacheStorageCompression: true, cacheStorageCompression: true,
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate', cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',
cnameAliasList: 'unset',
cnameIgnoreList: 'unset', cnameIgnoreList: 'unset',
cnameIgnore1stParty: true, cnameIgnore1stParty: true,
cnameIgnoreExceptions: true,
cnameIgnoreRootDocument: true, cnameIgnoreRootDocument: true,
cnameMaxTTL: 120, cnameMaxTTL: 60,
cnameReplayFullURL: false, cnameReplayFullURL: false,
cnameUncloak: true,
consoleLogLevel: 'unset', consoleLogLevel: 'unset',
debugScriptlets: false, debugScriptlets: false,
debugScriptletInjector: false, debugScriptletInjector: false,

View File

@ -136,12 +136,13 @@
self.addEventListener('hiddenSettingsChanged', ( ) => { self.addEventListener('hiddenSettingsChanged', ( ) => {
self.log.verbosity = µBlock.hiddenSettings.consoleLogLevel; self.log.verbosity = µBlock.hiddenSettings.consoleLogLevel;
vAPI.net.setOptions({ vAPI.net.setOptions({
cnameAliasList: µBlock.hiddenSettings.cnameAliasList,
cnameIgnoreList: µBlock.hiddenSettings.cnameIgnoreList, cnameIgnoreList: µBlock.hiddenSettings.cnameIgnoreList,
cnameIgnore1stParty: µBlock.hiddenSettings.cnameIgnore1stParty, cnameIgnore1stParty: µBlock.hiddenSettings.cnameIgnore1stParty,
cnameIgnoreExceptions: µBlock.hiddenSettings.cnameIgnoreExceptions,
cnameIgnoreRootDocument: µBlock.hiddenSettings.cnameIgnoreRootDocument, cnameIgnoreRootDocument: µBlock.hiddenSettings.cnameIgnoreRootDocument,
cnameMaxTTL: µBlock.hiddenSettings.cnameMaxTTL, cnameMaxTTL: µBlock.hiddenSettings.cnameMaxTTL,
cnameReplayFullURL: µBlock.hiddenSettings.cnameReplayFullURL, cnameReplayFullURL: µBlock.hiddenSettings.cnameReplayFullURL,
cnameUncloak: µBlock.hiddenSettings.cnameUncloak,
}); });
}); });

View File

@ -103,7 +103,8 @@ const onBeforeRequest = function(details) {
) { ) {
pageStore.setFrame(details.frameId, details.url); pageStore.setFrame(details.frameId, details.url);
} }
return; if ( result !== 2 ) { return; }
return { cancel: false };
} }
// Blocked // Blocked