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

Commit

Permalink
Only allow whitelisted protocols to load in tor tabs
Browse files Browse the repository at this point in the history
fix #14664
  • Loading branch information
diracdeltas committed Jul 5, 2018
1 parent 3f8feb2 commit 9759cc3
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ module.exports.registerHeadersReceivedFilteringCB = (filteringFn) => {
headersReceivedFilteringFns.push(filteringFn)
}

// Protocols which are safe to load in tor tabs
const whitelistedTorProtocols = ['http:', 'https:', 'chrome-extension:', 'chrome-devtools:']
if (process.env.NODE_ENV === 'development') {
// Needed for connection to webpack local server
whitelistedTorProtocols.push('ws:')
}

/**
* Register for notifications for webRequest.onBeforeRequest for a particular
* session.
Expand All @@ -111,6 +118,26 @@ module.exports.registerHeadersReceivedFilteringCB = (filteringFn) => {
function registerForBeforeRequest (session, partition) {
const isPrivate = module.exports.isPrivate(partition)
session.webRequest.onBeforeRequest((details, muonCb) => {
if (partition === appConfig.tor.partition) {
if (isMagnetURL(details)) {
// Show a useful warning for magnet urls
showTorrentBlockedInTorWarning(details, muonCb)
return
}
if (!details.url) {
muonCb({ cancel: true })
return
}
// To minimize leakage risk, only allow whitelisted protocols in Tor
// sessions
const protocol = urlParse(details.url).protocol
if (!whitelistedTorProtocols.includes(protocol)) {
console.log('Blocked protocol from loading in tor tab:', protocol)
muonCb({ cancel: true })
return
}
}

if (process.env.NODE_ENV === 'development') {
let page = appUrlUtil.getGenDir(details.url)
if (page) {
Expand All @@ -136,11 +163,6 @@ function registerForBeforeRequest (session, partition) {
return
}

if ((isMagnetURL(details)) && partition === appConfig.tor.partition) {
showTorrentBlockedInTorWarning(details, muonCb)
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

0 comments on commit 9759cc3

Please sign in to comment.