Avoid using dns.resolve() for proxied DNS resolution

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/1743
This commit is contained in:
Raymond Hill 2024-09-10 14:58:40 -04:00
parent 09ccfc8cfb
commit d5f14ffa32
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
3 changed files with 2 additions and 47 deletions

View file

@ -19,12 +19,6 @@
Home: https://github.com/gorhill/uBlock Home: https://github.com/gorhill/uBlock
*/ */
/* globals browser */
'use strict';
/******************************************************************************/
import { import {
domainFromHostname, domainFromHostname,
hostnameFromNetworkURL, hostnameFromNetworkURL,
@ -34,24 +28,6 @@ import {
// Canonical name-uncloaking feature. // Canonical name-uncloaking feature.
let cnameUncloakEnabled = browser.dns instanceof Object; let cnameUncloakEnabled = browser.dns instanceof Object;
let cnameUncloakProxied = false;
// 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.
const proxyDetector = function(details) {
if ( details.proxyInfo instanceof Object ) {
cnameUncloakEnabled = false;
proxyDetectorTryCount = 0;
}
if ( proxyDetectorTryCount === 0 ) {
browser.webRequest.onHeadersReceived.removeListener(proxyDetector);
return;
}
proxyDetectorTryCount -= 1;
};
let proxyDetectorTryCount = 0;
// Related issues: // Related issues:
// - https://github.com/gorhill/uBlock/issues/1327 // - https://github.com/gorhill/uBlock/issues/1327
@ -81,9 +57,6 @@ vAPI.Net = class extends vAPI.Net {
this.canUncloakCnames && this.canUncloakCnames &&
options.cnameUncloakEnabled !== false; options.cnameUncloakEnabled !== false;
} }
if ( 'cnameUncloakProxied' in options ) {
cnameUncloakProxied = options.cnameUncloakProxied === true;
}
if ( 'cnameIgnoreList' in options ) { if ( 'cnameIgnoreList' in options ) {
this.cnameIgnoreList = this.cnameIgnoreList =
this.regexFromStrList(options.cnameIgnoreList); this.regexFromStrList(options.cnameIgnoreList);
@ -108,23 +81,6 @@ vAPI.Net = class extends vAPI.Net {
} }
this.cnames.clear(); this.cnames.set('', null); this.cnames.clear(); this.cnames.set('', null);
this.cnameFlushTime = Date.now() + this.cnameMaxTTL * 60000; this.cnameFlushTime = Date.now() + this.cnameMaxTTL * 60000;
// https://github.com/uBlockOrigin/uBlock-issues/issues/911
// Install/remove proxy detector.
if ( vAPI.webextFlavor.major < 80 ) {
const wrohr = browser.webRequest.onHeadersReceived;
if ( cnameUncloakEnabled === false || cnameUncloakProxied ) {
if ( wrohr.hasListener(proxyDetector) ) {
wrohr.removeListener(proxyDetector);
}
} else if ( wrohr.hasListener(proxyDetector) === false ) {
wrohr.addListener(
proxyDetector,
{ urls: [ '*://*/*' ] },
[ 'blocking' ]
);
}
proxyDetectorTryCount = 32;
}
} }
normalizeDetails(details) { normalizeDetails(details) {
const type = details.type; const type = details.type;
@ -236,7 +192,7 @@ vAPI.Net = class extends vAPI.Net {
return /^./; return /^./;
} }
return new RegExp( return new RegExp(
'(?:^|\.)(?:' + '(?:^|\\.)(?:' +
list.trim() list.trim()
.split(/\s+/) .split(/\s+/)
.map(a => a.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) .map(a => a.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
@ -261,6 +217,7 @@ vAPI.Net = class extends vAPI.Net {
if ( cnRecord !== undefined ) { if ( cnRecord !== undefined ) {
return this.processCanonicalName(hn, cnRecord, details); return this.processCanonicalName(hn, cnRecord, details);
} }
if ( details.proxyInfo && details.proxyInfo.proxyDNS ) { return; }
const documentUrl = details.documentUrl || details.url; const documentUrl = details.documentUrl || details.url;
const isRootDocument = this.cnameIgnoreRootDocument && const isRootDocument = this.cnameIgnoreRootDocument &&
hn === hostnameFromNetworkURL(documentUrl); hn === hostnameFromNetworkURL(documentUrl);

View file

@ -61,7 +61,6 @@ const hiddenSettingsDefault = {
cnameIgnoreRootDocument: true, cnameIgnoreRootDocument: true,
cnameMaxTTL: 120, cnameMaxTTL: 120,
cnameReplayFullURL: false, cnameReplayFullURL: false,
cnameUncloakProxied: false,
consoleLogLevel: 'unset', consoleLogLevel: 'unset',
debugAssetsJson: false, debugAssetsJson: false,
debugScriptlets: false, debugScriptlets: false,

View file

@ -319,7 +319,6 @@ onBroadcast(msg => {
cnameIgnoreRootDocument: µbhs.cnameIgnoreRootDocument, cnameIgnoreRootDocument: µbhs.cnameIgnoreRootDocument,
cnameMaxTTL: µbhs.cnameMaxTTL, cnameMaxTTL: µbhs.cnameMaxTTL,
cnameReplayFullURL: µbhs.cnameReplayFullURL, cnameReplayFullURL: µbhs.cnameReplayFullURL,
cnameUncloakProxied: µbhs.cnameUncloakProxied,
}); });
}); });