From 7177a3e7246cc420f48ec3e79dc1bfe84ed08c95 Mon Sep 17 00:00:00 2001 From: Brian Clifton Date: Tue, 21 Jun 2022 22:22:10 -0700 Subject: [PATCH 1/2] Revert `Implement "reduce language fingerprinting'` and follow ups Fixes https://github.com/brave/brave-browser/issues/23093 Unfixes https://github.com/brave/brave-browser/issues/20096 Unfixes https://github.com/brave/brave-browser/issues/816 Reverts https://github.com/brave/brave-core/pull/13807 Which fixed https://github.com/brave/brave-browser/issues/23489 Reverts https://github.com/brave/brave-core/pull/13205 Which fixed https://github.com/brave/brave-browser/issues/22605 Reverts https://github.com/brave/brave-core/pull/12234 Which fixed https://github.com/brave/brave-browser/issues/20096 and https://github.com/brave/brave-browser/issues/816 --- app/brave_settings_strings.grdp | 6 - browser/about_flags.cc | 9 - browser/brave_browser_process.h | 2 - browser/brave_browser_process_impl.cc | 9 - browser/brave_browser_process_impl.h | 4 - browser/brave_content_browser_client.cc | 22 +- browser/brave_content_browser_client.h | 3 + browser/brave_prefs_browsertest.cc | 2 - browser/brave_profile_prefs.cc | 3 - .../brave_shields_web_contents_observer.cc | 18 - .../reduce_language_navigation_throttle.cc | 116 --- .../reduce_language_navigation_throttle.h | 60 -- browser/brave_shields/sources.gni | 2 - .../api/settings_private/brave_prefs_util.cc | 2 - browser/farbling/BUILD.gn | 1 - ...avigator_languages_farbling_browsertest.cc | 266 ------ .../default_brave_shields_page.html | 8 +- ...ave_settings_localized_strings_provider.cc | 3 - .../platform/web_content_settings_client.h | 1 - .../blink/renderer/core/core_initializer.cc | 13 - .../execution_context/execution_context.cc | 68 +- .../execution_context/execution_context.h | 7 - .../renderer/core/frame/navigator_language.cc | 41 - .../renderer/core/frame/navigator_language.h | 33 - .../platform/fonts/font_fallback_list.cc | 41 - .../platform/fonts/font_fallback_list.h | 29 - components/brave_shields/browser/BUILD.gn | 3 - .../browser/brave_farbling_service.cc | 67 -- .../browser/brave_farbling_service.h | 42 - .../browser/brave_shields_util.cc | 32 - .../browser/brave_shields_util.h | 6 - .../brave_shields/common/brave_shields.mojom | 4 - components/brave_shields/common/features.cc | 3 - components/brave_shields/common/features.h | 1 - components/brave_shields/common/pref_names.cc | 1 - components/brave_shields/common/pref_names.h | 1 - .../brave_content_settings_agent_impl.cc | 8 - .../brave_content_settings_agent_impl.h | 6 - ...platform-fonts-font_fallback_list.cc.patch | 12 - test/base/testing_brave_browser_process.cc | 6 - test/base/testing_brave_browser_process.h | 1 - .../navigator/service-workers-languages.html | 25 - .../navigator/service-workers-languages.js | 11 - test/data/navigator/workers-languages.html | 28 - third_party/blink/renderer/BUILD.gn | 6 +- third_party/blink/renderer/DEPS | 3 - .../blink/renderer/brave_font_whitelist.cc | 800 ------------------ .../blink/renderer/brave_font_whitelist.h | 30 - .../renderer/brave_font_whitelist_unittest.cc | 7 +- 49 files changed, 21 insertions(+), 1851 deletions(-) delete mode 100644 browser/brave_shields/reduce_language_navigation_throttle.cc delete mode 100644 browser/brave_shields/reduce_language_navigation_throttle.h delete mode 100644 browser/farbling/brave_navigator_languages_farbling_browsertest.cc delete mode 100644 chromium_src/third_party/blink/renderer/core/core_initializer.cc delete mode 100644 chromium_src/third_party/blink/renderer/core/frame/navigator_language.cc delete mode 100644 chromium_src/third_party/blink/renderer/core/frame/navigator_language.h delete mode 100644 chromium_src/third_party/blink/renderer/platform/fonts/font_fallback_list.cc delete mode 100644 chromium_src/third_party/blink/renderer/platform/fonts/font_fallback_list.h delete mode 100644 components/brave_shields/browser/brave_farbling_service.cc delete mode 100644 components/brave_shields/browser/brave_farbling_service.h delete mode 100644 patches/third_party-blink-renderer-platform-fonts-font_fallback_list.cc.patch delete mode 100644 test/data/navigator/service-workers-languages.html delete mode 100644 test/data/navigator/service-workers-languages.js delete mode 100644 test/data/navigator/workers-languages.html delete mode 100644 third_party/blink/renderer/DEPS delete mode 100644 third_party/blink/renderer/brave_font_whitelist.cc delete mode 100644 third_party/blink/renderer/brave_font_whitelist.h diff --git a/app/brave_settings_strings.grdp b/app/brave_settings_strings.grdp index b87bdd8b7b60..f81927973c6c 100644 --- a/app/brave_settings_strings.grdp +++ b/app/brave_settings_strings.grdp @@ -147,12 +147,6 @@ Always visit original (non-AMP) page URLs, instead of Google's Accelerated Mobile Page versions - - Prevent sites from fingerprinting me based on my language preferences - - - Enabling this setting reduces how much web sites can learn about your language preferences. - Trackers & ads blocking diff --git a/browser/about_flags.cc b/browser/about_flags.cc index 968adddee7a0..58c5819e0e18 100644 --- a/browser/about_flags.cc +++ b/browser/about_flags.cc @@ -53,7 +53,6 @@ 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; @@ -140,10 +139,6 @@ constexpr char kBraveExtensionNetworkBlockingName[] = constexpr char kBraveExtensionNetworkBlockingDescription[] = "Enable blocking for network requests initiated by extensions"; -constexpr char kBraveReduceLanguageName[] = "Reduce language identifiability"; -constexpr char kBraveReduceLanguageDescription[] = - "Reduce the identifiability of my language preferences"; - constexpr char kCosmeticFilteringSyncLoadName[] = "Enable sync loading of cosmetic filter rules"; constexpr char kCosmeticFilteringSyncLoadDescription[] = @@ -517,10 +512,6 @@ 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, \ diff --git a/browser/brave_browser_process.h b/browser/brave_browser_process.h index ddd1ad55713f..206c83be3a40 100644 --- a/browser/brave_browser_process.h +++ b/browser/brave_browser_process.h @@ -21,7 +21,6 @@ namespace brave { class BraveReferralsService; class BraveP3AService; -class BraveFarblingService; } // namespace brave namespace brave_component_updater { @@ -105,7 +104,6 @@ class BraveBrowserProcess { speedreader_rewriter_service() = 0; #endif virtual brave_ads::ResourceComponent* resource_component() = 0; - virtual brave::BraveFarblingService* brave_farbling_service() = 0; }; extern BraveBrowserProcess* g_brave_browser_process; diff --git a/browser/brave_browser_process_impl.cc b/browser/brave_browser_process_impl.cc index 6309922852d6..6175ce648684 100644 --- a/browser/brave_browser_process_impl.cc +++ b/browser/brave_browser_process_impl.cc @@ -5,7 +5,6 @@ #include "brave/browser/brave_browser_process_impl.h" -#include #include #include "base/bind.h" @@ -26,7 +25,6 @@ #include "brave/components/brave_shields/browser/ad_block_regional_service_manager.h" #include "brave/components/brave_shields/browser/ad_block_service.h" #include "brave/components/brave_shields/browser/ad_block_subscription_service_manager.h" -#include "brave/components/brave_shields/browser/brave_farbling_service.h" #include "brave/components/brave_shields/browser/https_everywhere_service.h" #include "brave/components/brave_sync/network_time_helper.h" #include "brave/components/constants/pref_names.h" @@ -48,7 +46,6 @@ #include "content/public/browser/child_process_security_policy.h" #include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/shared_url_loader_factory.h" -#include "url/gurl.h" #if BUILDFLAG(ENABLE_BRAVE_REFERRALS) #include "brave/components/brave_referrals/browser/brave_referrals_service.h" @@ -383,9 +380,3 @@ ipfs::BraveIpfsClientUpdater* BraveBrowserProcessImpl::ipfs_client_updater() { return ipfs_client_updater_.get(); } #endif // BUILDFLAG(ENABLE_IPFS) - -brave::BraveFarblingService* BraveBrowserProcessImpl::brave_farbling_service() { - if (!brave_farbling_service_) - brave_farbling_service_ = std::make_unique(); - return brave_farbling_service_.get(); -} diff --git a/browser/brave_browser_process_impl.h b/browser/brave_browser_process_impl.h index b35d968234a2..65fdeacaaec9 100644 --- a/browser/brave_browser_process_impl.h +++ b/browser/brave_browser_process_impl.h @@ -23,7 +23,6 @@ namespace brave { class BraveReferralsService; class BraveP3AService; class HistogramsBraveizer; -class BraveFarblingService; } // namespace brave namespace brave_component_updater { @@ -116,7 +115,6 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess, speedreader::SpeedreaderRewriterService* speedreader_rewriter_service() override; #endif - brave::BraveFarblingService* brave_farbling_service() override; private: // BrowserProcessImpl overrides: @@ -175,8 +173,6 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess, speedreader_rewriter_service_; #endif - std::unique_ptr brave_farbling_service_; - SEQUENCE_CHECKER(sequence_checker_); }; diff --git a/browser/brave_content_browser_client.cc b/browser/brave_content_browser_client.cc index 3e976dcea62d..b2d43105f065 100644 --- a/browser/brave_content_browser_client.cc +++ b/browser/brave_content_browser_client.cc @@ -12,12 +12,12 @@ #include "base/bind.h" #include "base/json/json_reader.h" +#include "base/rand_util.h" #include "base/strings/strcat.h" #include "base/system/sys_info.h" #include "brave/browser/brave_browser_main_extra_parts.h" #include "brave/browser/brave_browser_process.h" #include "brave/browser/brave_shields/brave_shields_web_contents_observer.h" -#include "brave/browser/brave_shields/reduce_language_navigation_throttle.h" #include "brave/browser/brave_wallet/brave_wallet_context_utils.h" #include "brave/browser/brave_wallet/brave_wallet_provider_delegate_impl.h" #include "brave/browser/brave_wallet/brave_wallet_service_factory.h" @@ -44,7 +44,6 @@ #include "brave/components/brave_search/common/brave_search_fallback.mojom.h" #include "brave/components/brave_search/common/brave_search_utils.h" #include "brave/components/brave_shields/browser/ad_block_service.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/browser/domain_block_navigation_throttle.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" @@ -378,7 +377,9 @@ void MaybeBindSkusSdkImpl( } // namespace -BraveContentBrowserClient::BraveContentBrowserClient() {} +BraveContentBrowserClient::BraveContentBrowserClient() + : session_token_(base::RandUint64()), + incognito_session_token_(base::RandUint64()) {} BraveContentBrowserClient::~BraveContentBrowserClient() {} @@ -653,9 +654,11 @@ void BraveContentBrowserClient::AppendExtraCommandLineSwitches( Profile* profile = process ? Profile::FromBrowserContext(process->GetBrowserContext()) : nullptr; - session_token = - g_brave_browser_process->brave_farbling_service()->session_token( - profile && !profile->IsOffTheRecord()); + if (profile && !profile->IsOffTheRecord()) { + session_token = session_token_; + } else { + session_token = incognito_session_token_; + } } command_line->AppendSwitchASCII("brave_session_token", base::NumberToString(session_token)); @@ -956,13 +959,6 @@ BraveContentBrowserClient::CreateThrottlesForNavigation( g_browser_process->GetApplicationLocale())) throttles.push_back(std::move(domain_block_navigation_throttle)); - if (std::unique_ptr - reduce_language_navigation_throttle = brave_shields:: - ReduceLanguageNavigationThrottle::MaybeCreateThrottleFor( - handle, HostContentSettingsMapFactory::GetForProfile( - Profile::FromBrowserContext(context)))) - throttles.push_back(std::move(reduce_language_navigation_throttle)); - return throttles; } diff --git a/browser/brave_content_browser_client.h b/browser/brave_content_browser_client.h index 95ef08c282c7..79bff06f2285 100644 --- a/browser/brave_content_browser_client.h +++ b/browser/brave_content_browser_client.h @@ -147,6 +147,9 @@ class BraveContentBrowserClient : public ChromeContentBrowserClient { blink::UserAgentMetadata GetUserAgentMetadata() override; private: + uint64_t session_token_; + uint64_t incognito_session_token_; + void OnAllowGoogleAuthChanged(); std::unique_ptr diff --git a/browser/brave_prefs_browsertest.cc b/browser/brave_prefs_browsertest.cc index 473ee5bac6fc..d2b06f6651ec 100644 --- a/browser/brave_prefs_browsertest.cc +++ b/browser/brave_prefs_browsertest.cc @@ -81,8 +81,6 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) { brave_shields::prefs::kTwitterEmbedControlType)); EXPECT_FALSE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( brave_shields::prefs::kLinkedInEmbedControlType)); - EXPECT_TRUE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( - brave_shields::prefs::kReduceLanguageEnabled)); #if BUILDFLAG(ENABLE_BRAVE_WAYBACK_MACHINE) EXPECT_TRUE(chrome_test_utils::GetProfile(this)->GetPrefs()->GetBoolean( kWebTorrentEnabled)); diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index c7ce9e204942..e17e0e80e36f 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -23,7 +23,6 @@ #include "brave/components/brave_search/browser/brave_search_default_host.h" #include "brave/components/brave_search/common/brave_search_utils.h" #include "brave/components/brave_search_conversion/utils.h" -#include "brave/components/brave_shields/browser/brave_farbling_service.h" #include "brave/components/brave_shields/browser/brave_shields_p3a.h" #include "brave/components/brave_shields/common/pref_names.h" #include "brave/components/brave_sync/brave_sync_prefs.h" @@ -456,8 +455,6 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { policy::policy_prefs::kIsolatedAppsDeveloperModeAllowed, base::Value(false)); - BraveFarblingService::RegisterProfilePrefs(registry); - RegisterProfilePrefsForMigration(registry); #if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO) diff --git a/browser/brave_shields/brave_shields_web_contents_observer.cc b/browser/brave_shields/brave_shields_web_contents_observer.cc index f2884ee0bd8b..ba7fb1dbe103 100644 --- a/browser/brave_shields/brave_shields_web_contents_observer.cc +++ b/browser/brave_shields/brave_shields_web_contents_observer.cc @@ -15,13 +15,11 @@ #include "brave/components/brave_shields/browser/brave_shields_util.h" #include "brave/components/brave_shields/common/brave_shield_constants.h" #include "brave/components/brave_shields/common/features.h" -#include "brave/components/brave_shields/common/pref_names.h" #include "brave/components/constants/pref_names.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/renderer_configuration.mojom.h" #include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_service.h" -#include "components/user_prefs/user_prefs.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/navigation_handle.h" #include "content/public/browser/render_frame_host.h" @@ -72,14 +70,6 @@ void BraveShieldsWebContentsObserver::RenderFrameCreated(RenderFrameHost* rfh) { GetBraveShieldsRemote(rfh)->SetAllowScriptsFromOriginsOnce( allowed_script_origins_); } - if (rfh) { - if (content::BrowserContext* context = rfh->GetBrowserContext()) { - if (PrefService* pref_service = user_prefs::UserPrefs::Get(context)) { - GetBraveShieldsRemote(rfh)->SetReduceLanguageEnabled( - brave_shields::IsReduceLanguageEnabledForProfile(pref_service)); - } - } - } } void BraveShieldsWebContentsObserver::RenderFrameDeleted(RenderFrameHost* rfh) { @@ -252,14 +242,6 @@ void BraveShieldsWebContentsObserver::ReadyToCommitNavigation( observer->GetBraveShieldsRemote(rfh) ->SetAllowScriptsFromOriginsOnce( observer->allowed_script_origins_); - if (content::BrowserContext* context = rfh->GetBrowserContext()) { - if (PrefService* pref_service = - user_prefs::UserPrefs::Get(context)) { - observer->GetBraveShieldsRemote(rfh)->SetReduceLanguageEnabled( - brave_shields::IsReduceLanguageEnabledForProfile( - pref_service)); - } - } }, base::Unretained(this))); } diff --git a/browser/brave_shields/reduce_language_navigation_throttle.cc b/browser/brave_shields/reduce_language_navigation_throttle.cc deleted file mode 100644 index bbed21544b4e..000000000000 --- a/browser/brave_shields/reduce_language_navigation_throttle.cc +++ /dev/null @@ -1,116 +0,0 @@ -/* 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 -#include - -#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_request_headers.h" -#include "net/http/http_util.h" - -namespace brave_shields { - -// static -std::unique_ptr -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(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); - // Add a fake q value after the language code. - std::vector q_values = {";q=0.5", ";q=0.6", ";q=0.7", ";q=0.8", - ";q=0.9"}; - brave::FarblingPRNG 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 diff --git a/browser/brave_shields/reduce_language_navigation_throttle.h b/browser/brave_shields/reduce_language_navigation_throttle.h deleted file mode 100644 index 29ad25737271..000000000000 --- a/browser/brave_shields/reduce_language_navigation_throttle.h +++ /dev/null @@ -1,60 +0,0 @@ -/* 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/. */ - -#ifndef BRAVE_BROWSER_BRAVE_SHIELDS_REDUCE_LANGUAGE_NAVIGATION_THROTTLE_H_ -#define BRAVE_BROWSER_BRAVE_SHIELDS_REDUCE_LANGUAGE_NAVIGATION_THROTTLE_H_ - -#include -#include -#include - -#include "base/memory/weak_ptr.h" -#include "brave/components/brave_shields/browser/brave_shields_util.h" -#include "content/public/browser/navigation_throttle.h" -#include "url/gurl.h" - -class HostContentSettingsMap; - -namespace content { -class NavigationHandle; -class WebContents; -} // namespace content - -namespace brave_shields { - -class ReduceLanguageNavigationThrottle : public content::NavigationThrottle { - public: - explicit ReduceLanguageNavigationThrottle( - content::NavigationHandle* navigation_handle, - HostContentSettingsMap* content_settings); - ~ReduceLanguageNavigationThrottle() override; - - ReduceLanguageNavigationThrottle(const ReduceLanguageNavigationThrottle&) = - delete; - ReduceLanguageNavigationThrottle& operator=( - const ReduceLanguageNavigationThrottle&) = delete; - - static std::unique_ptr - MaybeCreateThrottleFor(content::NavigationHandle* navigation_handle, - HostContentSettingsMap* content_settings); - - // content::NavigationThrottle implementation: - content::NavigationThrottle::ThrottleCheckResult WillStartRequest() override; - content::NavigationThrottle::ThrottleCheckResult WillRedirectRequest() - override; - const char* GetNameForLogging() override; - - private: - HostContentSettingsMap* content_settings_ = nullptr; - - void UpdateHeaders(); - - base::WeakPtrFactory weak_ptr_factory_{ - this}; -}; - -} // namespace brave_shields - -#endif // BRAVE_BROWSER_BRAVE_SHIELDS_REDUCE_LANGUAGE_NAVIGATION_THROTTLE_H_ diff --git a/browser/brave_shields/sources.gni b/browser/brave_shields/sources.gni index ddb31f94395b..82b2e4286528 100644 --- a/browser/brave_shields/sources.gni +++ b/browser/brave_shields/sources.gni @@ -14,8 +14,6 @@ brave_browser_brave_shields_sources = [ "//brave/browser/brave_shields/brave_shields_web_contents_observer.h", "//brave/browser/brave_shields/https_everywhere_component_installer.cc", "//brave/browser/brave_shields/https_everywhere_component_installer.h", - "//brave/browser/brave_shields/reduce_language_navigation_throttle.cc", - "//brave/browser/brave_shields/reduce_language_navigation_throttle.h", ] brave_browser_brave_shields_deps = [ diff --git a/browser/extensions/api/settings_private/brave_prefs_util.cc b/browser/extensions/api/settings_private/brave_prefs_util.cc index 1eba63ac44d6..1866f5d8fd8a 100644 --- a/browser/extensions/api/settings_private/brave_prefs_util.cc +++ b/browser/extensions/api/settings_private/brave_prefs_util.cc @@ -111,8 +111,6 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetAllowlistedKeys() { settings_api::PrefType::PREF_TYPE_BOOLEAN; (*s_brave_allowlist)[brave_shields::prefs::kLinkedInEmbedControlType] = settings_api::PrefType::PREF_TYPE_BOOLEAN; - (*s_brave_allowlist)[brave_shields::prefs::kReduceLanguageEnabled] = - settings_api::PrefType::PREF_TYPE_BOOLEAN; // Rewards/Ads prefs (*s_brave_allowlist)[ads::prefs::kEnabled] = diff --git a/browser/farbling/BUILD.gn b/browser/farbling/BUILD.gn index 4a4ddc46cd79..e2289c7ac7d9 100644 --- a/browser/farbling/BUILD.gn +++ b/browser/farbling/BUILD.gn @@ -15,7 +15,6 @@ if (!is_android) { "brave_navigator_devicememory_farbling_browsertest.cc", "brave_navigator_hardwareconcurrency_farbling_browsertest.cc", "brave_navigator_keyboard_api_browsertest.cc", - "brave_navigator_languages_farbling_browsertest.cc", "brave_navigator_plugins_farbling_browsertest.cc", "brave_navigator_useragent_farbling_browsertest.cc", "brave_offscreencanvas_farbling_browsertest.cc", diff --git a/browser/farbling/brave_navigator_languages_farbling_browsertest.cc b/browser/farbling/brave_navigator_languages_farbling_browsertest.cc deleted file mode 100644 index 07a0277cfbaa..000000000000 --- a/browser/farbling/brave_navigator_languages_farbling_browsertest.cc +++ /dev/null @@ -1,266 +0,0 @@ -/* 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 "base/path_service.h" -#include "base/strings/stringprintf.h" -#include "base/test/thread_test_helper.h" -#include "brave/browser/brave_browser_process.h" -#include "brave/browser/brave_content_browser_client.h" -#include "brave/browser/extensions/brave_base_local_data_files_browsertest.h" -#include "brave/components/brave_component_updater/browser/local_data_files_service.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 "brave/components/constants/brave_paths.h" -#include "brave/components/constants/pref_names.h" -#include "chrome/browser/content_settings/host_content_settings_map_factory.h" -#include "chrome/browser/extensions/extension_browsertest.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/common/chrome_content_client.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/base/ui_test_utils.h" -#include "components/language/core/browser/pref_names.h" -#include "components/network_session_configurator/common/network_switches.h" -#include "components/permissions/permission_request.h" -#include "components/prefs/pref_service.h" -#include "components/user_prefs/user_prefs.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/renderer/render_frame.h" -#include "content/public/test/browser_test.h" -#include "content/public/test/browser_test_utils.h" -#include "net/dns/mock_host_resolver.h" -#include "third_party/blink/public/web/web_local_frame.h" -#include "third_party/blink/renderer/core/frame/local_dom_window.h" -#include "third_party/blink/renderer/core/frame/navigator.h" -#include "third_party/blink/renderer/core/frame/navigator_language.h" - -using brave_shields::ControlType; -using content::TitleWatcher; - -namespace { -const char kNavigatorLanguagesScript[] = "navigator.languages.toString()"; -const uint64_t kTestingSessionToken = 12345; -} // namespace - -class BraveNavigatorLanguagesFarblingBrowserTest : public InProcessBrowserTest { - public: - BraveNavigatorLanguagesFarblingBrowserTest() - : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { - brave::RegisterPathProvider(); - base::FilePath test_data_dir; - base::PathService::Get(brave::DIR_TEST_DATA, &test_data_dir); - https_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_TEST_NAMES); - https_server_.ServeFilesFromDirectory(test_data_dir); - https_server_.RegisterRequestMonitor(base::BindRepeating( - &BraveNavigatorLanguagesFarblingBrowserTest::MonitorHTTPRequest, - base::Unretained(this))); - EXPECT_TRUE(https_server_.Start()); - } - - BraveNavigatorLanguagesFarblingBrowserTest( - const BraveNavigatorLanguagesFarblingBrowserTest&) = delete; - BraveNavigatorLanguagesFarblingBrowserTest& operator=( - const BraveNavigatorLanguagesFarblingBrowserTest&) = delete; - - ~BraveNavigatorLanguagesFarblingBrowserTest() override {} - - void SetUpOnMainThread() override { - InProcessBrowserTest::SetUpOnMainThread(); - - content_client_.reset(new ChromeContentClient); - content::SetContentClient(content_client_.get()); - browser_content_client_.reset(new BraveContentBrowserClient()); - content::SetBrowserClientForTesting(browser_content_client_.get()); - g_brave_browser_process->brave_farbling_service() - ->set_session_tokens_for_testing(kTestingSessionToken, - kTestingSessionToken); - - host_resolver()->AddRule("*", "127.0.0.1"); - } - - void TearDown() override { - browser_content_client_.reset(); - content_client_.reset(); - } - - protected: - base::test::ScopedFeatureList feature_list_; - net::EmbeddedTestServer https_server_; - - HostContentSettingsMap* content_settings() { - return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); - } - - void AllowFingerprinting(std::string domain) { - brave_shields::SetFingerprintingControlType( - content_settings(), ControlType::ALLOW, - https_server_.GetURL(domain, "/")); - } - - void BlockFingerprinting(std::string domain) { - brave_shields::SetFingerprintingControlType( - content_settings(), ControlType::BLOCK, - https_server_.GetURL(domain, "/")); - } - - void SetFingerprintingDefault(std::string domain) { - brave_shields::SetFingerprintingControlType( - content_settings(), ControlType::DEFAULT, - https_server_.GetURL(domain, "/")); - } - - content::WebContents* web_contents() { - return browser()->tab_strip_model()->GetActiveWebContents(); - } - - bool NavigateToURLUntilLoadStop(const GURL& url) { - EXPECT_TRUE(ui_test_utils::NavigateToURL(browser(), url)); - return WaitForLoadStop(web_contents()); - } - - void SetAcceptLanguages(const std::string& accept_languages) { - content::BrowserContext* context = - static_cast(browser()->profile()); - PrefService* prefs = user_prefs::UserPrefs::Get(context); - prefs->Set(language::prefs::kSelectedLanguages, - base::Value(accept_languages)); - } - - void MonitorHTTPRequest(const net::test_server::HttpRequest& request) { - if (request.relative_url != "/simple.html") - return; - if (expected_http_accept_language_.empty()) - return; - EXPECT_EQ(request.headers.at("accept-language"), - expected_http_accept_language_); - } - - void SetExpectedHTTPAcceptLanguage( - const std::string& expected_http_accept_language) { - expected_http_accept_language_ = expected_http_accept_language; - } - - private: - std::unique_ptr content_client_; - std::unique_ptr browser_content_client_; - std::string expected_http_accept_language_; -}; - -// Tests results of farbling known values -IN_PROC_BROWSER_TEST_F(BraveNavigatorLanguagesFarblingBrowserTest, - FarbleLanguages) { - std::string domain1 = "b.test"; - std::string domain2 = "d.test"; - GURL url1 = https_server_.GetURL(domain1, "/simple.html"); - GURL url2 = https_server_.GetURL(domain2, "/simple.html"); - // Farbling level: off - AllowFingerprinting(domain1); - NavigateToURLUntilLoadStop(url1); - std::string testing_languages = "en-US,en,es,la"; - SetAcceptLanguages(testing_languages); - EXPECT_EQ(testing_languages, - EvalJs(web_contents(), kNavigatorLanguagesScript)); - AllowFingerprinting(domain2); - NavigateToURLUntilLoadStop(url2); - EXPECT_EQ(testing_languages, - EvalJs(web_contents(), kNavigatorLanguagesScript)); - - // Farbling level: default - SetFingerprintingDefault(domain1); - NavigateToURLUntilLoadStop(url1); - std::string standard_languages = "en-US"; - EXPECT_EQ(standard_languages, - EvalJs(web_contents(), kNavigatorLanguagesScript)); - SetFingerprintingDefault(domain2); - NavigateToURLUntilLoadStop(url2); - EXPECT_EQ(standard_languages, - EvalJs(web_contents(), kNavigatorLanguagesScript)); - - // Farbling level: maximum - BlockFingerprinting(domain1); - NavigateToURLUntilLoadStop(url1); - std::string strict_languages = "en-US,en"; - EXPECT_EQ(strict_languages, - EvalJs(web_contents(), kNavigatorLanguagesScript)); - BlockFingerprinting(domain2); - NavigateToURLUntilLoadStop(url2); - EXPECT_EQ(strict_languages, - EvalJs(web_contents(), kNavigatorLanguagesScript)); -} - -// Tests that web workers inherit the farbled navigator.languages -IN_PROC_BROWSER_TEST_F(BraveNavigatorLanguagesFarblingBrowserTest, - FarbleLanguagesWebWorker) { - std::u16string expected_title(u"pass"); - std::string domain = "b.test"; - GURL url = https_server_.GetURL(domain, "/navigator/workers-languages.html"); - - // Farbling level: off - AllowFingerprinting(domain); - NavigateToURLUntilLoadStop(url); - TitleWatcher watcher1(web_contents(), expected_title); - EXPECT_EQ(expected_title, watcher1.WaitAndGetTitle()); - - // Farbling level: default - SetFingerprintingDefault(domain); - NavigateToURLUntilLoadStop(url); - TitleWatcher watcher2(web_contents(), expected_title); - EXPECT_EQ(expected_title, watcher2.WaitAndGetTitle()); - - // Farbling level: maximum - BlockFingerprinting(domain); - NavigateToURLUntilLoadStop(url); - TitleWatcher watcher3(web_contents(), expected_title); - EXPECT_EQ(expected_title, watcher3.WaitAndGetTitle()); -} - -// Tests that service workers inherit the farbled navigator.languages -IN_PROC_BROWSER_TEST_F(BraveNavigatorLanguagesFarblingBrowserTest, - FarbleLanguagesServiceWorker) { - std::u16string expected_title(u"pass"); - std::string domain = "b.test"; - GURL url = - https_server_.GetURL(domain, "/navigator/service-workers-languages.html"); - // Farbling level: default - SetFingerprintingDefault(domain); - NavigateToURLUntilLoadStop(url); - TitleWatcher watcher2(web_contents(), expected_title); - EXPECT_EQ(expected_title, watcher2.WaitAndGetTitle()); -} - -// Tests results of farbling user agent -IN_PROC_BROWSER_TEST_F(BraveNavigatorLanguagesFarblingBrowserTest, - FarbleHTTPAcceptLanguage) { - std::string domain_b = "b.test"; - std::string domain_d = "d.test"; - GURL url_b = https_server_.GetURL(domain_b, "/simple.html"); - GURL url_d = https_server_.GetURL(domain_d, "/simple.html"); - SetAcceptLanguages("la,es,en"); - - // Farbling level: off - // HTTP Accept-Language header should not be farbled. - AllowFingerprinting(domain_b); - SetExpectedHTTPAcceptLanguage("la,es;q=0.9,en;q=0.8"); - NavigateToURLUntilLoadStop(url_b); - AllowFingerprinting(domain_d); - NavigateToURLUntilLoadStop(url_d); - - // Farbling level: default - // HTTP Accept-Language header should be farbled by domain. - SetFingerprintingDefault(domain_b); - SetExpectedHTTPAcceptLanguage("la;q=0.7"); - NavigateToURLUntilLoadStop(url_b); - SetExpectedHTTPAcceptLanguage("la;q=0.8"); - SetFingerprintingDefault(domain_d); - NavigateToURLUntilLoadStop(url_d); - - // Farbling level: maximum - // HTTP Accept-Language header should be farbled but the same across domains. - BlockFingerprinting(domain_b); - SetExpectedHTTPAcceptLanguage("en-US,en"); - NavigateToURLUntilLoadStop(url_b); - BlockFingerprinting(domain_d); - NavigateToURLUntilLoadStop(url_d); -} diff --git a/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html b/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html index 6d3de027e8bc..6c0a26e41211 100644 --- a/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html +++ b/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html @@ -50,12 +50,6 @@ label="$i18n{deAmpSettingLabel}" sub-label="$i18n{deAmpSettingSubLabel}"> - -
$i18n{adControlLabel}