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

Commit

Permalink
Block loading .onion sites in non-Tor tabs.
Browse files Browse the repository at this point in the history
fix #14431

Auditors: @diracdeltas @bsclifton

Test Plan:
I:
	1. Open a tab _without_ Tor (private or nonprivate).
	2. Enter: https://nyttips4bmquxfzw.onion/
	3. Confirm that Brave blocks loading the URL.

II:
	1. Open a tab _without_ Tor (private or nonprivate).
	2. Enter: https://nyttips4bmquxfzw.onion:12345/
	3. Confirm that Brave blocks loading the URL.

III:
	1. Open a private tab with Tor.
	2. Enter: https://nyttips4bmquxfzw.onion/
	3. Confirm that the NYT SecureDrop page loads.
	4. Bookmark it.
	5. Open a tab _without_ Tor (private or nonprivate).
	6. Try to load the bookmark.
	7. Confirm that Brave blocks loading the bookmark.
  • Loading branch information
riastradh-brave committed Jul 12, 2018
1 parent e78fc93 commit 6efebe7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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

0 comments on commit 6efebe7

Please sign in to comment.