From: csagan5 <32685696+csagan5@users.noreply.github.com> Date: Thu, 22 Jul 2021 23:10:52 +0200 Subject: Client hints overrides Disable critical client hints and network early hints Use Google Chrome branding for client hints License: GPL-3.0-only - https://spdx.org/licenses/GPL-3.0-only.html --- components/embedder_support/user_agent_utils.cc | 4 +--- content/browser/client_hints/client_hints.cc | 15 ++++++++++----- .../browser/loader/navigation_url_loader_impl.cc | 5 +++++ .../about_flags_cc/Client-hints-overrides.inc | 9 +++++++++ .../common/features_cc/Client-hints-overrides.inc | 1 + .../cpp/features_cc/Client-hints-overrides.inc | 1 + net/http/http_network_transaction.cc | 1 + services/network/public/cpp/client_hints.cc | 1 + .../blink/common/client_hints/client_hints.cc | 6 ++++-- .../common/client_hints/enabled_client_hints.cc | 6 ++++++ .../blink/renderer/core/frame/navigator_ua.idl | 4 +++- .../renderer/core/frame/navigator_ua_data.cc | 1 + .../renderer/core/frame/navigator_ua_data.idl | 5 ++++- .../renderer/core/loader/base_fetch_context.cc | 6 ++++-- .../platform/runtime_enabled_features.json5 | 5 +++++ 15 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 cromite_flags/chrome/browser/about_flags_cc/Client-hints-overrides.inc create mode 100644 cromite_flags/content/common/features_cc/Client-hints-overrides.inc create mode 100644 cromite_flags/services/network/public/cpp/features_cc/Client-hints-overrides.inc diff --git a/components/embedder_support/user_agent_utils.cc b/components/embedder_support/user_agent_utils.cc --- a/components/embedder_support/user_agent_utils.cc +++ b/components/embedder_support/user_agent_utils.cc @@ -187,9 +187,7 @@ const blink::UserAgentBrandList GetUserAgentBrandList( bool parse_result = base::StringToInt(major_version, &major_version_number); DCHECK(parse_result); std::optional brand; -#if !BUILDFLAG(CHROMIUM_BRANDING) - brand = version_info::GetProductName(); -#endif + brand = "Google Chrome"; std::optional maybe_brand_override = base::GetFieldTrialParamValueByFeature(features::kGreaseUACH, "brand_override"); diff --git a/content/browser/client_hints/client_hints.cc b/content/browser/client_hints/client_hints.cc --- a/content/browser/client_hints/client_hints.cc +++ b/content/browser/client_hints/client_hints.cc @@ -60,6 +60,7 @@ #include "third_party/blink/public/common/permissions_policy/origin_with_possible_wildcards.h" #include "third_party/blink/public/common/permissions_policy/permissions_policy.h" #include "third_party/blink/public/common/user_agent/user_agent_metadata.h" +#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "ui/display/display.h" #include "ui/display/screen.h" #include "url/origin.h" @@ -722,7 +723,8 @@ void UpdateNavigationRequestClientUaHeadersImpl( // value, disable them. This overwrites previous decision from UI. disable_due_to_custom_ua = !ua_metadata.has_value(); } - + if (!blink::RuntimeEnabledFeatures::UserAgentClientHintEnabled()) + disable_due_to_custom_ua = true; if (!disable_due_to_custom_ua) { if (!ua_metadata.has_value()) ua_metadata = delegate->GetUserAgentMetadata(); @@ -904,10 +906,12 @@ void AddRequestClientHintsHeaders( AddEctHeader(headers, network_quality_tracker, url); } - UpdateNavigationRequestClientUaHeadersImpl( - delegate, is_ua_override_on, frame_tree_node, - ClientUaHeaderCallType::kDuringCreation, headers, container_policy, - request_url, data); + if (blink::RuntimeEnabledFeatures::UserAgentClientHintEnabled()) { + UpdateNavigationRequestClientUaHeadersImpl( + delegate, is_ua_override_on, frame_tree_node, + ClientUaHeaderCallType::kDuringCreation, headers, container_policy, + request_url, data); + } if (ShouldAddClientHint(data, WebClientHintsType::kPrefersColorScheme)) { AddPrefersColorSchemeHeader(headers, frame_tree_node); @@ -1001,6 +1005,7 @@ ParseAndPersistAcceptCHForNavigation( BrowserContext* context, ClientHintsControllerDelegate* delegate, FrameTreeNode* frame_tree_node) { + if ((true)) return std::nullopt; DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK(context); DCHECK(parsed_headers); diff --git a/content/browser/loader/navigation_url_loader_impl.cc b/content/browser/loader/navigation_url_loader_impl.cc --- a/content/browser/loader/navigation_url_loader_impl.cc +++ b/content/browser/loader/navigation_url_loader_impl.cc @@ -1206,6 +1206,11 @@ void NavigationURLLoaderImpl::OnAcceptCHFrameReceived( return; } + if (!base::FeatureList::IsEnabled(network::features::kAcceptCHFrame)) { + std::move(callback).Run(net::OK); + return; + } + LogAcceptCHFrameStatus(AcceptCHFrameRestart::kFramePresent); // Given that this is happening in the middle of navigation, there should diff --git a/cromite_flags/chrome/browser/about_flags_cc/Client-hints-overrides.inc b/cromite_flags/chrome/browser/about_flags_cc/Client-hints-overrides.inc new file mode 100644 --- /dev/null +++ b/cromite_flags/chrome/browser/about_flags_cc/Client-hints-overrides.inc @@ -0,0 +1,9 @@ +#ifdef FLAG_SECTION + + {"enable-ua-client-hint", + "Enable UA client hint", + "Allow sending base low entropy client hints as " + "UA, UAMobile and UAPlatform for compatibility", kOsAll, + FEATURE_VALUE_TYPE(blink::features::kUserAgentClientHint)}, + +#endif diff --git a/cromite_flags/content/common/features_cc/Client-hints-overrides.inc b/cromite_flags/content/common/features_cc/Client-hints-overrides.inc new file mode 100644 --- /dev/null +++ b/cromite_flags/content/common/features_cc/Client-hints-overrides.inc @@ -0,0 +1 @@ +SET_CROMITE_FEATURE_DISABLED(kCriticalClientHint); diff --git a/cromite_flags/services/network/public/cpp/features_cc/Client-hints-overrides.inc b/cromite_flags/services/network/public/cpp/features_cc/Client-hints-overrides.inc new file mode 100644 --- /dev/null +++ b/cromite_flags/services/network/public/cpp/features_cc/Client-hints-overrides.inc @@ -0,0 +1 @@ +SET_CROMITE_FEATURE_DISABLED(kAcceptCHFrame); diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -107,6 +107,7 @@ const size_t kMaxRestarts = 32; // Returns true when Early Hints are allowed on the given protocol. bool EarlyHintsAreAllowedOn(HttpConnectionInfo connection_info) { + if ((true)) return false; switch (connection_info) { case HttpConnectionInfo::kHTTP0_9: case HttpConnectionInfo::kHTTP1_0: diff --git a/services/network/public/cpp/client_hints.cc b/services/network/public/cpp/client_hints.cc --- a/services/network/public/cpp/client_hints.cc +++ b/services/network/public/cpp/client_hints.cc @@ -120,6 +120,7 @@ const DecodeMap& GetDecodeMap() { std::optional> ParseClientHintsHeader(const std::string& header) { + if ((true)) return std::nullopt; // Accept-CH is an sh-list of tokens; see: // https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-header-structure-19#section-3.1 std::optional maybe_list = diff --git a/third_party/blink/common/client_hints/client_hints.cc b/third_party/blink/common/client_hints/client_hints.cc --- a/third_party/blink/common/client_hints/client_hints.cc +++ b/third_party/blink/common/client_hints/client_hints.cc @@ -14,6 +14,7 @@ #include "base/strings/string_util.h" #include "services/network/public/cpp/client_hints.h" #include "third_party/blink/public/common/features.h" +#include "third_party/blink/renderer/platform/runtime_enabled_features.h" #include "third_party/blink/public/common/permissions_policy/permissions_policy.h" #include "url/origin.h" @@ -106,11 +107,12 @@ const PolicyFeatureToClientHintMap& GetPolicyFeatureToClientHintMap() { bool IsClientHintSentByDefault(network::mojom::WebClientHintsType type) { switch (type) { - case network::mojom::WebClientHintsType::kSaveData: case network::mojom::WebClientHintsType::kUA: case network::mojom::WebClientHintsType::kUAMobile: case network::mojom::WebClientHintsType::kUAPlatform: - return true; + return RuntimeEnabledFeatures::UserAgentClientHintEnabled(); + case network::mojom::WebClientHintsType::kSaveData: + return false; default: return false; } diff --git a/third_party/blink/common/client_hints/enabled_client_hints.cc b/third_party/blink/common/client_hints/enabled_client_hints.cc --- a/third_party/blink/common/client_hints/enabled_client_hints.cc +++ b/third_party/blink/common/client_hints/enabled_client_hints.cc @@ -15,6 +15,12 @@ namespace { using ::network::mojom::WebClientHintsType; bool IsDisabledByFeature(const WebClientHintsType type) { + if (type == WebClientHintsType::kUA || + type == WebClientHintsType::kUAMobile || + type == WebClientHintsType::kUAPlatform) { + return false; + } + if ((true)) return true; switch (type) { case WebClientHintsType::kUA: case WebClientHintsType::kUAArch: diff --git a/third_party/blink/renderer/core/frame/navigator_ua.idl b/third_party/blink/renderer/core/frame/navigator_ua.idl --- a/third_party/blink/renderer/core/frame/navigator_ua.idl +++ b/third_party/blink/renderer/core/frame/navigator_ua.idl @@ -4,6 +4,8 @@ // https://github.com/WICG/ua-client-hints -interface mixin NavigatorUA { +[ + RuntimeEnabled=UserAgentClientHint +] interface mixin NavigatorUA { [SecureContext] readonly attribute NavigatorUAData userAgentData; }; diff --git a/third_party/blink/renderer/core/frame/navigator_ua_data.cc b/third_party/blink/renderer/core/frame/navigator_ua_data.cc --- a/third_party/blink/renderer/core/frame/navigator_ua_data.cc +++ b/third_party/blink/renderer/core/frame/navigator_ua_data.cc @@ -219,6 +219,7 @@ ScriptPromise NavigatorUAData::getHighEntropyValues( Dactyloscoper::RecordDirectSurface( GetExecutionContext(), WebFeature::kNavigatorUAData_Platform, platform()); + if ((false)) for (const String& hint : hints) { if (hint == "platformVersion") { values->setPlatformVersion(platform_version_); diff --git a/third_party/blink/renderer/core/frame/navigator_ua_data.idl b/third_party/blink/renderer/core/frame/navigator_ua_data.idl --- a/third_party/blink/renderer/core/frame/navigator_ua_data.idl +++ b/third_party/blink/renderer/core/frame/navigator_ua_data.idl @@ -4,7 +4,10 @@ // https://github.com/WICG/ua-client-hints -[Exposed=(Window,Worker)] interface NavigatorUAData { +[ + RuntimeEnabled=UserAgentClientHint, + Exposed=(Window,Worker) +] interface NavigatorUAData { [HighEntropy, MeasureAs=NavigatorUAData_Brands] readonly attribute FrozenArray brands; [HighEntropy=Direct, MeasureAs=NavigatorUAData_Mobile] readonly attribute boolean mobile; [HighEntropy=Direct, MeasureAs=NavigatorUAData_Platform] readonly attribute DOMString platform; diff --git a/third_party/blink/renderer/core/loader/base_fetch_context.cc b/third_party/blink/renderer/core/loader/base_fetch_context.cc --- a/third_party/blink/renderer/core/loader/base_fetch_context.cc +++ b/third_party/blink/renderer/core/loader/base_fetch_context.cc @@ -167,7 +167,7 @@ void BaseFetchContext::AddClientHintsIfNecessary( // specifying accomponying client hints, in which case we disable sending // them. using network::mojom::blink::WebClientHintsType; - if (ua) { + if (RuntimeEnabledFeatures::UserAgentClientHintEnabled() && ua) { // ShouldSendClientHint is called to make sure UA is controlled by // Permissions Policy. if (ShouldSendClientHint(policy, resource_origin, is_1p_origin, @@ -329,7 +329,7 @@ void BaseFetchContext::AddClientHintsIfNecessary( } // Only send User Agent hints if the info is available - if (ua) { + if (RuntimeEnabledFeatures::UserAgentClientHintEnabled() && ua) { if (ShouldSendClientHint(policy, resource_origin, is_1p_origin, WebClientHintsType::kUAArch, hints_preferences)) { SetHttpHeader(WebClientHintsType::kUAArch, @@ -682,6 +682,8 @@ bool BaseFetchContext::ShouldSendClientHint( bool is_1p_origin, network::mojom::blink::WebClientHintsType type, const ClientHintsPreferences& hints_preferences) const { + if (!RuntimeEnabledFeatures::UserAgentClientHintEnabled()) + return false; // For subresource requests, sending the hint in the fetch request based on // the permissions policy. if ((!policy || diff --git a/third_party/blink/renderer/platform/runtime_enabled_features.json5 b/third_party/blink/renderer/platform/runtime_enabled_features.json5 --- a/third_party/blink/renderer/platform/runtime_enabled_features.json5 +++ b/third_party/blink/renderer/platform/runtime_enabled_features.json5 @@ -361,6 +361,11 @@ name: "AtomicMoveAPI", status: "test", }, + { + name: "UserAgentClientHint", + status: "stable", + base_feature: "UserAgentClientHint", + }, { name: "AttributionReporting", status: "stable", --