tor ip leak protection
This commit is contained in:
+3
-5
@@ -38,11 +38,9 @@ class ProxySettingsReplication extends _$ProxySettingsReplication {
|
|||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
torProxyServiceProvider.select((data) => data.value),
|
torProxyServiceProvider.select((data) => data.value),
|
||||||
(previous, next) async {
|
(previous, next) async {
|
||||||
if (next != null) {
|
await ref
|
||||||
await ref
|
.read(torProxyRepositoryProvider.notifier)
|
||||||
.read(torProxyRepositoryProvider.notifier)
|
.setProxyPort(next ?? -1);
|
||||||
.setProxyPort(next);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onError: (error, stackTrace) {
|
onError: (error, stackTrace) {
|
||||||
logger.e(
|
logger.e(
|
||||||
|
|||||||
+57
-50
@@ -31,6 +31,7 @@ export default class BackgroundMain {
|
|||||||
this.store = store
|
this.store = store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
initializeAuthListener(cookieStoreId: string, proxy: HttpProxySettings | HttpsProxySettings): void {
|
initializeAuthListener(cookieStoreId: string, proxy: HttpProxySettings | HttpsProxySettings): void {
|
||||||
const listener: (details: _OnAuthRequiredDetails) => BlockingResponse = (details) => {
|
const listener: (details: _OnAuthRequiredDetails) => BlockingResponse = (details) => {
|
||||||
if (!details.isProxy) return {}
|
if (!details.isProxy) return {}
|
||||||
@@ -55,65 +56,71 @@ export default class BackgroundMain {
|
|||||||
['blocking']
|
['blocking']
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
async onRequest(requestDetails: Pick<_OnRequestDetails, 'cookieStoreId' | 'url' | 'tabId'>): Promise<DoNotProxy | ProxyInfo[]> {
|
async onRequest(requestDetails: Pick<_OnRequestDetails, 'cookieStoreId' | 'url' | 'tabId'>): Promise<DoNotProxy | ProxyInfo[]> {
|
||||||
if (requestDetails.tabId > -1) {
|
const tab = (requestDetails.tabId > -1) ? (await browser.tabs.get(requestDetails.tabId)) : null
|
||||||
const tab = (await browser.tabs.get(requestDetails.tabId))
|
|
||||||
|
|
||||||
if (this.store.hasGeneralRelation() ||
|
if (this.store.hasGeneralRelation() ||
|
||||||
tab.cookieStoreId?.startsWith(containerIdentifier) === true ||
|
tab === null ||
|
||||||
tab.cookieStoreId === privateIdentifier
|
tab.cookieStoreId?.startsWith(containerIdentifier) === true ||
|
||||||
) {
|
tab.cookieStoreId === privateIdentifier
|
||||||
try {
|
) {
|
||||||
let cookieStoreId: string
|
try {
|
||||||
|
let cookieStoreId: string
|
||||||
|
|
||||||
if (tab.cookieStoreId?.startsWith(containerIdentifier) === true) {
|
if (tab?.cookieStoreId?.startsWith(containerIdentifier) === true) {
|
||||||
cookieStoreId = tab.cookieStoreId.substring(containerIdentifier.length)
|
cookieStoreId = tab.cookieStoreId.substring(containerIdentifier.length)
|
||||||
} else if (tab.cookieStoreId === privateIdentifier) {
|
} else if (tab?.cookieStoreId === privateIdentifier) {
|
||||||
// Handle private tabs - use 'private' as identifier
|
// Handle private tabs - use 'private' as identifier
|
||||||
cookieStoreId = 'private'
|
cookieStoreId = 'private'
|
||||||
} else {
|
} else {
|
||||||
cookieStoreId = 'general'
|
cookieStoreId = 'general'
|
||||||
}
|
}
|
||||||
|
|
||||||
const proxies = this.store.getProxiesForContainer(cookieStoreId)
|
let proxies = this.store.getProxiesForContainer(cookieStoreId)
|
||||||
|
if ((proxies?.length ?? 0) == 0 && tab === null) {
|
||||||
|
//When no tab is specified and general relation doesnt exist, we get all proxies to avoid leakage
|
||||||
|
proxies = this.store.getAllProxies()
|
||||||
|
|
||||||
if (proxies === null) {
|
if (proxies.length == 0) {
|
||||||
return doNotProxy
|
return doNotProxy
|
||||||
}
|
}
|
||||||
|
} else if (proxies === null) {
|
||||||
if (proxies.length > 0) {
|
return doNotProxy
|
||||||
proxies.forEach(p => {
|
|
||||||
if (p.type === ProxyType.Http || p.type === ProxyType.Https) {
|
|
||||||
this.initializeAuthListener(cookieStoreId, p)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const result: ProxyInfo[] = proxies.filter((p: ProxySettings) => {
|
|
||||||
try {
|
|
||||||
const documentUrl = new URL(requestDetails.url)
|
|
||||||
const isLocalhost = localhosts.has(documentUrl.hostname)
|
|
||||||
if (isLocalhost && p.doNotProxyLocal) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}).map(p => p.asProxyInfo())
|
|
||||||
|
|
||||||
if (result.length === 0) {
|
|
||||||
return [emergencyBreak]
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
return [emergencyBreak]
|
|
||||||
} catch (e: unknown) {
|
|
||||||
console.error(`Error in onRequest listener: ${e as string}`)
|
|
||||||
return [emergencyBreak]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (proxies.length > 0) {
|
||||||
|
// proxies.forEach(p => {
|
||||||
|
// if (p.type === ProxyType.Http || p.type === ProxyType.Https) {
|
||||||
|
// this.initializeAuthListener(cookieStoreId, p)
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
|
||||||
|
const result: ProxyInfo[] = proxies.filter((p: ProxySettings) => {
|
||||||
|
try {
|
||||||
|
const documentUrl = new URL(requestDetails.url)
|
||||||
|
const isLocalhost = localhosts.has(documentUrl.hostname)
|
||||||
|
if (isLocalhost && p.doNotProxyLocal) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}).map(p => p.asProxyInfo())
|
||||||
|
|
||||||
|
if (result.length === 0) {
|
||||||
|
return [emergencyBreak]
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
return [emergencyBreak]
|
||||||
|
} catch (e: unknown) {
|
||||||
|
console.error(`Error in onRequest listener: ${e as string}`)
|
||||||
|
return [emergencyBreak]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-10
@@ -17,16 +17,21 @@ port.onMessage.addListener((raw: unknown): void => {
|
|||||||
const message = raw as Message;
|
const message = raw as Message;
|
||||||
switch (message.action) {
|
switch (message.action) {
|
||||||
case "setProxyPort":
|
case "setProxyPort":
|
||||||
store.putProxy(new Socks5ProxySettings({
|
if (message.args > -1) {
|
||||||
id: 'tor',
|
store.putProxy(new Socks5ProxySettings({
|
||||||
type: 'socks',
|
id: 'tor',
|
||||||
host: '127.0.0.1',
|
type: 'socks',
|
||||||
port: message.args,
|
host: '127.0.0.1',
|
||||||
doNotProxyLocal: true,
|
port: message.args,
|
||||||
title: 'Tor',
|
doNotProxyLocal: true,
|
||||||
proxyDNS: true,
|
title: 'Tor',
|
||||||
}))
|
proxyDNS: true,
|
||||||
console.log('put tor port ' + message.args)
|
}))
|
||||||
|
console.log('put tor port ' + message.args)
|
||||||
|
} else {
|
||||||
|
store.deleteProxyById('tor')
|
||||||
|
console.log('remove tor port')
|
||||||
|
}
|
||||||
|
|
||||||
break
|
break
|
||||||
case "addContainerProxy":
|
case "addContainerProxy":
|
||||||
|
|||||||
Reference in New Issue
Block a user