281 lines
13 KiB
Diff
281 lines
13 KiB
Diff
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/frame_fetch_context.cc | 4 +++-
|
|
.../platform/runtime_enabled_features.json5 | 8 ++++++--
|
|
15 files changed, 56 insertions(+), 15 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
|
|
@@ -203,9 +203,7 @@ const blink::UserAgentBrandList GetUserAgentBrandList(
|
|
bool parse_result = base::StringToInt(major_version, &major_version_number);
|
|
DCHECK(parse_result);
|
|
std::optional<std::string> brand;
|
|
-#if !BUILDFLAG(CHROMIUM_BRANDING)
|
|
- brand = version_info::GetProductName();
|
|
-#endif
|
|
+ brand = "Google Chrome";
|
|
|
|
std::string brand_version =
|
|
output_version_type == blink::UserAgentBrandVersionType::kFullVersion
|
|
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
|
|
@@ -57,6 +57,7 @@
|
|
#include "third_party/blink/public/common/features.h"
|
|
#include "third_party/blink/public/common/page/page_zoom.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"
|
|
@@ -703,7 +704,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();
|
|
@@ -885,10 +887,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);
|
|
@@ -969,6 +973,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
|
|
@@ -1380,6 +1380,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
|
|
@@ -111,6 +111,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
|
|
@@ -112,6 +112,7 @@ const DecodeMap& GetDecodeMap() {
|
|
|
|
std::optional<std::vector<network::mojom::WebClientHintsType>>
|
|
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<net::structured_headers::List> 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 "services/network/public/cpp/permissions_policy/client_hints_permissions_policy_mapping.h"
|
|
+#include "third_party/blink/public/common/features_generated.h"
|
|
#include "services/network/public/cpp/permissions_policy/permissions_policy.h"
|
|
#include "third_party/blink/public/common/features.h"
|
|
#include "url/origin.h"
|
|
@@ -22,11 +23,12 @@ namespace blink {
|
|
|
|
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 base::FeatureList::IsEnabled(blink::features::kUserAgentClientHint);
|
|
+ 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
|
|
@@ -186,6 +186,7 @@ const String& NavigatorUAData::platform() const {
|
|
}
|
|
|
|
bool AllowedToCollectHighEntropyValues(ExecutionContext* execution_context) {
|
|
+ if ((true)) return false;
|
|
// To determine whether a document is allowed to use the get high-entropy
|
|
// client hints returned by navigator.userAgentData.getHighEntropyValues(),
|
|
// check the following:
|
|
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<NavigatorUABrandVersion> 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/frame_fetch_context.cc b/third_party/blink/renderer/core/loader/frame_fetch_context.cc
|
|
--- a/third_party/blink/renderer/core/loader/frame_fetch_context.cc
|
|
+++ b/third_party/blink/renderer/core/loader/frame_fetch_context.cc
|
|
@@ -226,6 +226,8 @@ bool ShouldSendClientHint(const network::PermissionsPolicy& policy,
|
|
bool is_1p_origin,
|
|
network::mojom::blink::WebClientHintsType type,
|
|
const ClientHintsPreferences& hints_preferences) {
|
|
+ if (!RuntimeEnabledFeatures::UserAgentClientHintEnabled())
|
|
+ return false;
|
|
// For subresource requests, sending the hint in the fetch request based on
|
|
// the permissions policy.
|
|
if (!policy.IsFeatureEnabledForOrigin(
|
|
@@ -606,7 +608,7 @@ void FrameFetchContext::AddClientHintsIfNecessary(
|
|
}
|
|
|
|
// Only send User Agent hints if the info is available
|
|
- 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,
|
|
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
|
|
@@ -517,6 +517,11 @@
|
|
name: "AriaNotifyV2",
|
|
status: {"Android": "test", "Win": "test", "Mac": "test", "Linux": "test"},
|
|
},
|
|
+ {
|
|
+ name: "UserAgentClientHint",
|
|
+ status: "stable",
|
|
+ base_feature: "UserAgentClientHint",
|
|
+ },
|
|
{
|
|
name: "AriaRowColIndexText",
|
|
status: "stable",
|
|
@@ -903,8 +908,7 @@
|
|
// Allows top-level sites to restrict collection of high-entropy UA client
|
|
// hints (from 3Ps, or itself) via the getHighEntropyValues API.
|
|
// crbug.com/385161047
|
|
- name: "ClientHintUAHighEntropyValuesPermissionPolicy",
|
|
- status: "test",
|
|
+ name: "ClientHintUAHighEntropyValuesPermissionPolicy", // disabled by default
|
|
},
|
|
{
|
|
// Enables clipboardchange event API for listening for changes to the
|
|
--
|