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

Commit 6023abd

Browse files
committed
ignore internal and extension generated requests
maybe fixes #5930 fix #5934 auditors: @bbondy
1 parent 46cea13 commit 6023abd

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

app/filtering.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function registerForBeforeRequest (session, partition) {
9898
}
9999
}
100100

101-
if (shouldIgnoreUrl(details.url)) {
101+
if (shouldIgnoreUrl(details)) {
102102
cb({})
103103
return
104104
}
@@ -197,7 +197,7 @@ function registerForBeforeRedirect (session, partition) {
197197
// Note that onBeforeRedirect listener doesn't take a callback
198198
session.webRequest.onBeforeRedirect(function (details) {
199199
// Using an electron binary which isn't from Brave
200-
if (shouldIgnoreUrl(details.url)) {
200+
if (shouldIgnoreUrl(details)) {
201201
return
202202
}
203203
for (let i = 0; i < beforeRedirectFilteringFns.length; i++) {
@@ -224,7 +224,7 @@ function registerForBeforeSendHeaders (session, partition) {
224224

225225
session.webRequest.onBeforeSendHeaders(function (details, cb) {
226226
// Using an electron binary which isn't from Brave
227-
if (shouldIgnoreUrl(details.url)) {
227+
if (shouldIgnoreUrl(details)) {
228228
cb({})
229229
return
230230
}
@@ -297,7 +297,7 @@ function registerForHeadersReceived (session, partition) {
297297
// Note that onBeforeRedirect listener doesn't take a callback
298298
session.webRequest.onHeadersReceived(function (details, cb) {
299299
// Using an electron binary which isn't from Brave
300-
if (shouldIgnoreUrl(details.url)) {
300+
if (shouldIgnoreUrl(details)) {
301301
cb({})
302302
return
303303
}
@@ -550,16 +550,30 @@ function initForPartition (partition) {
550550

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

553-
function shouldIgnoreUrl (url) {
553+
function shouldIgnoreUrl (details) {
554+
// internal requests
555+
if (details.tabId === -1) {
556+
return true
557+
}
558+
554559
// Ensure host is well-formed (RFC 1035) and has a non-empty hostname
560+
try {
561+
const firstPartyUrl = urlParse(details.firstPartyUrl)
562+
if (!filterableProtocols.includes(firstPartyUrl.protocol)) {
563+
return true
564+
}
565+
} catch (e) {
566+
console.warn('Error parsing ' + details.firstPartyUrl)
567+
}
568+
555569
try {
556570
// TODO(bridiver) - handle RFS check and cancel http/https requests with 0 or > 255 length hostames
557-
const parsedUrl = urlParse(url)
571+
const parsedUrl = urlParse(details.url)
558572
if (filterableProtocols.includes(parsedUrl.protocol)) {
559573
return false
560574
}
561575
} catch (e) {
562-
console.warn('Error parsing ' + url)
576+
console.warn('Error parsing ' + details.url)
563577
}
564578
return true
565579
}

0 commit comments

Comments
 (0)