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

Block loading .onion sites in non-Tor tabs. #14715

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ submit=Submit
tabsSuggestionTitle=Tabs
topSiteSuggestionTitle=Top Site
urlBlockedInTor=For your privacy, Brave blocks this URL from loading in a private tab when Tor is enabled.
urlBlockedOutsideTor=For your privacy, Brave blocks this URL from loading in a tab without Tor.
urlWarningOk=Ok
torConnectionError=Unable to connect to the Tor network
torConnectionErrorInfo=Brave could not make a connection to the Tor network. Disable Tor to continue private browsing without Tor protection.
Expand Down
21 changes: 19 additions & 2 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ function registerForBeforeRequest (session, partition) {
onBlockedInTor(details, muonCb)
return
}
} else {
const hostname = urlParse(details.url).hostname
// US-ASCII only in `.onion', so no need for locale-dependent
// case-insensitive comparisons.
if (typeof hostname === 'string' &&
hostname.toLowerCase().endsWith('.onion')) {
onBlockedOutsideTor(details, muonCb)
return
}
}

if (process.env.NODE_ENV === 'development') {
Expand Down Expand Up @@ -393,11 +402,11 @@ function registerForBeforeSendHeaders (session, partition) {
})
}

function onBlockedInTor (details, muonCb) {
function onBlocked (reasonKey, details, muonCb) {
const cb = () => muonCb({cancel: true})
if (details.tabId && details.resourceType === 'mainFrame') {
tabMessageBox.show(details.tabId, {
message: `${locale.translation('urlBlockedInTor')}`,
message: `${locale.translation(reasonKey)}`,
title: 'Brave',
buttons: [locale.translation('urlWarningOk')]
}, cb)
Expand All @@ -406,6 +415,14 @@ function onBlockedInTor (details, muonCb) {
}
}

function onBlockedInTor (details, muonCb) {
onBlocked('urlBlockedInTor', details, muonCb)
}

function onBlockedOutsideTor (details, muonCb) {
onBlocked('urlBlockedOutsideTor', details, muonCb)
}

/**
* Register for notifications for webRequest.onHeadersReceived for a particular
* session.
Expand Down
1 change: 1 addition & 0 deletions app/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ var rendererIdentifiers = function () {
'noDownloads',
'torrentDesc',
'urlBlockedInTor',
'urlBlockedOutsideTor',
'urlWarningOk',
'multiSelectionBookmarks',
// Caption buttons in titlebar (min/max/close - Windows only)
Expand Down