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

Commit 53b0e06

Browse files
jumdebsclifton
authored andcommitted
Fixes: #14374 Show warning if torrent files are opened in tor private tabs
1 parent 077cde6 commit 53b0e06

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')
@@ -42,6 +43,7 @@ const tor = require('./tor')
4243

4344
let appStore = null
4445

46+
const tabMessageBox = require('./browser/tabMessageBox')
4547
const beforeSendHeadersFilteringFns = []
4648
const beforeRequestFilteringFns = []
4749
const beforeRedirectFilteringFns = []
@@ -119,6 +121,11 @@ function registerForBeforeRequest (session, partition) {
119121
return
120122
}
121123

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

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