diff --git a/platform/firefox/vapi-webrequest.js b/platform/firefox/vapi-webrequest.js index eaa74b34f..c083cabfe 100644 --- a/platform/firefox/vapi-webrequest.js +++ b/platform/firefox/vapi-webrequest.js @@ -50,7 +50,7 @@ const parsedURL = new URL('about:blank'); // Canonical name-uncloaking feature. - let cnameUncloak = browser.dns instanceof Object; + let cnameUncloakEnabled = browser.dns instanceof Object; let cnameUncloakProxied = false; // https://github.com/uBlockOrigin/uBlock-issues/issues/911 @@ -59,7 +59,7 @@ // DNS leaks. const proxyDetector = function(details) { if ( details.proxyInfo instanceof Object ) { - cnameUncloak = false; + cnameUncloakEnabled = false; proxyDetectorTryCount = 0; } if ( proxyDetectorTryCount === 0 ) { @@ -81,6 +81,7 @@ constructor() { super(); this.pendingRequests = []; + this.canUncloakCnames = browser.dns instanceof Object; this.cnames = new Map([ [ '', '' ] ]); this.cnameIgnoreList = null; this.cnameIgnore1stParty = true; @@ -92,9 +93,10 @@ } setOptions(options) { super.setOptions(options); - if ( 'cnameUncloak' in options ) { - cnameUncloak = browser.dns instanceof Object && - options.cnameUncloak !== false; + if ( 'cnameUncloakEnabled' in options ) { + cnameUncloakEnabled = + this.canUncloakCnames && + options.cnameUncloakEnabled !== false; } if ( 'cnameUncloakProxied' in options ) { cnameUncloakProxied = options.cnameUncloakProxied === true; @@ -127,7 +129,7 @@ // Install/remove proxy detector. if ( vAPI.webextFlavor.major < 80 ) { const wrohr = browser.webRequest.onHeadersReceived; - if ( cnameUncloak === false || cnameUncloakProxied ) { + if ( cnameUncloakEnabled === false || cnameUncloakProxied ) { if ( wrohr.hasListener(proxyDetector) ) { wrohr.removeListener(proxyDetector); } @@ -266,7 +268,7 @@ } onBeforeSuspendableRequest(details) { const r = super.onBeforeSuspendableRequest(details); - if ( cnameUncloak === false ) { return r; } + if ( cnameUncloakEnabled === false ) { return r; } if ( r !== undefined ) { if ( r.cancel === true || diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 5179f0af5..470ee4401 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -371,6 +371,10 @@ "message": "Block CSP reports", "description": "background information: https://github.com/gorhill/uBlock/issues/3150" }, + "settingsUncloakCnamePrompt": { + "message": "Uncloak canonical names", + "description": "background information: https://github.com/uBlockOrigin/uBlock-issues/issues/1513" + }, "settingsLastRestorePrompt": { "message": "Last restore:", "description": "English: Last restore:" diff --git a/src/css/common.css b/src/css/common.css index c15a14f32..4f83c7a83 100644 --- a/src/css/common.css +++ b/src/css/common.css @@ -179,6 +179,10 @@ label { border-color: var(--checkbox-checked-ink); stroke: var(--default-surface); } +.checkbox[disabled], +.checkbox[disabled] ~ span { + opacity: 0.5; + } select { padding: 2px; diff --git a/src/js/background.js b/src/js/background.js index e96566c36..df1621f1d 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -88,6 +88,7 @@ const µBlock = (( ) => { // jshint ignore:line alwaysDetachLogger: true, autoUpdate: true, cloudStorageEnabled: false, + cnameUncloakEnabled: true, collapseBlocked: true, colorBlindFriendly: false, contextMenuEnabled: true, diff --git a/src/js/messaging.js b/src/js/messaging.js index ca3d8383c..5b442fc11 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -190,6 +190,9 @@ const onMessage = function(request, sender, callback) { case 'userSettings': response = µb.changeUserSettings(request.name, request.value); + if ( vAPI.net.canUncloakCnames !== true ) { + response.cnameUncloakEnabled = undefined; + } break; default: diff --git a/src/js/settings.js b/src/js/settings.js index b33a54040..8dba98ddb 100644 --- a/src/js/settings.js +++ b/src/js/settings.js @@ -240,16 +240,20 @@ const onPreventDefault = function(ev) { // TODO: use data-* to declare simple settings const onUserSettingsReceived = function(details) { - uDom('[data-setting-type="bool"]').forEach(function(uNode) { - uNode.prop('checked', details[uNode.attr('data-setting-name')] === true) - .on('change', function() { - changeUserSettings( - this.getAttribute('data-setting-name'), - this.checked - ); - synchronizeDOM(); - }); - }); + const checkboxes = document.querySelectorAll('[data-setting-type="bool"]'); + for ( const checkbox of checkboxes ) { + const name = checkbox.getAttribute('data-setting-name') || ''; + if ( details[name] === undefined ) { + checkbox.closest('.checkbox').setAttribute('disabled', ''); + checkbox.setAttribute('disabled', ''); + continue; + } + checkbox.checked = details[name] === true; + checkbox.addEventListener('change', ( ) => { + changeUserSettings(name, checkbox.checked); + synchronizeDOM(); + }); + } uDom('[data-i18n="settingsNoLargeMediaPrompt"] > input[type="number"]') .attr('data-setting-name', 'largeMediaSize') diff --git a/src/js/start.js b/src/js/start.js index dfe64106b..63285e588 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -175,6 +175,17 @@ const onUserSettingsReady = function(fetched) { fetched.externalLists.trim().split(/[\n\r]+/); } + // https://github.com/uBlockOrigin/uBlock-issues/issues/1513 + // Transition nicely. + // TODO: remove when current version of uBO is well past 1.34.0. + if ( typeof µb.hiddenSettings.cnameUncloak === false ) { + fetched.cnameUncloakEnabled = false; + µb.hiddenSettings.cnameUncloak = true; + µb.saveHiddenSettings(); + } + µb.hiddenSettingsDefault.cnameUncloak = undefined; + µb.hiddenSettings.cnameUncloak = undefined; + fromFetch(µb.userSettings, fetched); if ( µb.privacySettingsSupported ) { @@ -184,6 +195,14 @@ const onUserSettingsReady = function(fetched) { 'webrtcIPAddress': !µb.userSettings.webrtcIPAddressHidden }); } + + // https://github.com/uBlockOrigin/uBlock-issues/issues/1513 + if ( + vAPI.net.canUncloakCnames && + µb.userSettings.cnameUncloakEnabled === false + ) { + vAPI.net.setOptions({ cnameUncloakEnabled: false }); + } }; /******************************************************************************/ diff --git a/src/js/storage.js b/src/js/storage.js index e59c1bbb9..5f12022ea 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -234,7 +234,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { cnameIgnoreRootDocument: µbhs.cnameIgnoreRootDocument, cnameMaxTTL: µbhs.cnameMaxTTL, cnameReplayFullURL: µbhs.cnameReplayFullURL, - cnameUncloak: µbhs.cnameUncloak, cnameUncloakProxied: µbhs.cnameUncloakProxied, }); }); diff --git a/src/js/ublock.js b/src/js/ublock.js index 2a7d188ad..4284d15b4 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -322,7 +322,7 @@ const matchBucket = function(url, hostname, bucket, start) { } // Change -- but only if the user setting actually exists. - let mustSave = us.hasOwnProperty(name) && value !== us[name]; + const mustSave = us.hasOwnProperty(name) && value !== us[name]; if ( mustSave ) { us[name] = value; } @@ -337,6 +337,11 @@ const matchBucket = function(url, hostname, bucket, start) { case 'autoUpdate': this.scheduleAssetUpdater(value ? 7 * 60 * 1000 : 0); break; + case 'cnameUncloakEnabled': + if ( vAPI.net.canUncloakCnames === true ) { + vAPI.net.setOptions({ cnameUncloakEnabled: value === true }); + } + break; case 'collapseBlocked': if ( value === false ) { this.cosmeticFilteringEngine.removeFromSelectorCache('*', 'net'); diff --git a/src/settings.html b/src/settings.html index 6efb3d5fb..a3739a794 100644 --- a/src/settings.html +++ b/src/settings.html @@ -28,6 +28,7 @@
+