@@ -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,26 @@ 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 ( isMagnetURL ( details ) ) {
123
+ // Show a useful warning for magnet urls
124
+ showTorrentBlockedInTorWarning ( details , muonCb )
125
+ return
126
+ }
127
+ if ( ! details . url ) {
128
+ muonCb ( { cancel : true } )
129
+ return
130
+ }
131
+ // To minimize leakage risk, only allow whitelisted protocols in Tor
132
+ // sessions
133
+ const protocol = urlParse ( details . url ) . protocol
134
+ if ( ! whitelistedTorProtocols . includes ( protocol ) ) {
135
+ console . log ( 'Blocked protocol from loading in tor tab:' , protocol )
136
+ muonCb ( { cancel : true } )
137
+ return
138
+ }
139
+ }
140
+
114
141
if ( process . env . NODE_ENV === 'development' ) {
115
142
let page = appUrlUtil . getGenDir ( details . url )
116
143
if ( page ) {
@@ -136,11 +163,6 @@ function registerForBeforeRequest (session, partition) {
136
163
return
137
164
}
138
165
139
- if ( ( isMagnetURL ( details ) ) && partition === appConfig . tor . partition ) {
140
- showTorrentBlockedInTorWarning ( details , muonCb )
141
- return
142
- }
143
-
144
166
const firstPartyUrl = module . exports . getMainFrameUrl ( details )
145
167
// this can happen if the tab is closed and the webContents is no longer available
146
168
if ( ! firstPartyUrl ) {
0 commit comments