Skip to content

Commit 7840f18

Browse files
committed
Fix isResourceEnabled private tab overlay
fix brave#5701 Auditors: @bbondy Test Plan: covered by auto test
1 parent abfbbb3 commit 7840f18

File tree

7 files changed

+227
-32
lines changed

7 files changed

+227
-32
lines changed

app/filtering.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function registerForBeforeRequest (session, partition) {
110110
}
111111

112112
for (let i = 0; i < beforeRequestFilteringFns.length; i++) {
113-
let results = beforeRequestFilteringFns[i](details)
113+
let results = beforeRequestFilteringFns[i](details, isPrivate)
114114
const isAdBlock = results.resourceName === appConfig.resourceNames.ADBLOCK || appConfig[results.resourceName] && appConfig[results.resourceName].resourceType === adBlockResourceName
115115
const isHttpsEverywhere = results.resourceName === appConfig.resourceNames.HTTPS_EVERYWHERE
116116
const isTracker = results.resourceName === appConfig.resourceNames.TRACKING_PROTECTION
@@ -185,7 +185,8 @@ function registerForBeforeRequest (session, partition) {
185185
* session.
186186
* @param {object} session Session to add webRequest filtering on
187187
*/
188-
function registerForBeforeRedirect (session) {
188+
function registerForBeforeRedirect (session, partition) {
189+
const isPrivate = !partition.startsWith('persist:')
189190
// Note that onBeforeRedirect listener doesn't take a callback
190191
session.webRequest.onBeforeRedirect(function (details) {
191192
// Using an electron binary which isn't from Brave
@@ -196,7 +197,7 @@ function registerForBeforeRedirect (session) {
196197
// Note that since this isn't supposed to have a return value, the
197198
// redirect filtering function must check whether the resource is
198199
// enabled and do nothing if it's not.
199-
beforeRedirectFilteringFns[i](details)
200+
beforeRedirectFilteringFns[i](details, isPrivate)
200201
}
201202
})
202203
}
@@ -244,7 +245,7 @@ function registerForBeforeSendHeaders (session, partition) {
244245
}
245246

246247
for (let i = 0; i < beforeSendHeadersFilteringFns.length; i++) {
247-
let results = beforeSendHeadersFilteringFns[i](details)
248+
let results = beforeSendHeadersFilteringFns[i](details, isPrivate)
248249
if (!module.exports.isResourceEnabled(results.resourceName, firstPartyUrl, isPrivate)) {
249250
continue
250251
}
@@ -401,20 +402,17 @@ function registerPermissionHandler (session, partition) {
401402
}
402403

403404
const permissionName = permission + 'Permission'
405+
let isAllowed
404406
if (settings) {
405-
let isAllowed = settings.get(permissionName)
406-
if (typeof isAllowed === 'boolean') {
407-
cb(isAllowed)
408-
return
409-
}
407+
isAllowed = settings.get(permissionName)
410408
}
411409
// Private tabs inherit settings from normal tabs, but not vice versa.
412410
if (isPrivate && tempSettings) {
413-
let isAllowed = tempSettings.get(permissionName)
414-
if (typeof isAllowed === 'boolean') {
415-
cb(isAllowed)
416-
return
417-
}
411+
isAllowed = tempSettings.get(permissionName)
412+
}
413+
if (typeof isAllowed === 'boolean') {
414+
cb(isAllowed)
415+
return
418416
}
419417

420418
const message = locale.translation('permissionMessage').replace(/{{\s*host\s*}}/, origin).replace(/{{\s*permission\s*}}/, permissions[permission].action)
@@ -605,13 +603,13 @@ module.exports.isResourceEnabled = (resourceName, url, isPrivate) => {
605603
}
606604

607605
const appState = appStore.getState()
608-
let settings
609-
if (!isPrivate) {
610-
settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), url)
611-
} else {
612-
settings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), url)
606+
const settings = siteSettings.getSiteSettingsForURL(appState.get('siteSettings'), url)
607+
const tempSettings = siteSettings.getSiteSettingsForURL(appState.get('temporarySiteSettings'), url)
608+
609+
let braverySettings = siteSettings.activeSettings(settings, appState, appConfig)
610+
if (isPrivate && tempSettings) {
611+
braverySettings = siteSettings.activeSettings(tempSettings, appState, appConfig)
613612
}
614-
const braverySettings = siteSettings.activeSettings(settings, appState, appConfig)
615613

616614
// If full shields are down never enable extra protection
617615
if (braverySettings.shieldsUp === false) {

app/httpsEverywhere.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ function startHttpsEverywhere () {
112112
Filtering.registerBeforeRedirectFilteringCB(onBeforeRedirect)
113113
}
114114

115-
function onBeforeHTTPRequest (details) {
115+
function onBeforeHTTPRequest (details, isPrivate) {
116116
let result = { resourceName: module.exports.resourceName }
117117

118118
const mainFrameUrl = Filtering.getMainFrameUrl(details)
119-
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl)) {
119+
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl, isPrivate)) {
120120
return result
121121
}
122122
// Ignore URLs that are not HTTP
@@ -137,9 +137,9 @@ function onBeforeHTTPRequest (details) {
137137
return result
138138
}
139139

140-
function onBeforeRedirect (details) {
140+
function onBeforeRedirect (details, isPrivate) {
141141
const mainFrameUrl = Filtering.getMainFrameUrl(details)
142-
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl)) {
142+
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl, isPrivate)) {
143143
return
144144
}
145145
// Ignore URLs that are not HTTP

app/siteHacks.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports.init = () => {
1515
if (!appConfig[resourceName].enabled) {
1616
return
1717
}
18-
Filtering.registerBeforeSendHeadersFilteringCB((details) => {
18+
Filtering.registerBeforeSendHeadersFilteringCB((details, isPrivate) => {
1919
if (details.resourceType !== 'mainFrame') {
2020
return {
2121
resourceName
@@ -31,7 +31,7 @@ module.exports.init = () => {
3131
const result = hack.onBeforeSendHeaders.call(this, details)
3232
if (result && result.customCookie) {
3333
customCookie = result.customCookie
34-
} else if (Filtering.isResourceEnabled(appConfig.resourceNames.NOSCRIPT, 'https://twitter.com/') &&
34+
} else if (Filtering.isResourceEnabled(appConfig.resourceNames.NOSCRIPT, 'https://twitter.com/', isPrivate) &&
3535
result && result.cancel) {
3636
// cancel is only called on Twitter where noscript is enabled
3737
cancel = true
@@ -43,7 +43,7 @@ module.exports.init = () => {
4343
cancel
4444
}
4545
})
46-
Filtering.registerBeforeRequestFilteringCB((details) => {
46+
Filtering.registerBeforeRequestFilteringCB((details, isPrivate) => {
4747
let domain = URL.parse(details.url).hostname
4848
let hack = siteHacks[domain]
4949

@@ -58,8 +58,8 @@ module.exports.init = () => {
5858
}
5959
if (hack && hack.onBeforeRequest &&
6060
(hack.enableForAll ||
61-
hack.enableForAdblock && Filtering.isResourceEnabled(appConfig.resourceNames.ADBLOCK, mainFrameUrl) ||
62-
hack.enableForTrackingProtection && Filtering.isResourceEnabled(appConfig.resourceNames.TRACKING_PROTECTION, mainFrameUrl))) {
61+
hack.enableForAdblock && Filtering.isResourceEnabled(appConfig.resourceNames.ADBLOCK, mainFrameUrl, isPrivate) ||
62+
hack.enableForTrackingProtection && Filtering.isResourceEnabled(appConfig.resourceNames.TRACKING_PROTECTION, mainFrameUrl, isPrivate))) {
6363
const result = hack.onBeforeRequest.call(this, details)
6464
if (result && result.redirectURL) {
6565
redirectURL = result.redirectURL

js/components/braveryPanel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class BraveryPanel extends ImmutableComponent {
287287
braverySelectTitle: true,
288288
disabled: !shieldsUp
289289
})} data-l10n-id='adControl' />
290-
<select className='form-control' value={adControl} onChange={this.onToggleAdControl} disabled={!shieldsUp}>
290+
<select className='adsBlockedControl form-control' value={adControl} onChange={this.onToggleAdControl} disabled={!shieldsUp}>
291291
<option data-l10n-id='showBraveAds' value='showBraveAds' />
292292
<option data-l10n-id='blockAds' value='blockAds' />
293293
<option data-l10n-id='allowAdsAndTracking' value='allowAdsAndTracking' />

0 commit comments

Comments
 (0)