Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit 2e345b0

Browse files
committed
Only allow whitelisted protocols to load in tor tabs
fix #14664
1 parent 3f8feb2 commit 2e345b0

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

app/extensions/brave/locales/en-US/app.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ streetAddress=Street Address
237237
submit=Submit
238238
tabsSuggestionTitle=Tabs
239239
topSiteSuggestionTitle=Top Site
240-
torrentBlockedInTor=For your privacy, torrents are blocked in private tabs when Tor is enabled.
241-
torrentWarningOk=Ok
240+
urlBlockedInTor=For your privacy, Brave blocks this URL from loading in a private tab when Tor is enabled.
241+
urlWarningOk=Ok
242242
torConnectionError=Unable to connect to the Tor network
243243
torConnectionErrorInfo=Brave could not make a connection to the Tor network. Disable Tor to continue private browsing without Tor protection.
244244
torConnectionErrorDisable=Disable Tor

app/filtering.js

+27-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const ipcMain = electron.ipcMain
2929
const app = electron.app
3030
const path = require('path')
3131
const getOrigin = require('../js/lib/urlutil').getOrigin
32-
const {isTorrentFile, isMagnetURL} = require('./browser/webtorrent')
32+
const {isTorrentFile} = require('./browser/webtorrent')
3333
const {adBlockResourceName} = require('./adBlock')
3434
const {updateElectronDownloadItem} = require('./browser/electronDownloadItem')
3535
const {fullscreenOption} = require('./common/constants/settingsEnums')
@@ -103,6 +103,13 @@ module.exports.registerHeadersReceivedFilteringCB = (filteringFn) => {
103103
headersReceivedFilteringFns.push(filteringFn)
104104
}
105105

106+
// Protocols which are safe to load in tor tabs
107+
const whitelistedTorProtocols = ['http:', 'https:', 'chrome-extension:', 'chrome-devtools:']
108+
if (process.env.NODE_ENV === 'development') {
109+
// Needed for connection to webpack local server
110+
whitelistedTorProtocols.push('ws:')
111+
}
112+
106113
/**
107114
* Register for notifications for webRequest.onBeforeRequest for a particular
108115
* session.
@@ -111,6 +118,20 @@ module.exports.registerHeadersReceivedFilteringCB = (filteringFn) => {
111118
function registerForBeforeRequest (session, partition) {
112119
const isPrivate = module.exports.isPrivate(partition)
113120
session.webRequest.onBeforeRequest((details, muonCb) => {
121+
if (partition === appConfig.tor.partition) {
122+
if (!details.url) {
123+
muonCb({ cancel: true })
124+
return
125+
}
126+
// To minimize leakage risk, only allow whitelisted protocols in Tor
127+
// sessions
128+
const protocol = urlParse(details.url).protocol
129+
if (!whitelistedTorProtocols.includes(protocol)) {
130+
onBlockedInTor(details, muonCb)
131+
return
132+
}
133+
}
134+
114135
if (process.env.NODE_ENV === 'development') {
115136
let page = appUrlUtil.getGenDir(details.url)
116137
if (page) {
@@ -136,11 +157,6 @@ function registerForBeforeRequest (session, partition) {
136157
return
137158
}
138159

139-
if ((isMagnetURL(details)) && partition === appConfig.tor.partition) {
140-
showTorrentBlockedInTorWarning(details, muonCb)
141-
return
142-
}
143-
144160
const firstPartyUrl = module.exports.getMainFrameUrl(details)
145161
// this can happen if the tab is closed and the webContents is no longer available
146162
if (!firstPartyUrl) {
@@ -377,13 +393,13 @@ function registerForBeforeSendHeaders (session, partition) {
377393
})
378394
}
379395

380-
function showTorrentBlockedInTorWarning (details, muonCb) {
396+
function onBlockedInTor (details, muonCb) {
381397
const cb = () => muonCb({cancel: true})
382-
if (details.tabId) {
398+
if (details.tabId && details.resourceType === 'mainFrame') {
383399
tabMessageBox.show(details.tabId, {
384-
message: `${locale.translation('torrentBlockedInTor')}`,
400+
message: `${locale.translation('urlBlockedInTor')}`,
385401
title: 'Brave',
386-
buttons: [locale.translation('torrentWarningOk')]
402+
buttons: [locale.translation('urlWarningOk')]
387403
}, cb)
388404
} else {
389405
cb()
@@ -404,7 +420,7 @@ function registerForHeadersReceived (session, partition) {
404420
return
405421
}
406422
if ((isTorrentFile(details)) && partition === appConfig.tor.partition) {
407-
showTorrentBlockedInTorWarning(details, muonCb)
423+
onBlockedInTor(details, muonCb)
408424
return
409425
}
410426
const firstPartyUrl = module.exports.getMainFrameUrl(details)

app/locale.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ var rendererIdentifiers = function () {
269269
'downloadPaused',
270270
'noDownloads',
271271
'torrentDesc',
272-
'torrentBlockedInTor',
273-
'torrentWarningOk',
272+
'urlBlockedInTor',
273+
'urlWarningOk',
274274
'multiSelectionBookmarks',
275275
// Caption buttons in titlebar (min/max/close - Windows only)
276276
'windowCaptionButtonMinimize',

0 commit comments

Comments
 (0)