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

Expose ability to toggle on/off cname-uncloaking to all users

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

Prior to this commit, the ability to enable/disable the
uncloaking of canonical names was only available to advanced
users. This commit make it so that the setting can be
toggled from the _Settings_ pane.

The setting is enabled by default. The documentation should
be clear that the setting should not be disabled unless it
actually solves serious network issues, for example:

https://bugzilla.mozilla.org/show_bug.cgi?id=1694404

Also, as a result, the advanced setting `cnameUncloak` is no
longer available from within the advanced settings editor.
This commit is contained in:
Raymond Hill 2021-03-02 13:00:56 -05:00
parent 794c67c7d2
commit 1c3b45f75d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
10 changed files with 61 additions and 19 deletions

View File

@ -50,7 +50,7 @@
const parsedURL = new URL('about:blank'); const parsedURL = new URL('about:blank');
// Canonical name-uncloaking feature. // Canonical name-uncloaking feature.
let cnameUncloak = browser.dns instanceof Object; let cnameUncloakEnabled = browser.dns instanceof Object;
let cnameUncloakProxied = false; let cnameUncloakProxied = false;
// https://github.com/uBlockOrigin/uBlock-issues/issues/911 // https://github.com/uBlockOrigin/uBlock-issues/issues/911
@ -59,7 +59,7 @@
// DNS leaks. // DNS leaks.
const proxyDetector = function(details) { const proxyDetector = function(details) {
if ( details.proxyInfo instanceof Object ) { if ( details.proxyInfo instanceof Object ) {
cnameUncloak = false; cnameUncloakEnabled = false;
proxyDetectorTryCount = 0; proxyDetectorTryCount = 0;
} }
if ( proxyDetectorTryCount === 0 ) { if ( proxyDetectorTryCount === 0 ) {
@ -81,6 +81,7 @@
constructor() { constructor() {
super(); super();
this.pendingRequests = []; this.pendingRequests = [];
this.canUncloakCnames = browser.dns instanceof Object;
this.cnames = new Map([ [ '', '' ] ]); this.cnames = new Map([ [ '', '' ] ]);
this.cnameIgnoreList = null; this.cnameIgnoreList = null;
this.cnameIgnore1stParty = true; this.cnameIgnore1stParty = true;
@ -92,9 +93,10 @@
} }
setOptions(options) { setOptions(options) {
super.setOptions(options); super.setOptions(options);
if ( 'cnameUncloak' in options ) { if ( 'cnameUncloakEnabled' in options ) {
cnameUncloak = browser.dns instanceof Object && cnameUncloakEnabled =
options.cnameUncloak !== false; this.canUncloakCnames &&
options.cnameUncloakEnabled !== false;
} }
if ( 'cnameUncloakProxied' in options ) { if ( 'cnameUncloakProxied' in options ) {
cnameUncloakProxied = options.cnameUncloakProxied === true; cnameUncloakProxied = options.cnameUncloakProxied === true;
@ -127,7 +129,7 @@
// Install/remove proxy detector. // Install/remove proxy detector.
if ( vAPI.webextFlavor.major < 80 ) { if ( vAPI.webextFlavor.major < 80 ) {
const wrohr = browser.webRequest.onHeadersReceived; const wrohr = browser.webRequest.onHeadersReceived;
if ( cnameUncloak === false || cnameUncloakProxied ) { if ( cnameUncloakEnabled === false || cnameUncloakProxied ) {
if ( wrohr.hasListener(proxyDetector) ) { if ( wrohr.hasListener(proxyDetector) ) {
wrohr.removeListener(proxyDetector); wrohr.removeListener(proxyDetector);
} }
@ -266,7 +268,7 @@
} }
onBeforeSuspendableRequest(details) { onBeforeSuspendableRequest(details) {
const r = super.onBeforeSuspendableRequest(details); const r = super.onBeforeSuspendableRequest(details);
if ( cnameUncloak === false ) { return r; } if ( cnameUncloakEnabled === false ) { return r; }
if ( r !== undefined ) { if ( r !== undefined ) {
if ( if (
r.cancel === true || r.cancel === true ||

View File

@ -371,6 +371,10 @@
"message": "Block CSP reports", "message": "Block CSP reports",
"description": "background information: https://github.com/gorhill/uBlock/issues/3150" "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": { "settingsLastRestorePrompt": {
"message": "Last restore:", "message": "Last restore:",
"description": "English: Last restore:" "description": "English: Last restore:"

View File

@ -179,6 +179,10 @@ label {
border-color: var(--checkbox-checked-ink); border-color: var(--checkbox-checked-ink);
stroke: var(--default-surface); stroke: var(--default-surface);
} }
.checkbox[disabled],
.checkbox[disabled] ~ span {
opacity: 0.5;
}
select { select {
padding: 2px; padding: 2px;

View File

@ -88,6 +88,7 @@ const µBlock = (( ) => { // jshint ignore:line
alwaysDetachLogger: true, alwaysDetachLogger: true,
autoUpdate: true, autoUpdate: true,
cloudStorageEnabled: false, cloudStorageEnabled: false,
cnameUncloakEnabled: true,
collapseBlocked: true, collapseBlocked: true,
colorBlindFriendly: false, colorBlindFriendly: false,
contextMenuEnabled: true, contextMenuEnabled: true,

View File

@ -190,6 +190,9 @@ const onMessage = function(request, sender, callback) {
case 'userSettings': case 'userSettings':
response = µb.changeUserSettings(request.name, request.value); response = µb.changeUserSettings(request.name, request.value);
if ( vAPI.net.canUncloakCnames !== true ) {
response.cnameUncloakEnabled = undefined;
}
break; break;
default: default:

View File

@ -240,16 +240,20 @@ const onPreventDefault = function(ev) {
// TODO: use data-* to declare simple settings // TODO: use data-* to declare simple settings
const onUserSettingsReceived = function(details) { const onUserSettingsReceived = function(details) {
uDom('[data-setting-type="bool"]').forEach(function(uNode) { const checkboxes = document.querySelectorAll('[data-setting-type="bool"]');
uNode.prop('checked', details[uNode.attr('data-setting-name')] === true) for ( const checkbox of checkboxes ) {
.on('change', function() { const name = checkbox.getAttribute('data-setting-name') || '';
changeUserSettings( if ( details[name] === undefined ) {
this.getAttribute('data-setting-name'), checkbox.closest('.checkbox').setAttribute('disabled', '');
this.checked checkbox.setAttribute('disabled', '');
); continue;
synchronizeDOM(); }
}); checkbox.checked = details[name] === true;
}); checkbox.addEventListener('change', ( ) => {
changeUserSettings(name, checkbox.checked);
synchronizeDOM();
});
}
uDom('[data-i18n="settingsNoLargeMediaPrompt"] > input[type="number"]') uDom('[data-i18n="settingsNoLargeMediaPrompt"] > input[type="number"]')
.attr('data-setting-name', 'largeMediaSize') .attr('data-setting-name', 'largeMediaSize')

View File

@ -175,6 +175,17 @@ const onUserSettingsReady = function(fetched) {
fetched.externalLists.trim().split(/[\n\r]+/); 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); fromFetch(µb.userSettings, fetched);
if ( µb.privacySettingsSupported ) { if ( µb.privacySettingsSupported ) {
@ -184,6 +195,14 @@ const onUserSettingsReady = function(fetched) {
'webrtcIPAddress': !µb.userSettings.webrtcIPAddressHidden '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 });
}
}; };
/******************************************************************************/ /******************************************************************************/

View File

@ -234,7 +234,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
cnameIgnoreRootDocument: µbhs.cnameIgnoreRootDocument, cnameIgnoreRootDocument: µbhs.cnameIgnoreRootDocument,
cnameMaxTTL: µbhs.cnameMaxTTL, cnameMaxTTL: µbhs.cnameMaxTTL,
cnameReplayFullURL: µbhs.cnameReplayFullURL, cnameReplayFullURL: µbhs.cnameReplayFullURL,
cnameUncloak: µbhs.cnameUncloak,
cnameUncloakProxied: µbhs.cnameUncloakProxied, cnameUncloakProxied: µbhs.cnameUncloakProxied,
}); });
}); });

View File

@ -322,7 +322,7 @@ const matchBucket = function(url, hostname, bucket, start) {
} }
// Change -- but only if the user setting actually exists. // 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 ) { if ( mustSave ) {
us[name] = value; us[name] = value;
} }
@ -337,6 +337,11 @@ const matchBucket = function(url, hostname, bucket, start) {
case 'autoUpdate': case 'autoUpdate':
this.scheduleAssetUpdater(value ? 7 * 60 * 1000 : 0); this.scheduleAssetUpdater(value ? 7 * 60 * 1000 : 0);
break; break;
case 'cnameUncloakEnabled':
if ( vAPI.net.canUncloakCnames === true ) {
vAPI.net.setOptions({ cnameUncloakEnabled: value === true });
}
break;
case 'collapseBlocked': case 'collapseBlocked':
if ( value === false ) { if ( value === false ) {
this.cosmeticFilteringEngine.removeFromSelectorCache('*', 'net'); this.cosmeticFilteringEngine.removeFromSelectorCache('*', 'net');

View File

@ -28,6 +28,7 @@
<div class="li"><label><span class="input checkbox"><input type="checkbox" data-setting-name="hyperlinkAuditingDisabled" data-setting-type="bool"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span><span data-i18n="settingsHyperlinkAuditingDisabledPrompt"></span>&nbsp;<a class="fa-icon info important" href="https://github.com/gorhill/uBlock/wiki/Dashboard:-Settings#disable-hyperlink-auditing" target="_blank">info-circle</a></span></label></div> <div class="li"><label><span class="input checkbox"><input type="checkbox" data-setting-name="hyperlinkAuditingDisabled" data-setting-type="bool"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span><span data-i18n="settingsHyperlinkAuditingDisabledPrompt"></span>&nbsp;<a class="fa-icon info important" href="https://github.com/gorhill/uBlock/wiki/Dashboard:-Settings#disable-hyperlink-auditing" target="_blank">info-circle</a></span></label></div>
<div class="li"><label><span class="input checkbox"><input type="checkbox" data-setting-name="webrtcIPAddressHidden" data-setting-type="bool"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span><span data-i18n="settingsWebRTCIPAddressHiddenPrompt"></span>&nbsp;<a class="fa-icon info important" href="https://github.com/gorhill/uBlock/wiki/Prevent-WebRTC-from-leaking-local-IP-address" target="_blank">info-circle</a></span></label></div> <div class="li"><label><span class="input checkbox"><input type="checkbox" data-setting-name="webrtcIPAddressHidden" data-setting-type="bool"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span><span data-i18n="settingsWebRTCIPAddressHiddenPrompt"></span>&nbsp;<a class="fa-icon info important" href="https://github.com/gorhill/uBlock/wiki/Prevent-WebRTC-from-leaking-local-IP-address" target="_blank">info-circle</a></span></label></div>
<div class="li"><label><span class="input checkbox"><input type="checkbox" data-setting-name="noCSPReports" data-setting-type="bool"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span><span data-i18n="settingsNoCSPReportsPrompt"></span>&nbsp;<a class="fa-icon info" href="https://github.com/gorhill/uBlock/wiki/Dashboard:-Settings#block-csp-reports" target="_blank">info-circle</a></span></label></div> <div class="li"><label><span class="input checkbox"><input type="checkbox" data-setting-name="noCSPReports" data-setting-type="bool"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span><span data-i18n="settingsNoCSPReportsPrompt"></span>&nbsp;<a class="fa-icon info" href="https://github.com/gorhill/uBlock/wiki/Dashboard:-Settings#block-csp-reports" target="_blank">info-circle</a></span></label></div>
<div class="li"><label><span class="input checkbox"><input type="checkbox" data-setting-name="cnameUncloakEnabled" data-setting-type="bool"><svg viewBox="0 0 24 24"><path d="M1.73,12.91 8.1,19.28 22.79,4.59"/></svg></span><span><span data-i18n="settingsUncloakCnamePrompt"></span>&nbsp;<a class="fa-icon info" href="https://github.com/gorhill/uBlock/wiki/Dashboard:-Settings#uncloak-canonical-names" target="_blank">info-circle</a></span></label></div>
</div> </div>
<hr> <hr>
<div class="fieldset"> <div class="fieldset">