@@ -29,7 +29,7 @@ const ipcMain = electron.ipcMain
29
29
const app = electron . app
30
30
const path = require ( 'path' )
31
31
const getOrigin = require ( '../js/lib/urlutil' ) . getOrigin
32
- const { isTorrentFile, isMagnetURL } = require ( './browser/webtorrent' )
32
+ const { isTorrentFile} = require ( './browser/webtorrent' )
33
33
const { adBlockResourceName} = require ( './adBlock' )
34
34
const { updateElectronDownloadItem} = require ( './browser/electronDownloadItem' )
35
35
const { fullscreenOption} = require ( './common/constants/settingsEnums' )
@@ -103,6 +103,13 @@ module.exports.registerHeadersReceivedFilteringCB = (filteringFn) => {
103
103
headersReceivedFilteringFns . push ( filteringFn )
104
104
}
105
105
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
+
106
113
/**
107
114
* Register for notifications for webRequest.onBeforeRequest for a particular
108
115
* session.
@@ -111,6 +118,20 @@ module.exports.registerHeadersReceivedFilteringCB = (filteringFn) => {
111
118
function registerForBeforeRequest ( session , partition ) {
112
119
const isPrivate = module . exports . isPrivate ( partition )
113
120
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
+
114
135
if ( process . env . NODE_ENV === 'development' ) {
115
136
let page = appUrlUtil . getGenDir ( details . url )
116
137
if ( page ) {
@@ -136,11 +157,6 @@ function registerForBeforeRequest (session, partition) {
136
157
return
137
158
}
138
159
139
- if ( ( isMagnetURL ( details ) ) && partition === appConfig . tor . partition ) {
140
- showTorrentBlockedInTorWarning ( details , muonCb )
141
- return
142
- }
143
-
144
160
const firstPartyUrl = module . exports . getMainFrameUrl ( details )
145
161
// this can happen if the tab is closed and the webContents is no longer available
146
162
if ( ! firstPartyUrl ) {
@@ -377,13 +393,13 @@ function registerForBeforeSendHeaders (session, partition) {
377
393
} )
378
394
}
379
395
380
- function showTorrentBlockedInTorWarning ( details , muonCb ) {
396
+ function onBlockedInTor ( details , muonCb ) {
381
397
const cb = ( ) => muonCb ( { cancel : true } )
382
- if ( details . tabId ) {
398
+ if ( details . tabId && details . resourceType === 'mainFrame' ) {
383
399
tabMessageBox . show ( details . tabId , {
384
- message : `${ locale . translation ( 'torrentBlockedInTor ' ) } ` ,
400
+ message : `${ locale . translation ( 'urlBlockedInTor ' ) } ` ,
385
401
title : 'Brave' ,
386
- buttons : [ locale . translation ( 'torrentWarningOk ' ) ]
402
+ buttons : [ locale . translation ( 'urlWarningOk ' ) ]
387
403
} , cb )
388
404
} else {
389
405
cb ( )
@@ -404,7 +420,7 @@ function registerForHeadersReceived (session, partition) {
404
420
return
405
421
}
406
422
if ( ( isTorrentFile ( details ) ) && partition === appConfig . tor . partition ) {
407
- showTorrentBlockedInTorWarning ( details , muonCb )
423
+ onBlockedInTor ( details , muonCb )
408
424
return
409
425
}
410
426
const firstPartyUrl = module . exports . getMainFrameUrl ( details )
0 commit comments