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

Commit 5be86a7

Browse files
jumdebsclifton
authored andcommitted
Fixes: #14374 Show warning if torrent files are opened in tor private tabs
1 parent 9505e6b commit 5be86a7

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

app/browser/webtorrent.js

+2
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,7 @@ function getHeader (headers, headerName) {
145145

146146
module.exports = {
147147
init,
148+
isTorrentFile,
149+
isMagnetURL,
148150
resourceName: 'webtorrent'
149151
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -237,6 +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
240242
turnOffNotifications=Turn off notifications
241243
unknownError=Oops, something went wrong.
242244
unmuteTab=Unmute tab

app/filtering.js

+21
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const ipcMain = electron.ipcMain
2828
const app = electron.app
2929
const path = require('path')
3030
const getOrigin = require('../js/lib/urlutil').getOrigin
31+
const {isTorrentFile, isMagnetURL} = require('./browser/webtorrent')
3132
const {adBlockResourceName} = require('./adBlock')
3233
const {updateElectronDownloadItem} = require('./browser/electronDownloadItem')
3334
const {fullscreenOption} = require('./common/constants/settingsEnums')
@@ -41,6 +42,7 @@ const tor = require('./tor')
4142

4243
let appStore = null
4344

45+
const tabMessageBox = require('./browser/tabMessageBox')
4446
const beforeSendHeadersFilteringFns = []
4547
const beforeRequestFilteringFns = []
4648
const beforeRedirectFilteringFns = []
@@ -118,6 +120,11 @@ function registerForBeforeRequest (session, partition) {
118120
return
119121
}
120122

123+
if ((isMagnetURL(details)) && partition === appConfig.tor.partition) {
124+
showTorrentBlockedInTorWarning(details)
125+
return
126+
}
127+
121128
const firstPartyUrl = module.exports.getMainFrameUrl(details)
122129
const url = details.url
123130
// this can happen if the tab is closed and the webContents is no longer available
@@ -349,6 +356,16 @@ function registerForBeforeSendHeaders (session, partition) {
349356
})
350357
}
351358

359+
function showTorrentBlockedInTorWarning (details) {
360+
if (details.tabId) {
361+
tabMessageBox.show(details.tabId, {
362+
message: `${locale.translation('torrentBlockedInTor')}`,
363+
title: 'Brave',
364+
buttons: [locale.translation('torrentWarningOk')]
365+
})
366+
}
367+
}
368+
352369
/**
353370
* Register for notifications for webRequest.onHeadersReceived for a particular
354371
* session.
@@ -362,6 +379,10 @@ function registerForHeadersReceived (session, partition) {
362379
muonCb({})
363380
return
364381
}
382+
if ((isTorrentFile(details)) && partition === appConfig.tor.partition) {
383+
showTorrentBlockedInTorWarning(details)
384+
return
385+
}
365386
const firstPartyUrl = module.exports.getMainFrameUrl(details)
366387
// this can happen if the tab is closed and the webContents is no longer available
367388
if (!firstPartyUrl) {

app/locale.js

+2
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ var rendererIdentifiers = function () {
257257
'downloadPaused',
258258
'noDownloads',
259259
'torrentDesc',
260+
'torrentBlockedInTor',
261+
'torrentWarningOk',
260262
'multiSelectionBookmarks',
261263
// Caption buttons in titlebar (min/max/close - Windows only)
262264
'windowCaptionButtonMinimize',

0 commit comments

Comments
 (0)