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

Commit 25c678e

Browse files
bridiverposix4e
authored andcommitted
ignore internal and extension generated requests
maybe fixes #5930 fix #5934 auditors: @bbondy
1 parent e6595a8 commit 25c678e

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
@@ -96,7 +96,7 @@ function registerForBeforeRequest (session, partition) {
9696
}
9797
}
9898

99-
if (shouldIgnoreUrl(details.url)) {
99+
if (shouldIgnoreUrl(details)) {
100100
cb({})
101101
return
102102
}
@@ -195,7 +195,7 @@ function registerForBeforeRedirect (session, partition) {
195195
// Note that onBeforeRedirect listener doesn't take a callback
196196
session.webRequest.onBeforeRedirect(function (details) {
197197
// Using an electron binary which isn't from Brave
198-
if (shouldIgnoreUrl(details.url)) {
198+
if (shouldIgnoreUrl(details)) {
199199
return
200200
}
201201
for (let i = 0; i < beforeRedirectFilteringFns.length; i++) {
@@ -222,7 +222,7 @@ function registerForBeforeSendHeaders (session, partition) {
222222

223223
session.webRequest.onBeforeSendHeaders(function (details, cb) {
224224
// Using an electron binary which isn't from Brave
225-
if (shouldIgnoreUrl(details.url)) {
225+
if (shouldIgnoreUrl(details)) {
226226
cb({})
227227
return
228228
}
@@ -295,7 +295,7 @@ function registerForHeadersReceived (session, partition) {
295295
// Note that onBeforeRedirect listener doesn't take a callback
296296
session.webRequest.onHeadersReceived(function (details, cb) {
297297
// Using an electron binary which isn't from Brave
298-
if (shouldIgnoreUrl(details.url)) {
298+
if (shouldIgnoreUrl(details)) {
299299
cb({})
300300
return
301301
}
@@ -558,16 +558,30 @@ function initForPartition (partition) {
558558

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

561-
function shouldIgnoreUrl (url) {
561+
function shouldIgnoreUrl (details) {
562+
// internal requests
563+
if (details.tabId === -1) {
564+
return true
565+
}
566+
562567
// Ensure host is well-formed (RFC 1035) and has a non-empty hostname
568+
try {
569+
const firstPartyUrl = urlParse(details.firstPartyUrl)
570+
if (!filterableProtocols.includes(firstPartyUrl.protocol)) {
571+
return true
572+
}
573+
} catch (e) {
574+
console.warn('Error parsing ' + details.firstPartyUrl)
575+
}
576+
563577
try {
564578
// TODO(bridiver) - handle RFS check and cancel http/https requests with 0 or > 255 length hostames
565-
const parsedUrl = urlParse(url)
579+
const parsedUrl = urlParse(details.url)
566580
if (filterableProtocols.includes(parsedUrl.protocol)) {
567581
return false
568582
}
569583
} catch (e) {
570-
console.warn('Error parsing ' + url)
584+
console.warn('Error parsing ' + details.url)
571585
}
572586
return true
573587
}

0 commit comments

Comments
 (0)