Storage is limited to the user session, lasts 1 minute, and is not permitted in iframes. This change is necessary to bypass certain checks performed by websites without having to send any information.
296 lines
14 KiB
Diff
296 lines
14 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/client_hints/browser/client_hints.cc | 5 +++--
|
|
components/embedder_support/user_agent_utils.cc | 5 ++---
|
|
content/browser/client_hints/client_hints.cc | 17 +++++++++++++++--
|
|
.../about_flags_cc/Client-hints-overrides.inc | 9 +++++++++
|
|
.../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 | 2 +-
|
|
.../blink/common/client_hints/client_hints.cc | 6 ++++--
|
|
.../common/client_hints/enabled_client_hints.cc | 8 ++++++++
|
|
.../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, 62 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/client_hints/browser/client_hints.cc b/components/client_hints/browser/client_hints.cc
|
|
--- a/components/client_hints/browser/client_hints.cc
|
|
+++ b/components/client_hints/browser/client_hints.cc
|
|
@@ -35,7 +35,7 @@ ParseInitializeClientHintsStorage() {
|
|
auto results =
|
|
base::flat_map<url::Origin,
|
|
std::vector<network::mojom::WebClientHintsType>>();
|
|
-
|
|
+ if ((true)) return results;
|
|
std::string raw_client_hint_json =
|
|
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
|
|
switches::kInitializeClientHintsStorage);
|
|
@@ -200,7 +200,8 @@ void ClientHints::PersistClientHints(
|
|
// TODO(tbansal): crbug.com/735518. Disable updates to client hints settings
|
|
// when cookies are disabled for |primary_origin|.
|
|
content_settings::ContentSettingConstraints constraints;
|
|
- constraints.set_session_model(content_settings::mojom::SessionModel::DURABLE);
|
|
+ constraints.set_session_model(content_settings::mojom::SessionModel::USER_SESSION);
|
|
+ constraints.set_lifetime(base::Minutes(1));
|
|
settings_map_->SetWebsiteSettingDefaultScope(
|
|
primary_url, GURL(), ContentSettingsType::CLIENT_HINTS,
|
|
base::Value(std::move(client_hints_dictionary)), constraints);
|
|
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
|
|
@@ -202,9 +202,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
|
|
@@ -698,6 +696,7 @@ blink::UserAgentMetadata GetUserAgentMetadata(const PrefService* pref_service,
|
|
}
|
|
|
|
// High entropy client hints.
|
|
+ if ((true)) return metadata;
|
|
metadata.brand_full_version_list =
|
|
GetUserAgentBrandFullVersionListInternal(std::nullopt);
|
|
metadata.full_version = std::string(version_info::GetVersionNumber());
|
|
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
|
|
@@ -58,6 +58,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"
|
|
@@ -602,10 +603,21 @@ bool IsClientHintEnabled(const ClientHintsExtendedData& data,
|
|
|
|
bool IsClientHintAllowed(const ClientHintsExtendedData& data,
|
|
WebClientHintsType type) {
|
|
+ if (!blink::RuntimeEnabledFeatures::UserAgentClientHintEnabled())
|
|
+ return false;
|
|
+
|
|
+ bool allowed = false;
|
|
+ if (type == WebClientHintsType::kUA ||
|
|
+ type == WebClientHintsType::kUAMobile ||
|
|
+ type == WebClientHintsType::kUAPlatform ||
|
|
+ type == WebClientHintsType::kUAModel ||
|
|
+ type == WebClientHintsType::kUAPlatformVersion) {
|
|
+ allowed = true;
|
|
+ }
|
|
if (data.is_outermost_main_frame) {
|
|
- return true;
|
|
+ return allowed;
|
|
}
|
|
- return (data.permissions_policy->IsFeatureEnabledForOrigin(
|
|
+ return ((false)) && (data.permissions_policy->IsFeatureEnabledForOrigin(
|
|
network::GetClientHintToPolicyFeatureMap().at(type),
|
|
data.resource_origin));
|
|
}
|
|
@@ -630,6 +642,7 @@ bool IsJavascriptEnabled(FrameTreeNode* frame_tree_node) {
|
|
void UpdateIFramePermissionsPolicyWithDelegationSupportForClientHints(
|
|
ClientHintsExtendedData& data,
|
|
const network::ParsedPermissionsPolicy& container_policy) {
|
|
+ if ((true)) return;
|
|
if (container_policy.empty()) {
|
|
return;
|
|
}
|
|
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_ENABLED(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_ENABLED(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
|
|
@@ -113,6 +113,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
|
|
@@ -111,7 +111,7 @@ const DecodeMap& GetDecodeMap() {
|
|
} // namespace
|
|
|
|
std::optional<std::vector<network::mojom::WebClientHintsType>>
|
|
-ParseClientHintsHeader(const std::string& header) {
|
|
+ParseClientHintsHeader(const std::string& header) { // Parse Client Hints Header
|
|
// 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,14 @@ namespace {
|
|
using ::network::mojom::WebClientHintsType;
|
|
|
|
bool IsDisabledByFeature(const WebClientHintsType type) {
|
|
+ if (type == WebClientHintsType::kUA ||
|
|
+ type == WebClientHintsType::kUAMobile ||
|
|
+ type == WebClientHintsType::kUAPlatform ||
|
|
+ type == WebClientHintsType::kUAModel ||
|
|
+ type == WebClientHintsType::kUAPlatformVersion) {
|
|
+ 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
|
|
@@ -231,6 +231,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(
|
|
@@ -713,7 +715,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
|
|
@@ -569,6 +569,11 @@
|
|
name: "AriaNotifyV2",
|
|
status: {"Android": "test", "Win": "test", "Mac": "test", "Linux": "test"},
|
|
},
|
|
+ {
|
|
+ name: "UserAgentClientHint",
|
|
+ status: "stable",
|
|
+ base_feature: "UserAgentClientHint",
|
|
+ },
|
|
{
|
|
name: "AriaRowColIndexText",
|
|
status: "stable",
|
|
@@ -976,8 +981,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
|
|
--
|