Commit fabe9c51 authored by Mike West's avatar Mike West Committed by Commit Bot

Gate `Sec-Fetch-Dest` on an additional feature flag.

We're aiming to ship most of Fetch Metadata before we've resolved
`Sec-Fetch-Dest` completely. This patch adds another feature flag
and RuntimeEnabledFeature to allow that.

Bug: 843478
Change-Id: I392e20b0bb5a5ab117a720e5d3800258fd3e6e9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1554662Reviewed-by: default avatarJochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarMike West <mkwst@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarŁukasz Anforowicz <lukasza@chromium.org>
Commit-Queue: Mike West <mkwst@chromium.org>
Auto-Submit: Mike West <mkwst@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649840}
parent 7c502920
...@@ -50,7 +50,10 @@ class BookmarkBarNavigationTest : public InProcessBrowserTest { ...@@ -50,7 +50,10 @@ class BookmarkBarNavigationTest : public InProcessBrowserTest {
: https_test_server_(net::EmbeddedTestServer::TYPE_HTTPS) {} : https_test_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
void SetUp() override { void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(network::features::kSecMetadata); scoped_feature_list_.InitWithFeatures(
{network::features::kFetchMetadata,
network::features::kFetchMetadataDestination},
{});
InProcessBrowserTest::SetUp(); InProcessBrowserTest::SetUp();
} }
......
...@@ -139,8 +139,15 @@ bool IsSecureFrame(FrameTreeNode* frame) { ...@@ -139,8 +139,15 @@ bool IsSecureFrame(FrameTreeNode* frame) {
return true; return true;
} }
bool IsSecMetadataEnabled() { bool IsFetchMetadataEnabled() {
return base::FeatureList::IsEnabled(network::features::kSecMetadata) || return base::FeatureList::IsEnabled(network::features::kFetchMetadata) ||
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
}
bool IsFetchMetadataDestinationEnabled() {
return base::FeatureList::IsEnabled(
network::features::kFetchMetadataDestination) ||
base::CommandLine::ForCurrentProcess()->HasSwitch( base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures); switches::kEnableExperimentalWebPlatformFeatures);
} }
...@@ -207,7 +214,7 @@ void AddAdditionalRequestHeaders(net::HttpRequestHeaders* headers, ...@@ -207,7 +214,7 @@ void AddAdditionalRequestHeaders(net::HttpRequestHeaders* headers,
// TODO(mkwst): Extract this logic out somewhere that can be shared between // TODO(mkwst): Extract this logic out somewhere that can be shared between
// Blink and //content. // Blink and //content.
if (IsSecMetadataEnabled() && IsOriginSecure(url)) { if (IsFetchMetadataEnabled() && IsOriginSecure(url)) {
std::string site_value = "cross-site"; std::string site_value = "cross-site";
std::string user_value = has_user_gesture ? "?1" : std::string(); std::string user_value = has_user_gesture ? "?1" : std::string();
...@@ -251,7 +258,10 @@ void AddAdditionalRequestHeaders(net::HttpRequestHeaders* headers, ...@@ -251,7 +258,10 @@ void AddAdditionalRequestHeaders(net::HttpRequestHeaders* headers,
destination = "nested-document"; destination = "nested-document";
mode = "nested-navigate"; mode = "nested-navigate";
} }
headers->SetHeaderIfMissing("Sec-Fetch-Dest", destination.c_str());
if (IsFetchMetadataDestinationEnabled()) {
headers->SetHeaderIfMissing("Sec-Fetch-Dest", destination.c_str());
}
headers->SetHeaderIfMissing("Sec-Fetch-Mode", mode.c_str()); headers->SetHeaderIfMissing("Sec-Fetch-Mode", mode.c_str());
headers->SetHeaderIfMissing("Sec-Fetch-Site", site_value.c_str()); headers->SetHeaderIfMissing("Sec-Fetch-Site", site_value.c_str());
if (!user_value.empty()) if (!user_value.empty())
......
...@@ -37,7 +37,10 @@ class SecFetchBrowserTest : public ContentBrowserTest { ...@@ -37,7 +37,10 @@ class SecFetchBrowserTest : public ContentBrowserTest {
https_test_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_OK); https_test_server_.SetSSLConfig(net::EmbeddedTestServer::CERT_OK);
ASSERT_TRUE(https_test_server_.Start()); ASSERT_TRUE(https_test_server_.Start());
feature_list_.InitAndEnableFeature(network::features::kSecMetadata); feature_list_.InitWithFeatures(
{network::features::kFetchMetadata,
network::features::kFetchMetadataDestination},
{});
} }
WebContents* web_contents() { return shell()->web_contents(); } WebContents* web_contents() { return shell()->web_contents(); }
......
...@@ -214,9 +214,11 @@ void WorkerScriptFetchInitiator::AddAdditionalRequestHeaders( ...@@ -214,9 +214,11 @@ void WorkerScriptFetchInitiator::AddAdditionalRequestHeaders(
} }
// Set Fetch metadata headers if necessary. // Set Fetch metadata headers if necessary.
if ((base::FeatureList::IsEnabled(network::features::kSecMetadata) || bool experimental_features_enabled =
base::CommandLine::ForCurrentProcess()->HasSwitch( base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures)) && switches::kEnableExperimentalWebPlatformFeatures);
if ((base::FeatureList::IsEnabled(network::features::kFetchMetadata) ||
experimental_features_enabled) &&
IsOriginSecure(resource_request->url)) { IsOriginSecure(resource_request->url)) {
// The worker's origin can be different from the constructor's origin, for // The worker's origin can be different from the constructor's origin, for
// example, when the worker created from the extension. // example, when the worker created from the extension.
...@@ -227,13 +229,18 @@ void WorkerScriptFetchInitiator::AddAdditionalRequestHeaders( ...@@ -227,13 +229,18 @@ void WorkerScriptFetchInitiator::AddAdditionalRequestHeaders(
url::Origin::Create(resource_request->url))) { url::Origin::Create(resource_request->url))) {
site_value = "same-origin"; site_value = "same-origin";
} }
resource_request->headers.SetHeaderIfMissing("Sec-Fetch-Dest",
"sharedworker");
resource_request->headers.SetHeaderIfMissing("Sec-Fetch-Site", resource_request->headers.SetHeaderIfMissing("Sec-Fetch-Site",
site_value.c_str()); site_value.c_str());
resource_request->headers.SetHeaderIfMissing("Sec-Fetch-Mode", resource_request->headers.SetHeaderIfMissing("Sec-Fetch-Mode",
"same-origin"); "same-origin");
// We don't set `Sec-Fetch-User` for subresource requests. // We don't set `Sec-Fetch-User` for subresource requests.
if (base::FeatureList::IsEnabled(
network::features::kFetchMetadataDestination) ||
experimental_features_enabled) {
resource_request->headers.SetHeaderIfMissing("Sec-Fetch-Dest",
"sharedworker");
}
} }
} }
......
...@@ -201,8 +201,12 @@ void SetIndividualRuntimeFeatures( ...@@ -201,8 +201,12 @@ void SetIndividualRuntimeFeatures(
// TODO(yashard): Remove |enable_experimental_web_platform_features| flag // TODO(yashard): Remove |enable_experimental_web_platform_features| flag
// since the feature should have been enabled when it is set to experimental // since the feature should have been enabled when it is set to experimental
WebRuntimeFeatures::EnableSecMetadata( WebRuntimeFeatures::EnableFetchMetadata(
base::FeatureList::IsEnabled(network::features::kSecMetadata) || base::FeatureList::IsEnabled(network::features::kFetchMetadata) ||
enable_experimental_web_platform_features);
WebRuntimeFeatures::EnableFetchMetadataDestination(
base::FeatureList::IsEnabled(
network::features::kFetchMetadataDestination) ||
enable_experimental_web_platform_features); enable_experimental_web_platform_features);
WebRuntimeFeatures::EnableUserActivationPostMessageTransfer( WebRuntimeFeatures::EnableUserActivationPostMessageTransfer(
......
...@@ -60,8 +60,14 @@ const base::Feature kEnforceRequestInitiatorLockForCorb{ ...@@ -60,8 +60,14 @@ const base::Feature kEnforceRequestInitiatorLockForCorb{
"EnforceRequestInitiatorLockForCorb", base::FEATURE_ENABLED_BY_DEFAULT}; "EnforceRequestInitiatorLockForCorb", base::FEATURE_ENABLED_BY_DEFAULT};
// Implementation of https://mikewest.github.io/sec-metadata/ // Implementation of https://mikewest.github.io/sec-metadata/
const base::Feature kSecMetadata{"SecMetadata", const base::Feature kFetchMetadata{"FetchMetadata",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// The `Sec-Fetch-Dest` header is split out from the main "FetchMetadata"
// feature so we can ship the broader feature without this specifific bit
// while we continue discussion.
const base::Feature kFetchMetadataDestination{
"FetchMetadataDestination", base::FEATURE_DISABLED_BY_DEFAULT};
bool ShouldEnableOutOfBlinkCors() { bool ShouldEnableOutOfBlinkCors() {
// OOR-CORS requires NetworkService. // OOR-CORS requires NetworkService.
......
...@@ -28,7 +28,9 @@ extern const base::Feature kDelayRequestsOnMultiplexedConnections; ...@@ -28,7 +28,9 @@ extern const base::Feature kDelayRequestsOnMultiplexedConnections;
COMPONENT_EXPORT(NETWORK_CPP) COMPONENT_EXPORT(NETWORK_CPP)
extern const base::Feature kEnforceRequestInitiatorLockForCorb; extern const base::Feature kEnforceRequestInitiatorLockForCorb;
COMPONENT_EXPORT(NETWORK_CPP) COMPONENT_EXPORT(NETWORK_CPP)
extern const base::Feature kSecMetadata; extern const base::Feature kFetchMetadata;
COMPONENT_EXPORT(NETWORK_CPP)
extern const base::Feature kFetchMetadataDestination;
COMPONENT_EXPORT(NETWORK_CPP) bool ShouldEnableOutOfBlinkCors(); COMPONENT_EXPORT(NETWORK_CPP) bool ShouldEnableOutOfBlinkCors();
......
...@@ -171,7 +171,8 @@ class WebRuntimeFeatures { ...@@ -171,7 +171,8 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableScriptedSpeechRecognition(bool); BLINK_PLATFORM_EXPORT static void EnableScriptedSpeechRecognition(bool);
BLINK_PLATFORM_EXPORT static void EnableScriptedSpeechSynthesis(bool); BLINK_PLATFORM_EXPORT static void EnableScriptedSpeechSynthesis(bool);
BLINK_PLATFORM_EXPORT static void EnableScrollAnchorSerialization(bool); BLINK_PLATFORM_EXPORT static void EnableScrollAnchorSerialization(bool);
BLINK_PLATFORM_EXPORT static void EnableSecMetadata(bool); BLINK_PLATFORM_EXPORT static void EnableFetchMetadata(bool);
BLINK_PLATFORM_EXPORT static void EnableFetchMetadataDestination(bool);
BLINK_PLATFORM_EXPORT static void EnableSharedArrayBuffer(bool); BLINK_PLATFORM_EXPORT static void EnableSharedArrayBuffer(bool);
BLINK_PLATFORM_EXPORT static void EnableSharedWorker(bool); BLINK_PLATFORM_EXPORT static void EnableSharedWorker(bool);
BLINK_PLATFORM_EXPORT static void EnableTextFragmentAnchor(bool); BLINK_PLATFORM_EXPORT static void EnableTextFragmentAnchor(bool);
......
...@@ -144,7 +144,7 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request) { ...@@ -144,7 +144,7 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request) {
scoped_refptr<SecurityOrigin> url_origin = scoped_refptr<SecurityOrigin> url_origin =
SecurityOrigin::Create(request.Url()); SecurityOrigin::Create(request.Url());
if (blink::RuntimeEnabledFeatures::SecMetadataEnabled() && if (blink::RuntimeEnabledFeatures::FetchMetadataEnabled() &&
url_origin->IsPotentiallyTrustworthy()) { url_origin->IsPotentiallyTrustworthy()) {
const char* destination_value = const char* destination_value =
GetDestinationFromContext(request.GetRequestContext()); GetDestinationFromContext(request.GetRequestContext());
...@@ -154,7 +154,7 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request) { ...@@ -154,7 +154,7 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request) {
if (strlen(destination_value) == 0) if (strlen(destination_value) == 0)
destination_value = "empty"; destination_value = "empty";
// We'll handle adding the header to navigations outside of Blink. // We'll handle adding these headers to navigations outside of Blink.
if (strncmp(destination_value, "document", 8) != 0 && if (strncmp(destination_value, "document", 8) != 0 &&
request.GetRequestContext() != mojom::RequestContextType::INTERNAL) { request.GetRequestContext() != mojom::RequestContextType::INTERNAL) {
const char* site_value = "cross-site"; const char* site_value = "cross-site";
...@@ -173,7 +173,10 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request) { ...@@ -173,7 +173,10 @@ void BaseFetchContext::AddAdditionalRequestHeaders(ResourceRequest& request) {
} }
} }
request.SetHttpHeaderField("Sec-Fetch-Dest", destination_value); if (blink::RuntimeEnabledFeatures::FetchMetadataDestinationEnabled()) {
request.SetHttpHeaderField("Sec-Fetch-Dest", destination_value);
}
request.SetHttpHeaderField( request.SetHttpHeaderField(
"Sec-Fetch-Mode", "Sec-Fetch-Mode",
FetchRequestModeToString(request.GetFetchRequestMode())); FetchRequestModeToString(request.GetFetchRequestMode()));
......
...@@ -519,8 +519,12 @@ void WebRuntimeFeatures::EnableScrollAnchorSerialization(bool enable) { ...@@ -519,8 +519,12 @@ void WebRuntimeFeatures::EnableScrollAnchorSerialization(bool enable) {
RuntimeEnabledFeatures::SetScrollAnchorSerializationEnabled(enable); RuntimeEnabledFeatures::SetScrollAnchorSerializationEnabled(enable);
} }
void WebRuntimeFeatures::EnableSecMetadata(bool enable) { void WebRuntimeFeatures::EnableFetchMetadata(bool enable) {
RuntimeEnabledFeatures::SetSecMetadataEnabled(enable); RuntimeEnabledFeatures::SetFetchMetadataEnabled(enable);
}
void WebRuntimeFeatures::EnableFetchMetadataDestination(bool enable) {
RuntimeEnabledFeatures::SetFetchMetadataDestinationEnabled(enable);
} }
void WebRuntimeFeatures::EnableTimerThrottlingForBackgroundTabs(bool enable) { void WebRuntimeFeatures::EnableTimerThrottlingForBackgroundTabs(bool enable) {
......
...@@ -549,6 +549,14 @@ ...@@ -549,6 +549,14 @@
{ {
name: "FeaturePolicyVibrateFeature" name: "FeaturePolicyVibrateFeature"
}, },
{
name: "FetchMetadata",
status: "experimental"
},
{
name: "FetchMetadataDestination",
status: "experimental"
},
{ {
name: "FileSystem", name: "FileSystem",
status: "stable", status: "stable",
...@@ -1268,10 +1276,6 @@ ...@@ -1268,10 +1276,6 @@
name: "ScrollTopLeftInterop", name: "ScrollTopLeftInterop",
status: "stable", status: "stable",
}, },
{
name: "SecMetadata",
status: "experimental"
},
{ {
name: "SendBeaconThrowForBlobWithNonSimpleType", name: "SendBeaconThrowForBlobWithNonSimpleType",
status: "stable", status: "stable",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment