Skip to content

Commit ff35507

Browse files
committed
Refactor conncheck from extension detection
1 parent 820f0ae commit ff35507

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/helpers/domain.ts

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export const checkDomain = (host: string) => {
77
hasSubdomain: Boolean(parsed.subdomain),
88
subDomain: host,
99
domain: parsed.domain || host,
10-
isMullvadNet: parsed.domain === 'mullvad.net',
1110
};
1211
};
1312

src/helpers/socksProxy/socksProxy.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const handleProxyRequest = async (details: browser.proxy._OnRequestDetail
3030
const hostProxiesDetailsParsed: Record<string, ProxyDetails> = JSON.parse(hostProxiesDetails);
3131

3232
const currentHost = getCurrentHost(details);
33-
const { hasSubdomain, domain, subDomain, isMullvadNet } = checkDomain(currentHost);
33+
const { hasSubdomain, domain, subDomain } = checkDomain(currentHost);
3434
const currentDomain = hasSubdomain ? subDomain : domain;
3535

3636
const isDomainExcluded = excludedHostsParsed.includes(currentDomain);
@@ -50,13 +50,7 @@ export const handleProxyRequest = async (details: browser.proxy._OnRequestDetail
5050

5151
// 3. When the request if a conncheck/DNS check originating from the extension,
5252
// we want to use the same proxy as the active tab, to get a consistent conncheck result
53-
const isExtensionRequest = details.documentUrl?.startsWith('moz-extension://');
54-
const isConnCheck = isMullvadNet && details.url?.endsWith('am.i.mullvad.net/json');
55-
const isDNSCheck = isMullvadNet && details.url?.endsWith('dnsleak.am.i.mullvad.net/');
56-
57-
const isExtConnCheck = isExtensionRequest && (isConnCheck || isDNSCheck);
58-
59-
if (isExtConnCheck) {
53+
if (isExtConnCheck(details)) {
6054
return getProxyForExtensionConnectionCheck(
6155
isGlobalProxyEnabled,
6256
globalConfigParsed,
@@ -115,6 +109,17 @@ const getCurrentHost = (details: RequestDetails) => {
115109
return new URL(details.url).hostname;
116110
};
117111

112+
const isExtConnCheck = (details: RequestDetails): boolean => {
113+
const isExtensionRequest = Boolean(details.documentUrl?.startsWith('moz-extension://'));
114+
const isConnCheck =
115+
details.url === 'https://ipv4.am.i.mullvad.net/json' ||
116+
details.url === 'https://ipv6.am.i.mullvad.net/json';
117+
const isDNSCheck =
118+
checkDomain(details.url).domain === 'mullvad.net' && details.url.endsWith('am.i.mullvad.net/');
119+
120+
return isExtensionRequest && (isConnCheck || isDNSCheck);
121+
};
122+
118123
export const isLocalOrReservedIP = (hostname: string) => {
119124
if (hostname.includes('localhost')) return true;
120125
if (!ipaddr.isValid(hostname)) return false;

0 commit comments

Comments
 (0)