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

Commit

Permalink
Fixes: #14374 Show warning if torrent files are opened in tor private…
Browse files Browse the repository at this point in the history
… tabs
  • Loading branch information
jumde authored and bsclifton committed Jun 25, 2018
1 parent 1c6778f commit 0e8c70c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/browser/webtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,7 @@ function getHeader (headers, headerName) {

module.exports = {
init,
isTorrentFile,
isMagnetURL,
resourceName: 'webtorrent'
}
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ streetAddress=Street Address
submit=Submit
tabsSuggestionTitle=Tabs
topSiteSuggestionTitle=Top Site
torrentBlockedInTor=For your privacy, torrents are blocked in private tabs when Tor is enabled.
torrentWarningOk=Ok
turnOffNotifications=Turn off notifications
unknownError=Oops, something went wrong.
unmuteTab=Unmute tab
Expand Down
21 changes: 21 additions & 0 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ipcMain = electron.ipcMain
const app = electron.app
const path = require('path')
const getOrigin = require('../js/lib/urlutil').getOrigin
const {isTorrentFile, isMagnetURL} = require('./browser/webtorrent')
const {adBlockResourceName} = require('./adBlock')
const {updateElectronDownloadItem} = require('./browser/electronDownloadItem')
const {fullscreenOption} = require('./common/constants/settingsEnums')
Expand All @@ -42,6 +43,7 @@ const tor = require('./tor')

let appStore = null

const tabMessageBox = require('./browser/tabMessageBox')
const beforeSendHeadersFilteringFns = []
const beforeRequestFilteringFns = []
const beforeRedirectFilteringFns = []
Expand Down Expand Up @@ -119,6 +121,11 @@ function registerForBeforeRequest (session, partition) {
return
}

if ((isMagnetURL(details)) && partition === appConfig.tor.partition) {
showTorrentBlockedInTorWarning(details)
return
}

const firstPartyUrl = module.exports.getMainFrameUrl(details)
const url = details.url
// this can happen if the tab is closed and the webContents is no longer available
Expand Down Expand Up @@ -350,6 +357,16 @@ function registerForBeforeSendHeaders (session, partition) {
})
}

function showTorrentBlockedInTorWarning (details) {
if (details.tabId) {
tabMessageBox.show(details.tabId, {
message: `${locale.translation('torrentBlockedInTor')}`,
title: 'Brave',
buttons: [locale.translation('torrentWarningOk')]
})
}
}

/**
* Register for notifications for webRequest.onHeadersReceived for a particular
* session.
Expand All @@ -363,6 +380,10 @@ function registerForHeadersReceived (session, partition) {
muonCb({})
return
}
if ((isTorrentFile(details)) && partition === appConfig.tor.partition) {
showTorrentBlockedInTorWarning(details)
return
}
const firstPartyUrl = module.exports.getMainFrameUrl(details)
// this can happen if the tab is closed and the webContents is no longer available
if (!firstPartyUrl) {
Expand Down
2 changes: 2 additions & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ var rendererIdentifiers = function () {
'downloadPaused',
'noDownloads',
'torrentDesc',
'torrentBlockedInTor',
'torrentWarningOk',
'multiSelectionBookmarks',
// Caption buttons in titlebar (min/max/close - Windows only)
'windowCaptionButtonMinimize',
Expand Down

0 comments on commit 0e8c70c

Please sign in to comment.