Do not cname-uncloak when a proxy is in use

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/911

Since cname-uncloaking is available only on Firefox
at the moment, the fix is relevant only to Firefox.

By default uBO will no longer cname-uncloak when it
detects that network requests are being being proxied.

This default behavior can be overriden by setting the
new advanced setting `cnameUncloakProxied` to `true`.
The new setting default to `false`, i.e. cname-uncloaking
is disabled when uBO detects that a proxy is in use.

This new advanced setting may disappear once the
following Firefox issue is fixed:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1618271
This commit is contained in:
Raymond Hill 2020-03-22 14:52:58 -04:00
parent f5204235b7
commit 3f7ece9469
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
4 changed files with 50 additions and 13 deletions

View file

@ -72,14 +72,32 @@
} }
setOptions(options) { setOptions(options) {
super.setOptions(options); super.setOptions(options);
this.cnameUncloak = browser.dns instanceof Object && if ( 'cnameUncloak' in options ) {
options.cnameUncloak !== false; this.cnameUncloak = browser.dns instanceof Object &&
this.cnameIgnoreList = this.regexFromStrList(options.cnameIgnoreList); options.cnameUncloak !== false;
this.cnameIgnore1stParty = options.cnameIgnore1stParty !== false; }
this.cnameIgnoreExceptions = options.cnameIgnoreExceptions !== false; if ( 'cnameIgnoreList' in options ) {
this.cnameIgnoreRootDocument = options.cnameIgnoreRootDocument !== false; this.cnameIgnoreList =
this.cnameMaxTTL = options.cnameMaxTTL || 120; this.regexFromStrList(options.cnameIgnoreList);
this.cnameReplayFullURL = options.cnameReplayFullURL === true; }
if ( 'cnameIgnore1stParty' in options ) {
this.cnameIgnore1stParty =
options.cnameIgnore1stParty !== false;
}
if ( 'cnameIgnoreExceptions' in options ) {
this.cnameIgnoreExceptions =
options.cnameIgnoreExceptions !== false;
}
if ( 'cnameIgnoreRootDocument' in options ) {
this.cnameIgnoreRootDocument =
options.cnameIgnoreRootDocument !== false;
}
if ( 'cnameMaxTTL' in options ) {
this.cnameMaxTTL = options.cnameMaxTTL || 120;
}
if ( 'cnameReplayFullURL' in options ) {
this.cnameReplayFullURL = options.cnameReplayFullURL === true;
}
this.cnames.clear(); this.cnames.set('', ''); this.cnames.clear(); this.cnames.set('', '');
this.cnameFlushTime = Date.now() + this.cnameMaxTTL * 60000; this.cnameFlushTime = Date.now() + this.cnameMaxTTL * 60000;
} }

View file

@ -54,6 +54,7 @@ const µBlock = (( ) => { // jshint ignore:line
cnameMaxTTL: 120, cnameMaxTTL: 120,
cnameReplayFullURL: false, cnameReplayFullURL: false,
cnameUncloak: true, cnameUncloak: true,
cnameUncloakProxied: false,
consoleLogLevel: 'unset', consoleLogLevel: 'unset',
debugScriptlets: false, debugScriptlets: false,
debugScriptletInjector: false, debugScriptletInjector: false,
@ -105,6 +106,7 @@ const µBlock = (( ) => { // jshint ignore:line
cloudStorageSupported: vAPI.cloud instanceof Object, cloudStorageSupported: vAPI.cloud instanceof Object,
canFilterResponseData: typeof browser.webRequest.filterResponseData === 'function', canFilterResponseData: typeof browser.webRequest.filterResponseData === 'function',
canInjectScriptletsNow: vAPI.webextFlavor.soup.has('chromium'), canInjectScriptletsNow: vAPI.webextFlavor.soup.has('chromium'),
proxyDNS: undefined,
// https://github.com/chrisaljoudi/uBlock/issues/180 // https://github.com/chrisaljoudi/uBlock/issues/180
// Whitelist directives need to be loaded once the PSL is available // Whitelist directives need to be loaded once the PSL is available

View file

@ -143,6 +143,16 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
cnameReplayFullURL: µBlock.hiddenSettings.cnameReplayFullURL, cnameReplayFullURL: µBlock.hiddenSettings.cnameReplayFullURL,
cnameUncloak: µBlock.hiddenSettings.cnameUncloak, cnameUncloak: µBlock.hiddenSettings.cnameUncloak,
}); });
// https://github.com/uBlockOrigin/uBlock-issues/issues/911
// See uBO's onHeadersReceived() listener.
if (
µBlock.hiddenSettings.cnameUncloak === false ||
µBlock.hiddenSettings.cnameUncloakProxied === true
) {
µBlock.proxyDNS = false;
} else {
µBlock.proxyDNS = undefined;
}
}); });
/******************************************************************************/ /******************************************************************************/

View file

@ -441,6 +441,17 @@ const onHeadersReceived = function(details) {
const isRootDoc = requestType === 'main_frame'; const isRootDoc = requestType === 'main_frame';
const isDoc = isRootDoc || requestType === 'sub_frame'; const isDoc = isRootDoc || requestType === 'sub_frame';
// https://github.com/uBlockOrigin/uBlock-issues/issues/911
// We detect here whether network requests are proxied, and if so,
// de-aliasing of hostnames will be disabled to avoid possible
// DNS leaks.
if ( isRootDoc && µb.proxyDNS === undefined ) {
µb.proxyDNS = details.proxyInfo instanceof Object;
if ( µb.proxyDNS ) {
vAPI.Net.setOptions({ cnameUncloak: false });
}
}
let pageStore = µb.pageStoreFromTabId(fctxt.tabId); let pageStore = µb.pageStoreFromTabId(fctxt.tabId);
if ( pageStore === null ) { if ( pageStore === null ) {
if ( isRootDoc === false ) { return; } if ( isRootDoc === false ) { return; }
@ -454,11 +465,7 @@ const onHeadersReceived = function(details) {
const responseHeaders = details.responseHeaders; const responseHeaders = details.responseHeaders;
if ( requestType === 'image' || requestType === 'media' ) { if ( requestType === 'image' || requestType === 'media' ) {
return foilLargeMediaElement( return foilLargeMediaElement(fctxt, pageStore, responseHeaders);
fctxt,
pageStore,
responseHeaders
);
} }
if ( isDoc === false ) { return; } if ( isDoc === false ) { return; }