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

Commit

Permalink
ignore internal and extension generated requests
Browse files Browse the repository at this point in the history
maybe fixes #5930
fix #5934

auditors: @bbondy
  • Loading branch information
bridiver committed Nov 30, 2016
1 parent 46cea13 commit 6023abd
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function registerForBeforeRequest (session, partition) {
}
}

if (shouldIgnoreUrl(details.url)) {
if (shouldIgnoreUrl(details)) {
cb({})
return
}
Expand Down Expand Up @@ -197,7 +197,7 @@ function registerForBeforeRedirect (session, partition) {
// Note that onBeforeRedirect listener doesn't take a callback
session.webRequest.onBeforeRedirect(function (details) {
// Using an electron binary which isn't from Brave
if (shouldIgnoreUrl(details.url)) {
if (shouldIgnoreUrl(details)) {
return
}
for (let i = 0; i < beforeRedirectFilteringFns.length; i++) {
Expand All @@ -224,7 +224,7 @@ function registerForBeforeSendHeaders (session, partition) {

session.webRequest.onBeforeSendHeaders(function (details, cb) {
// Using an electron binary which isn't from Brave
if (shouldIgnoreUrl(details.url)) {
if (shouldIgnoreUrl(details)) {
cb({})
return
}
Expand Down Expand Up @@ -297,7 +297,7 @@ function registerForHeadersReceived (session, partition) {
// Note that onBeforeRedirect listener doesn't take a callback
session.webRequest.onHeadersReceived(function (details, cb) {
// Using an electron binary which isn't from Brave
if (shouldIgnoreUrl(details.url)) {
if (shouldIgnoreUrl(details)) {
cb({})
return
}
Expand Down Expand Up @@ -550,16 +550,30 @@ function initForPartition (partition) {

const filterableProtocols = ['http:', 'https:']

function shouldIgnoreUrl (url) {
function shouldIgnoreUrl (details) {
// internal requests
if (details.tabId === -1) {
return true
}

// Ensure host is well-formed (RFC 1035) and has a non-empty hostname
try {
const firstPartyUrl = urlParse(details.firstPartyUrl)
if (!filterableProtocols.includes(firstPartyUrl.protocol)) {
return true
}
} catch (e) {
console.warn('Error parsing ' + details.firstPartyUrl)
}

try {
// TODO(bridiver) - handle RFS check and cancel http/https requests with 0 or > 255 length hostames
const parsedUrl = urlParse(url)
const parsedUrl = urlParse(details.url)
if (filterableProtocols.includes(parsedUrl.protocol)) {
return false
}
} catch (e) {
console.warn('Error parsing ' + url)
console.warn('Error parsing ' + details.url)
}
return true
}
Expand Down

1 comment on commit 6023abd

@bbondy
Copy link
Member

@bbondy bbondy commented on 6023abd Dec 1, 2016

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.