From 327fcc7433b266b2d4f3437cfe021d35541696bd Mon Sep 17 00:00:00 2001 From: yan Date: Tue, 1 Mar 2016 17:05:22 -0800 Subject: [PATCH] Remove brave from the user agent string Partial fix for #242 Auditors: @bbondy --- app/filtering.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/filtering.js b/app/filtering.js index 99ea863fbcc..5ce2379eeed 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -124,15 +124,24 @@ function registerForBeforeSendHeaders (session) { // For efficiency, avoid calculating sendDNT on every request. This means the // browser must be restarted for changes to take effect. const sendDNT = getSetting(settings.DO_NOT_TRACK) + let spoofedUserAgent + const braveRegex = new RegExp('brave/.+? ', 'gi') + session.webRequest.onBeforeSendHeaders(function (details, cb) { + let requestHeaders = details.requestHeaders + + // To minimize fingerprintability, remove Brave from the UA string. + // This can be removed once https://github.com/atom/electron/issues/3602 is + // resolved + spoofedUserAgent = spoofedUserAgent || requestHeaders['User-Agent'].replace(braveRegex, '') + requestHeaders['User-Agent'] = spoofedUserAgent + // Using an electron binary which isn't from Brave if (!details.firstPartyUrl) { cb({}) return } - let requestHeaders = details.requestHeaders - let customHeaders = false for (let i = 0; i < beforeSendHeadersFilteringFns.length; i++) { let results = beforeSendHeadersFilteringFns[i](details) if (!module.exports.isResourceEnabled(results.resourceName)) { @@ -144,7 +153,6 @@ function registerForBeforeSendHeaders (session) { } if (results.customCookie) { requestHeaders.Cookie = results.customCookie - customHeaders = true } } @@ -155,23 +163,16 @@ function registerForBeforeSendHeaders (session) { // Clear cookie and referer on third-party requests if (requestHeaders['Cookie']) { requestHeaders['Cookie'] = undefined - customHeaders = true } if (requestHeaders['Referer'] && !refererExceptions.includes(hostname)) { requestHeaders['Referer'] = undefined - customHeaders = true } } if (sendDNT) { requestHeaders['DNT'] = '1' - customHeaders = true } - if (customHeaders) { - cb({ requestHeaders }) - } else { - cb({}) - } + cb({ requestHeaders }) }) }