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

Commit

Permalink
check for null mainFrameUrl
Browse files Browse the repository at this point in the history
auditors: @bbondy @diracdeltas

fix #4325

Test Plan:
Test the crash
1. Open the browser with at least two tabs
2. Go to https://jpn.privateinternetaccess.com/
3. You will see the page header appear and as soon as you see the rest of the page start to load immediately close the tab
Because the timing is tricky this should be tried several times

Test ad block and tracking protection still work
1. Go to slashdot.org
2. No ads should be displayed
3. Open the dev tools and check to see that ga.js is blocked (google analytics)

Test site hacks still work
1. Go to forbes.com
2. You should go directly to the home page and not see the landing page

Test https everywhere still works
1. Go to https://badssl.com/
2. Click on https-everwhere
3. You should get a green page with ssl enabled
  • Loading branch information
bridiver committed Sep 27, 2016
1 parent ba86711 commit 814a723
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
9 changes: 8 additions & 1 deletion app/adBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ const whitelistHosts = ['disqus.com', 'a.disquscdn.com']

const startAdBlocking = (adblock, resourceName, shouldCheckMainFrame) => {
Filtering.registerBeforeRequestFilteringCB((details) => {
const firstPartyUrl = URL.parse(Filtering.getMainFrameUrl(details))
const mainFrameUrl = Filtering.getMainFrameUrl(details)
// this can happen if the tab is closed and the webContents is no longer available
if (!mainFrameUrl) {
return {
resourceName: module.exports.resourceName
}
}
const firstPartyUrl = URL.parse(mainFrameUrl)
let firstPartyUrlHost = firstPartyUrl.hostname || ''
const urlHost = URL.parse(details.url).hostname
const cancel = firstPartyUrl.protocol &&
Expand Down
9 changes: 5 additions & 4 deletions app/httpsEverywhere.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ function startHttpsEverywhere () {

function onBeforeHTTPRequest (details) {
let result = { resourceName: module.exports.resourceName }
if (!Filtering.isResourceEnabled(module.exports.resourceName,
Filtering.getMainFrameUrl(details))) {

const mainFrameUrl = Filtering.getMainFrameUrl(details)
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl)) {
return result
}
// Ignore URLs that are not HTTP
Expand All @@ -137,8 +138,8 @@ function onBeforeHTTPRequest (details) {
}

function onBeforeRedirect (details) {
if (!Filtering.isResourceEnabled(module.exports.resourceName,
Filtering.getMainFrameUrl(details))) {
const mainFrameUrl = Filtering.getMainFrameUrl(details)
if (!mainFrameUrl || !Filtering.isResourceEnabled(module.exports.resourceName, mainFrameUrl)) {
return
}

Expand Down
18 changes: 16 additions & 2 deletions app/siteHacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ module.exports.init = () => {
let hack = siteHacks[domain]
let customCookie
let cancel
const firstPartyUrl = Filtering.getMainFrameUrl(details)
const mainFrameUrl = Filtering.getMainFrameUrl(details)
// this can happen if the tab is closed and the webContents is no longer available
if (!mainFrameUrl) {
return {
resourceName: module.exports.resourceName
}
}
const firstPartyUrl = URL.parse(mainFrameUrl)
if (hack && hack.onBeforeSendHeaders) {
const result = hack.onBeforeSendHeaders.call(this, details)
if (result && result.customCookie) {
Expand All @@ -49,7 +56,14 @@ module.exports.init = () => {

let redirectURL
let cancel
const firstPartyUrl = Filtering.getMainFrameUrl(details)
const mainFrameUrl = Filtering.getMainFrameUrl(details)
// this can happen if the tab is closed and the webContents is no longer available
if (!mainFrameUrl) {
return {
resourceName: module.exports.resourceName
}
}
const firstPartyUrl = URL.parse(mainFrameUrl)
if (hack && hack.onBeforeRequest &&
(hack.enableForAll ||
hack.enableForAdblock && Filtering.isResourceEnabled(appConfig.resourceNames.ADBLOCK, firstPartyUrl) ||
Expand Down
9 changes: 8 additions & 1 deletion app/trackingProtection.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ const whitelistHosts = ['connect.facebook.net', 'connect.facebook.com', 'staticx

const startTrackingProtection = (wnd) => {
Filtering.registerBeforeRequestFilteringCB((details) => {
const firstPartyUrl = URL.parse(Filtering.getMainFrameUrl(details))
const mainFrameUrl = Filtering.getMainFrameUrl(details)
// this can happen if the tab is closed and the webContents is no longer available
if (!mainFrameUrl) {
return {
resourceName: module.exports.resourceName
}
}
const firstPartyUrl = URL.parse(mainFrameUrl)
let firstPartyUrlHost = firstPartyUrl.hostname || ''
if (firstPartyUrlHost.startsWith('www.')) {
firstPartyUrlHost = firstPartyUrlHost.substring(4)
Expand Down

1 comment on commit 814a723

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.