Skip to content

Commit 1c3b45f

Browse files
committed
Expose ability to toggle on/off cname-uncloaking to all users
Related issue: - uBlockOrigin/uBlock-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.
1 parent 794c67c commit 1c3b45f

File tree

10 files changed

+61
-19
lines changed

10 files changed

+61
-19
lines changed

platform/firefox/vapi-webrequest.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
const parsedURL = new URL('about:blank');
5151

5252
// Canonical name-uncloaking feature.
53-
let cnameUncloak = browser.dns instanceof Object;
53+
let cnameUncloakEnabled = browser.dns instanceof Object;
5454
let cnameUncloakProxied = false;
5555

5656
// https://github.com/uBlockOrigin/uBlock-issues/issues/911
@@ -59,7 +59,7 @@
5959
// DNS leaks.
6060
const proxyDetector = function(details) {
6161
if ( details.proxyInfo instanceof Object ) {
62-
cnameUncloak = false;
62+
cnameUncloakEnabled = false;
6363
proxyDetectorTryCount = 0;
6464
}
6565
if ( proxyDetectorTryCount === 0 ) {
@@ -81,6 +81,7 @@
8181
constructor() {
8282
super();
8383
this.pendingRequests = [];
84+
this.canUncloakCnames = browser.dns instanceof Object;
8485
this.cnames = new Map([ [ '', '' ] ]);
8586
this.cnameIgnoreList = null;
8687
this.cnameIgnore1stParty = true;
@@ -92,9 +93,10 @@
9293
}
9394
setOptions(options) {
9495
super.setOptions(options);
95-
if ( 'cnameUncloak' in options ) {
96-
cnameUncloak = browser.dns instanceof Object &&
97-
options.cnameUncloak !== false;
96+
if ( 'cnameUncloakEnabled' in options ) {
97+
cnameUncloakEnabled =
98+
this.canUncloakCnames &&
99+
options.cnameUncloakEnabled !== false;
98100
}
99101
if ( 'cnameUncloakProxied' in options ) {
100102
cnameUncloakProxied = options.cnameUncloakProxied === true;
@@ -127,7 +129,7 @@
127129
// Install/remove proxy detector.
128130
if ( vAPI.webextFlavor.major < 80 ) {
129131
const wrohr = browser.webRequest.onHeadersReceived;
130-
if ( cnameUncloak === false || cnameUncloakProxied ) {
132+
if ( cnameUncloakEnabled === false || cnameUncloakProxied ) {
131133
if ( wrohr.hasListener(proxyDetector) ) {
132134
wrohr.removeListener(proxyDetector);
133135
}
@@ -266,7 +268,7 @@
266268
}
267269
onBeforeSuspendableRequest(details) {
268270
const r = super.onBeforeSuspendableRequest(details);
269-
if ( cnameUncloak === false ) { return r; }
271+
if ( cnameUncloakEnabled === false ) { return r; }
270272
if ( r !== undefined ) {
271273
if (
272274
r.cancel === true ||

src/_locales/en/messages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@
371371
"message": "Block CSP reports",
372372
"description": "background information: https://github.com/gorhill/uBlock/issues/3150"
373373
},
374+
"settingsUncloakCnamePrompt": {
375+
"message": "Uncloak canonical names",
376+
"description": "background information: https://github.com/uBlockOrigin/uBlock-issues/issues/1513"
377+
},
374378
"settingsLastRestorePrompt": {
375379
"message": "Last restore:",
376380
"description": "English: Last restore:"

src/css/common.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ label {
179179
border-color: var(--checkbox-checked-ink);
180180
stroke: var(--default-surface);
181181
}
182+
.checkbox[disabled],
183+
.checkbox[disabled] ~ span {
184+
opacity: 0.5;
185+
}
182186

183187
select {
184188
padding: 2px;

src/js/background.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const µBlock = (( ) => { // jshint ignore:line
8888
alwaysDetachLogger: true,
8989
autoUpdate: true,
9090
cloudStorageEnabled: false,
91+
cnameUncloakEnabled: true,
9192
collapseBlocked: true,
9293
colorBlindFriendly: false,
9394
contextMenuEnabled: true,

src/js/messaging.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ const onMessage = function(request, sender, callback) {
190190

191191
case 'userSettings':
192192
response = µb.changeUserSettings(request.name, request.value);
193+
if ( vAPI.net.canUncloakCnames !== true ) {
194+
response.cnameUncloakEnabled = undefined;
195+
}
193196
break;
194197

195198
default:

src/js/settings.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,20 @@ const onPreventDefault = function(ev) {
240240
// TODO: use data-* to declare simple settings
241241

242242
const onUserSettingsReceived = function(details) {
243-
uDom('[data-setting-type="bool"]').forEach(function(uNode) {
244-
uNode.prop('checked', details[uNode.attr('data-setting-name')] === true)
245-
.on('change', function() {
246-
changeUserSettings(
247-
this.getAttribute('data-setting-name'),
248-
this.checked
249-
);
250-
synchronizeDOM();
251-
});
252-
});
243+
const checkboxes = document.querySelectorAll('[data-setting-type="bool"]');
244+
for ( const checkbox of checkboxes ) {
245+
const name = checkbox.getAttribute('data-setting-name') || '';
246+
if ( details[name] === undefined ) {
247+
checkbox.closest('.checkbox').setAttribute('disabled', '');
248+
checkbox.setAttribute('disabled', '');
249+
continue;
250+
}
251+
checkbox.checked = details[name] === true;
252+
checkbox.addEventListener('change', ( ) => {
253+
changeUserSettings(name, checkbox.checked);
254+
synchronizeDOM();
255+
});
256+
}
253257

254258
uDom('[data-i18n="settingsNoLargeMediaPrompt"] > input[type="number"]')
255259
.attr('data-setting-name', 'largeMediaSize')

src/js/start.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ const onUserSettingsReady = function(fetched) {
175175
fetched.externalLists.trim().split(/[\n\r]+/);
176176
}
177177

178+
// https://github.com/uBlockOrigin/uBlock-issues/issues/1513
179+
// Transition nicely.
180+
// TODO: remove when current version of uBO is well past 1.34.0.
181+
if ( typeof µb.hiddenSettings.cnameUncloak === false ) {
182+
fetched.cnameUncloakEnabled = false;
183+
µb.hiddenSettings.cnameUncloak = true;
184+
µb.saveHiddenSettings();
185+
}
186+
µb.hiddenSettingsDefault.cnameUncloak = undefined;
187+
µb.hiddenSettings.cnameUncloak = undefined;
188+
178189
fromFetch(µb.userSettings, fetched);
179190

180191
if ( µb.privacySettingsSupported ) {
@@ -184,6 +195,14 @@ const onUserSettingsReady = function(fetched) {
184195
'webrtcIPAddress': !µb.userSettings.webrtcIPAddressHidden
185196
});
186197
}
198+
199+
// https://github.com/uBlockOrigin/uBlock-issues/issues/1513
200+
if (
201+
vAPI.net.canUncloakCnames &&
202+
µb.userSettings.cnameUncloakEnabled === false
203+
) {
204+
vAPI.net.setOptions({ cnameUncloakEnabled: false });
205+
}
187206
};
188207

189208
/******************************************************************************/

src/js/storage.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
234234
cnameIgnoreRootDocument: µbhs.cnameIgnoreRootDocument,
235235
cnameMaxTTL: µbhs.cnameMaxTTL,
236236
cnameReplayFullURL: µbhs.cnameReplayFullURL,
237-
cnameUncloak: µbhs.cnameUncloak,
238237
cnameUncloakProxied: µbhs.cnameUncloakProxied,
239238
});
240239
});

src/js/ublock.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ const matchBucket = function(url, hostname, bucket, start) {
322322
}
323323

324324
// Change -- but only if the user setting actually exists.
325-
let mustSave = us.hasOwnProperty(name) && value !== us[name];
325+
const mustSave = us.hasOwnProperty(name) && value !== us[name];
326326
if ( mustSave ) {
327327
us[name] = value;
328328
}
@@ -337,6 +337,11 @@ const matchBucket = function(url, hostname, bucket, start) {
337337
case 'autoUpdate':
338338
this.scheduleAssetUpdater(value ? 7 * 60 * 1000 : 0);
339339
break;
340+
case 'cnameUncloakEnabled':
341+
if ( vAPI.net.canUncloakCnames === true ) {
342+
vAPI.net.setOptions({ cnameUncloakEnabled: value === true });
343+
}
344+
break;
340345
case 'collapseBlocked':
341346
if ( value === false ) {
342347
this.cosmeticFilteringEngine.removeFromSelectorCache('*', 'net');

src/settings.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<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>
2929
<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>
3030
<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>
31+
<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>
3132
</div>
3233
<hr>
3334
<div class="fieldset">

0 commit comments

Comments
 (0)