Skip to content

Commit

Permalink
Avoid using dns.resolve() for proxied DNS resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 10, 2024
1 parent 09ccfc8 commit d5f14ff
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 47 deletions.
47 changes: 2 additions & 45 deletions platform/firefox/vapi-background-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
Home: https://github.com/gorhill/uBlock
*/

/* globals browser */

'use strict';

/******************************************************************************/

import {
domainFromHostname,
hostnameFromNetworkURL,
Expand All @@ -34,24 +28,6 @@ import {

// Canonical name-uncloaking feature.
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:
// - https://github.com/gorhill/uBlock/issues/1327
Expand Down Expand Up @@ -81,9 +57,6 @@ vAPI.Net = class extends vAPI.Net {
this.canUncloakCnames &&
options.cnameUncloakEnabled !== false;
}
if ( 'cnameUncloakProxied' in options ) {
cnameUncloakProxied = options.cnameUncloakProxied === true;
}
if ( 'cnameIgnoreList' in options ) {
this.cnameIgnoreList =
this.regexFromStrList(options.cnameIgnoreList);
Expand All @@ -108,23 +81,6 @@ vAPI.Net = class extends vAPI.Net {
}
this.cnames.clear(); this.cnames.set('', null);
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) {
const type = details.type;
Expand Down Expand Up @@ -236,7 +192,7 @@ vAPI.Net = class extends vAPI.Net {
return /^./;
}
return new RegExp(
'(?:^|\.)(?:' +
'(?:^|\\.)(?:' +
list.trim()
.split(/\s+/)
.map(a => a.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
Expand All @@ -261,6 +217,7 @@ vAPI.Net = class extends vAPI.Net {
if ( cnRecord !== undefined ) {
return this.processCanonicalName(hn, cnRecord, details);
}
if ( details.proxyInfo && details.proxyInfo.proxyDNS ) { return; }
const documentUrl = details.documentUrl || details.url;
const isRootDocument = this.cnameIgnoreRootDocument &&
hn === hostnameFromNetworkURL(documentUrl);
Expand Down
1 change: 0 additions & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const hiddenSettingsDefault = {
cnameIgnoreRootDocument: true,
cnameMaxTTL: 120,
cnameReplayFullURL: false,
cnameUncloakProxied: false,
consoleLogLevel: 'unset',
debugAssetsJson: false,
debugScriptlets: false,
Expand Down
1 change: 0 additions & 1 deletion src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ onBroadcast(msg => {
cnameIgnoreRootDocument: µbhs.cnameIgnoreRootDocument,
cnameMaxTTL: µbhs.cnameMaxTTL,
cnameReplayFullURL: µbhs.cnameReplayFullURL,
cnameUncloakProxied: µbhs.cnameUncloakProxied,
});
});

Expand Down

0 comments on commit d5f14ff

Please sign in to comment.