-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement "reduce language fingerprinting" #12234
Changes from all commits
b8d1761
6b8fd5a
4f0f398
331167e
56f7ca1
4995ccb
d256419
40b02ac
e3317c1
f90d4db
7be9858
9760e76
9adb38d
48e6b2b
7c2e354
932d9a7
89145c4
fc7510c
752b224
740aa95
6faf0ba
2101637
c207775
8bc4e75
171e2a5
b9241bd
d921376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ using brave_shields::features::kBraveDarkModeBlock; | |
using brave_shields::features::kBraveDomainBlock; | ||
using brave_shields::features::kBraveDomainBlock1PES; | ||
using brave_shields::features::kBraveExtensionNetworkBlocking; | ||
using brave_shields::features::kBraveReduceLanguage; | ||
using brave_shields::features::kCosmeticFilteringSyncLoad; | ||
|
||
using de_amp::features::kBraveDeAMP; | ||
|
@@ -146,6 +147,10 @@ constexpr char kBraveExtensionNetworkBlockingName[] = | |
constexpr char kBraveExtensionNetworkBlockingDescription[] = | ||
"Enable blocking for network requests initiated by extensions"; | ||
|
||
constexpr char kBraveReduceLanguageName[] = "Reduce language identifiability"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in all cases I think we should be clear that this is about accept-language There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well except it's more than that because the same setting controls font whitelisting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, seconding @pilgrim-brave , this setting controls both the explicit language preferneces in accept-language and navigator.languages, but also the implicit language preferences based on fonts available on the system There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still think |
||
constexpr char kBraveReduceLanguageDescription[] = | ||
"Reduce the identifiability of my language preferences"; | ||
|
||
constexpr char kCosmeticFilteringSyncLoadName[] = | ||
"Enable sync loading of cosmetic filter rules"; | ||
constexpr char kCosmeticFilteringSyncLoadDescription[] = | ||
|
@@ -499,6 +504,10 @@ const flags_ui::FeatureEntry::Choice kBraveSkusEnvChoices[] = { | |
flag_descriptions::kBraveExtensionNetworkBlockingName, \ | ||
flag_descriptions::kBraveExtensionNetworkBlockingDescription, kOsAll, \ | ||
FEATURE_VALUE_TYPE(kBraveExtensionNetworkBlocking)}, \ | ||
{"brave-reduce-language", \ | ||
flag_descriptions::kBraveReduceLanguageName, \ | ||
flag_descriptions::kBraveReduceLanguageDescription, kOsAll, \ | ||
FEATURE_VALUE_TYPE(kBraveReduceLanguage)}, \ | ||
{"brave-cosmetic-filtering-sync-load", \ | ||
flag_descriptions::kCosmeticFilteringSyncLoadName, \ | ||
flag_descriptions::kCosmeticFilteringSyncLoadDescription, kOsAll, \ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* Copyright (c) 2022 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/brave_shields/reduce_language_navigation_throttle.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "base/feature_list.h" | ||
#include "base/threading/thread_task_runner_handle.h" | ||
#include "brave/browser/brave_browser_process.h" | ||
#include "brave/components/brave_shields/browser/brave_farbling_service.h" | ||
#include "brave/components/brave_shields/browser/brave_shields_util.h" | ||
#include "brave/components/brave_shields/common/features.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "components/content_settings/core/browser/host_content_settings_map.h" | ||
#include "components/language/core/browser/language_prefs.h" | ||
#include "components/language/core/browser/pref_names.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "components/user_prefs/user_prefs.h" | ||
#include "content/public/browser/browser_context.h" | ||
#include "content/public/browser/browser_thread.h" | ||
#include "content/public/browser/navigation_handle.h" | ||
#include "content/public/browser/web_contents.h" | ||
#include "net/http/http_util.h" | ||
|
||
namespace brave_shields { | ||
|
||
// static | ||
std::unique_ptr<ReduceLanguageNavigationThrottle> | ||
ReduceLanguageNavigationThrottle::MaybeCreateThrottleFor( | ||
content::NavigationHandle* navigation_handle, | ||
HostContentSettingsMap* content_settings) { | ||
content::BrowserContext* context = | ||
navigation_handle->GetWebContents()->GetBrowserContext(); | ||
PrefService* pref_service = user_prefs::UserPrefs::Get(context); | ||
if (!IsReduceLanguageEnabledForProfile(pref_service)) | ||
return nullptr; | ||
return std::make_unique<ReduceLanguageNavigationThrottle>(navigation_handle, | ||
content_settings); | ||
} | ||
|
||
ReduceLanguageNavigationThrottle::ReduceLanguageNavigationThrottle( | ||
content::NavigationHandle* navigation_handle, | ||
HostContentSettingsMap* content_settings) | ||
: content::NavigationThrottle(navigation_handle), | ||
content_settings_(content_settings) { | ||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
} | ||
|
||
ReduceLanguageNavigationThrottle::~ReduceLanguageNavigationThrottle() { | ||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
} | ||
|
||
content::NavigationThrottle::ThrottleCheckResult | ||
ReduceLanguageNavigationThrottle::WillStartRequest() { | ||
UpdateHeaders(); | ||
return content::NavigationThrottle::PROCEED; | ||
} | ||
|
||
content::NavigationThrottle::ThrottleCheckResult | ||
ReduceLanguageNavigationThrottle::WillRedirectRequest() { | ||
UpdateHeaders(); | ||
return content::NavigationThrottle::PROCEED; | ||
} | ||
|
||
void ReduceLanguageNavigationThrottle::UpdateHeaders() { | ||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | ||
content::NavigationHandle* handle = navigation_handle(); | ||
GURL url = handle->GetURL(); | ||
content::BrowserContext* context = | ||
handle->GetWebContents()->GetBrowserContext(); | ||
PrefService* pref_service = user_prefs::UserPrefs::Get(context); | ||
|
||
if (!brave_shields::ShouldDoReduceLanguage(content_settings_, url, | ||
pref_service)) | ||
return; | ||
|
||
ControlType fingerprinting_control_type = | ||
brave_shields::GetFingerprintingControlType(content_settings_, url); | ||
|
||
// If fingerprint blocking is maximum, set Accept-Language header to | ||
// static value regardless of other preferences. | ||
if (fingerprinting_control_type == ControlType::BLOCK) { | ||
handle->SetRequestHeader(net::HttpRequestHeaders::kAcceptLanguage, | ||
"en-US,en"); | ||
return; | ||
} | ||
|
||
// If fingerprint blocking is default, compute Accept-Language header | ||
// based on user preferences. | ||
std::string languages = | ||
pref_service->Get(language::prefs::kAcceptLanguages)->GetString(); | ||
std::string first_language = language::GetFirstLanguage(languages); | ||
// Potentially add a fake q value after the language code. | ||
std::vector<std::string> q_values = {";q=0.5", ";q=0.6", ";q=0.7", | ||
pilgrim-brave marked this conversation as resolved.
Show resolved
Hide resolved
|
||
";q=0.8", ";q=0.9", ""}; | ||
std::mt19937_64 prng; | ||
auto* profile = Profile::FromBrowserContext(context); | ||
if (g_brave_browser_process->brave_farbling_service() | ||
->MakePseudoRandomGeneratorForURL( | ||
url, profile && !profile->IsOffTheRecord(), &prng)) { | ||
first_language += q_values[prng() % q_values.size()]; | ||
} | ||
handle->SetRequestHeader(net::HttpRequestHeaders::kAcceptLanguage, | ||
first_language); | ||
} | ||
|
||
const char* ReduceLanguageNavigationThrottle::GetNameForLogging() { | ||
return "ReduceLanguageNavigationThrottle"; | ||
} | ||
|
||
} // namespace brave_shields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have a more descriptive name for this. Maybe AcceptLanguageFingerprintingProtection or AcceptLanguageFarbling?