From fe5a8ecbfcfbeec32711da67d07f3d55148a544d Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 25 Sep 2020 12:32:55 +0200 Subject: [PATCH] Add ephemeral storage support for JavaScript cookies This change adds a new class EphemeralStoragePartition which provides access to an ephemeral version of a RestrictedCookieManager for the content process. In an upcoming change this will also provide a StoragePartition for navigation requests in third-party frames in order to add support for navigation cookies. --- browser/BUILD.gn | 13 +- browser/brave_tab_helpers.cc | 4 +- browser/ephemeral_storage/BUILD.gn | 1 + .../ephemeral_storage_browsertest.cc | 69 +++++++++- .../ephemeral_storage_tab_helper.cc | 33 ++--- .../ephemeral_storage_tab_helper.h | 4 +- chromium_src/chrome/browser/about_flags.cc | 9 +- .../content/browser/browser_context.cc | 4 +- .../content/browser/tld_ephemeral_lifetime.cc | 67 ++++++++++ .../content/public/browser/browser_context.h | 1 + .../public/browser/tld_ephemeral_lifetime.h | 59 +++++++++ .../blink/common => net/base}/features.cc | 6 +- chromium_src/net/base/features.h | 22 ++++ chromium_src/net/base/url_util.cc | 14 ++ chromium_src/net/base/url_util.h | 12 +- .../net/cookies/cookie_deletion_info.h | 16 +++ chromium_src/net/cookies/cookie_monster.cc | 120 ++++++++++++++++++ chromium_src/net/cookies/cookie_monster.h | 60 +++++++++ .../services/network/cookie_manager.cc | 12 ++ .../network/restricted_cookie_manager.cc | 48 +++++++ .../blink/public/common/features.h | 24 ---- .../modules/storage/dom_window_storage.cc | 6 +- .../net-cookies-cookie_deletion_info.h.patch | 12 ++ .../services-network-cookie_manager.cc.patch | 12 ++ ...rk-public-mojom-cookie_manager.mojom.patch | 12 ++ ...network-restricted_cookie_manager.cc.patch | 20 +++ 26 files changed, 592 insertions(+), 68 deletions(-) create mode 100644 chromium_src/content/browser/tld_ephemeral_lifetime.cc create mode 100644 chromium_src/content/public/browser/tld_ephemeral_lifetime.h rename chromium_src/{third_party/blink/common => net/base}/features.cc (81%) create mode 100644 chromium_src/net/base/features.h create mode 100644 chromium_src/net/cookies/cookie_deletion_info.h create mode 100644 chromium_src/net/cookies/cookie_monster.cc create mode 100644 chromium_src/net/cookies/cookie_monster.h create mode 100644 chromium_src/services/network/cookie_manager.cc create mode 100644 chromium_src/services/network/restricted_cookie_manager.cc delete mode 100644 chromium_src/third_party/blink/public/common/features.h create mode 100644 patches/net-cookies-cookie_deletion_info.h.patch create mode 100644 patches/services-network-cookie_manager.cc.patch create mode 100644 patches/services-network-public-mojom-cookie_manager.mojom.patch create mode 100644 patches/services-network-restricted_cookie_manager.cc.patch diff --git a/browser/BUILD.gn b/browser/BUILD.gn index 1ed432cced51..e6ea79cbe8ff 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -27,14 +27,14 @@ source_set("browser_process") { # Remove when https://github.com/brave/brave-browser/issues/10657 is resolved check_includes = false visibility = [ - "//chrome/browser/*", - "//brave/browser/*", "//brave:browser_dependencies", + "//brave/browser/*", "//brave/components/brave_ads/test:*", "//brave/components/brave_rewards/browser:testutil", "//brave/components/brave_rewards/test:*", "//brave/components/ipfs/test:*", "//brave/test:*", + "//chrome/browser/*", ] sources = [ @@ -174,8 +174,8 @@ source_set("browser_process") { "//components/services/patch/content", "//components/services/unzip/content", "//components/sessions", - "//components/sync_device_info", "//components/spellcheck/browser", + "//components/sync_device_info", "//components/unified_consent", "//components/update_client:patch_impl", "//components/update_client:unzip_impl", @@ -184,7 +184,6 @@ source_set("browser_process") { "//extensions/buildflags", "//services/metrics/public/cpp:metrics_cpp", "//services/network/public/cpp", - "//third_party/blink/public/common", "//third_party/blink/public/mojom:mojom_platform_headers", "//third_party/widevine/cdm:buildflags", "//ui/base", @@ -192,8 +191,8 @@ source_set("browser_process") { if (brave_wallet_enabled) { deps += [ - "//brave/components/brave_wallet", "brave_wallet", + "//brave/components/brave_wallet", ] } @@ -433,10 +432,10 @@ source_set("version_info") { source_set("browser") { visibility = [ - "//chrome/browser/*", - "//brave/browser/*", "//brave:browser_dependencies", + "//brave/browser/*", "//brave/test:*", + "//chrome/browser/*", ] deps = [ "//chrome/browser" ] diff --git a/browser/brave_tab_helpers.cc b/browser/brave_tab_helpers.cc index 2cc60ac9184e..bbeeb955c799 100644 --- a/browser/brave_tab_helpers.cc +++ b/browser/brave_tab_helpers.cc @@ -23,7 +23,7 @@ #include "brave/components/tor/buildflags/buildflags.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/web_contents.h" -#include "third_party/blink/public/common/features.h" +#include "net/base/features.h" #include "third_party/widevine/cdm/buildflags.h" #if BUILDFLAG(ENABLE_GREASELION) @@ -134,7 +134,7 @@ void AttachTabHelpers(content::WebContents* web_contents) { brave_stats::BraveStatsTabHelper::CreateForWebContents(web_contents); - if (base::FeatureList::IsEnabled(blink::features::kBraveEphemeralStorage)) { + if (base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage)) { ephemeral_storage::EphemeralStorageTabHelper::CreateForWebContents( web_contents); } diff --git a/browser/ephemeral_storage/BUILD.gn b/browser/ephemeral_storage/BUILD.gn index 9c36f970dea5..0f8ec42863a5 100644 --- a/browser/ephemeral_storage/BUILD.gn +++ b/browser/ephemeral_storage/BUILD.gn @@ -27,6 +27,7 @@ if (!is_android) { "//chrome/test:test_support_ui", "//content/public/common", "//content/test:test_support", + "//net", "//services/network:test_support", "//third_party/blink/public/common", "//url", diff --git a/browser/ephemeral_storage/ephemeral_storage_browsertest.cc b/browser/ephemeral_storage/ephemeral_storage_browsertest.cc index c40bd38b4a53..6880d8e6ccf7 100644 --- a/browser/ephemeral_storage/ephemeral_storage_browsertest.cc +++ b/browser/ephemeral_storage/ephemeral_storage_browsertest.cc @@ -21,9 +21,9 @@ #include "content/public/browser/web_contents.h" #include "content/public/test/browser_test.h" #include "content/public/test/test_navigation_observer.h" +#include "net/base/features.h" #include "net/dns/mock_host_resolver.h" #include "net/test/embedded_test_server/default_handlers.h" -#include "third_party/blink/public/common/features.h" #include "url/gurl.h" using content::RenderFrameHost; @@ -59,6 +59,16 @@ content::EvalJsResult GetStorageValueInFrame(RenderFrameHost* host, return content::EvalJs(host, script); } +void SetCookieInFrame(RenderFrameHost* host, std::string cookie) { + std::string script = base::StringPrintf( + "document.cookie='%s; path=/; SameSite=None; Secure'", cookie.c_str()); + ASSERT_TRUE(content::ExecuteScript(host, script)); +} + +content::EvalJsResult GetCookiesInFrame(RenderFrameHost* host) { + return content::EvalJs(host, "document.cookie"); +} + } // namespace class EphemeralStorageBrowserTest : public InProcessBrowserTest { @@ -66,7 +76,7 @@ class EphemeralStorageBrowserTest : public InProcessBrowserTest { EphemeralStorageBrowserTest() : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) { scoped_feature_list_.InitAndEnableFeature( - blink::features::kBraveEphemeralStorage); + net::features::kBraveEphemeralStorage); } void SetUpOnMainThread() override { @@ -111,6 +121,7 @@ class EphemeralStorageBrowserTest : public InProcessBrowserTest { auto set_values_in_frame = [&](RenderFrameHost* frame) { SetStorageValueInFrame(frame, storage_value, StorageType::Local); SetStorageValueInFrame(frame, storage_value, StorageType::Session); + SetCookieInFrame(frame, cookie_value); }; RenderFrameHost* main_frame = web_contents->GetMainFrame(); @@ -122,12 +133,14 @@ class EphemeralStorageBrowserTest : public InProcessBrowserTest { struct ValuesFromFrame { content::EvalJsResult local_storage; content::EvalJsResult session_storage; + content::EvalJsResult cookies; }; ValuesFromFrame GetValuesFromFrame(RenderFrameHost* frame) { return { GetStorageValueInFrame(frame, StorageType::Local), GetStorageValueInFrame(frame, StorageType::Session), + GetCookiesInFrame(frame), }; } @@ -192,6 +205,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, StorageIsPartitioned) { EXPECT_EQ("a.com", site_a_tab1_values.iframe_1.session_storage); EXPECT_EQ("a.com", site_a_tab1_values.iframe_2.session_storage); + EXPECT_EQ("from=a.com", site_a_tab1_values.main_frame.cookies); + EXPECT_EQ("from=a.com", site_a_tab1_values.iframe_1.cookies); + EXPECT_EQ("from=a.com", site_a_tab1_values.iframe_2.cookies); + // The second tab is loaded on the same domain, so should see the same // storage for the third-party iframes. ValuesFromFrames site_a_tab2_values = GetValuesFromFrames(site_a_tab2); @@ -203,6 +220,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, StorageIsPartitioned) { EXPECT_EQ(nullptr, site_a_tab2_values.iframe_1.session_storage); EXPECT_EQ(nullptr, site_a_tab2_values.iframe_2.session_storage); + EXPECT_EQ("from=a.com", site_a_tab2_values.main_frame.cookies); + EXPECT_EQ("from=a.com", site_a_tab2_values.iframe_1.cookies); + EXPECT_EQ("from=a.com", site_a_tab2_values.iframe_2.cookies); + // The storage in the first-party iframes should still reflect the // original value that was written in the non-ephemeral storage area. ValuesFromFrames first_party_values = GetValuesFromFrames(first_party_tab); @@ -215,6 +236,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, StorageIsPartitioned) { EXPECT_EQ("b.com - first party", first_party_values.iframe_1.session_storage); EXPECT_EQ("b.com - first party", first_party_values.iframe_2.session_storage); + EXPECT_EQ("from=b.com", first_party_values.main_frame.cookies); + EXPECT_EQ("from=b.com", first_party_values.iframe_1.cookies); + EXPECT_EQ("from=b.com", first_party_values.iframe_2.cookies); + // Even though this page loads b.com iframes as third-party iframes, the TLD // differs, so it should get an entirely different ephemeral storage area. ValuesFromFrames site_c_tab_values = GetValuesFromFrames(site_c_tab); @@ -225,6 +250,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, StorageIsPartitioned) { EXPECT_EQ(nullptr, site_c_tab_values.main_frame.session_storage); EXPECT_EQ(nullptr, site_c_tab_values.iframe_1.session_storage); EXPECT_EQ(nullptr, site_c_tab_values.iframe_2.session_storage); + + EXPECT_EQ("", site_c_tab_values.main_frame.cookies); + EXPECT_EQ("", site_c_tab_values.iframe_1.cookies); + EXPECT_EQ("", site_c_tab_values.iframe_2.cookies); } IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, @@ -245,6 +274,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ("a.com value", values_before.iframe_1.session_storage); EXPECT_EQ("a.com value", values_before.iframe_2.session_storage); + EXPECT_EQ("from=a.com", values_before.main_frame.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_1.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_2.cookies); + // Navigate away and then navigate back to the original site. ui_test_utils::NavigateToURL(browser(), b_site_ephemeral_storage_url_); ui_test_utils::NavigateToURL(browser(), a_site_ephemeral_storage_url_); @@ -257,6 +290,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ("a.com value", values_after.main_frame.session_storage); EXPECT_EQ(nullptr, values_after.iframe_1.session_storage); EXPECT_EQ(nullptr, values_after.iframe_2.session_storage); + + EXPECT_EQ("from=a.com", values_after.main_frame.cookies); + EXPECT_EQ("", values_after.iframe_1.cookies); + EXPECT_EQ("", values_after.iframe_2.cookies); } IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, @@ -277,6 +314,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ("a.com value", values_before.iframe_1.session_storage); EXPECT_EQ("a.com value", values_before.iframe_2.session_storage); + EXPECT_EQ("from=a.com", values_before.main_frame.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_1.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_2.cookies); + // Close the new tab which we set ephemeral storage value in. This should // clear the ephemeral storage since this is the last tab which has a.com as // an eTLD. @@ -299,6 +340,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ(nullptr, values_after.main_frame.session_storage); EXPECT_EQ(nullptr, values_after.iframe_1.session_storage); EXPECT_EQ(nullptr, values_after.iframe_2.session_storage); + + EXPECT_EQ("from=a.com", values_after.main_frame.cookies); + EXPECT_EQ("", values_after.iframe_1.cookies); + EXPECT_EQ("", values_after.iframe_2.cookies); } IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, @@ -319,6 +364,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ("a.com value", values_before.iframe_1.session_storage); EXPECT_EQ("a.com value", values_before.iframe_2.session_storage); + EXPECT_EQ("from=a.com", values_before.main_frame.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_1.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_2.cookies); + // Reload the page. ui_test_utils::NavigateToURL(browser(), a_site_ephemeral_storage_url_); @@ -330,6 +379,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ("a.com value", values_after.main_frame.session_storage); EXPECT_EQ("a.com value", values_after.iframe_1.session_storage); EXPECT_EQ("a.com value", values_after.iframe_2.session_storage); + + EXPECT_EQ("from=a.com", values_after.main_frame.cookies); + EXPECT_EQ("from=a.com", values_after.iframe_1.cookies); + EXPECT_EQ("from=a.com", values_after.iframe_2.cookies); } IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, @@ -350,6 +403,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ("a.com value", values_before.iframe_1.session_storage); EXPECT_EQ("a.com value", values_before.iframe_2.session_storage); + EXPECT_EQ("from=a.com", values_before.main_frame.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_1.cookies); + EXPECT_EQ("from=a.com", values_before.iframe_2.cookies); + // A browser with the same profile should share all values with the // first browser, including ephemeral storage values. Browser* same_profile_browser = CreateBrowser(browser()->profile()); @@ -368,6 +425,10 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ("a.com value", same_profile_values.iframe_1.session_storage); EXPECT_EQ("a.com value", same_profile_values.iframe_2.session_storage); + EXPECT_EQ("from=a.com", same_profile_values.main_frame.cookies); + EXPECT_EQ("from=a.com", same_profile_values.iframe_1.cookies); + EXPECT_EQ("from=a.com", same_profile_values.iframe_2.cookies); + // A browser with a different profile shouldn't share any values with // the first set of browsers. Browser* private_browser = CreateIncognitoBrowser(nullptr); @@ -383,4 +444,8 @@ IN_PROC_BROWSER_TEST_F(EphemeralStorageBrowserTest, EXPECT_EQ(nullptr, private_values.main_frame.session_storage); EXPECT_EQ(nullptr, private_values.iframe_1.session_storage); EXPECT_EQ(nullptr, private_values.iframe_2.session_storage); + + EXPECT_EQ("", private_values.main_frame.cookies); + EXPECT_EQ("", private_values.iframe_1.cookies); + EXPECT_EQ("", private_values.iframe_2.cookies); } diff --git a/browser/ephemeral_storage/ephemeral_storage_tab_helper.cc b/browser/ephemeral_storage/ephemeral_storage_tab_helper.cc index a25cff6414e3..3d504b1bc0ff 100644 --- a/browser/ephemeral_storage/ephemeral_storage_tab_helper.cc +++ b/browser/ephemeral_storage/ephemeral_storage_tab_helper.cc @@ -11,13 +11,12 @@ #include "base/feature_list.h" #include "base/hash/md5.h" #include "base/no_destructor.h" -#include "content/public/browser/browser_context.h" #include "content/public/browser/navigation_handle.h" #include "content/public/browser/session_storage_namespace.h" #include "content/public/browser/storage_partition.h" #include "content/public/browser/web_contents.h" -#include "net/base/registry_controlled_domains/registry_controlled_domain.h" -#include "third_party/blink/public/common/features.h" +#include "net/base/features.h" +#include "net/base/url_util.h" using content::BrowserContext; using content::NavigationHandle; @@ -28,18 +27,6 @@ namespace ephemeral_storage { namespace { -std::string URLToStorageDomain(const GURL& url) { - std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( - url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); - - // GetDomainAndRegistry might return an empty string if this host is an IP - // address or a file URL. - if (domain.empty()) - domain = url::Origin::Create(url.GetOrigin()).Serialize(); - - return domain; -} - // Session storage ids are expected to be 36 character long GUID strings. Since // we are constructing our own ids, we convert our string into a 32 character // hash and then use that make up our own GUID-like string. Because of the way @@ -54,15 +41,20 @@ std::string StringToSessionStorageId(const std::string& string, } // namespace +// EphemeralStorageTabHelper helps to manage the lifetime of ephemeral storage. +// For more information about the design of ephemeral storage please see the +// design document at: +// https://github.com/brave/brave-browser/wiki/Ephemeral-Storage-Design EphemeralStorageTabHelper::EphemeralStorageTabHelper(WebContents* web_contents) : WebContentsObserver(web_contents) { - DCHECK(base::FeatureList::IsEnabled(blink::features::kBraveEphemeralStorage)); + DCHECK(base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage)); // The URL might not be empty if this is a restored WebContents, for instance. // In that case we want to make sure it has valid ephemeral storage. const GURL& url = web_contents->GetLastCommittedURL(); if (!url.is_empty()) - CreateEphemeralStorageAreasForDomainAndURL(URLToStorageDomain(url), url); + CreateEphemeralStorageAreasForDomainAndURL( + net::URLToEphemeralStorageDomain(url), url); } EphemeralStorageTabHelper::~EphemeralStorageTabHelper() {} @@ -75,9 +67,9 @@ void EphemeralStorageTabHelper::ReadyToCommitNavigation( return; const GURL& new_url = navigation_handle->GetURL(); - std::string new_domain = URLToStorageDomain(new_url); + std::string new_domain = net::URLToEphemeralStorageDomain(new_url); std::string previous_domain = - URLToStorageDomain(web_contents()->GetLastCommittedURL()); + net::URLToEphemeralStorageDomain(web_contents()->GetLastCommittedURL()); if (new_domain == previous_domain) return; @@ -115,6 +107,9 @@ void EphemeralStorageTabHelper::CreateEphemeralStorageAreasForDomainAndURL( "/ephemeral-session-storage"); session_storage_namespace_ = content::CreateSessionStorageNamespace(partition, session_partition_id); + + tld_ephemeral_lifetime_ = content::TLDEphemeralLifetime::GetOrCreate( + browser_context, partition, new_domain); } WEB_CONTENTS_USER_DATA_KEY_IMPL(EphemeralStorageTabHelper) diff --git a/browser/ephemeral_storage/ephemeral_storage_tab_helper.h b/browser/ephemeral_storage/ephemeral_storage_tab_helper.h index b694254ce5e4..3f9b957ca1b8 100644 --- a/browser/ephemeral_storage/ephemeral_storage_tab_helper.h +++ b/browser/ephemeral_storage/ephemeral_storage_tab_helper.h @@ -9,13 +9,14 @@ #include #include +#include "content/public/browser/browser_context.h" #include "content/public/browser/session_storage_namespace.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" namespace content { -class WebContents; class BrowserContext; +class WebContents; } // namespace content namespace ephemeral_storage { @@ -43,6 +44,7 @@ class EphemeralStorageTabHelper friend class content::WebContentsUserData; scoped_refptr local_storage_namespace_; scoped_refptr session_storage_namespace_; + scoped_refptr tld_ephemeral_lifetime_; WEB_CONTENTS_USER_DATA_KEY_DECL(); }; diff --git a/chromium_src/chrome/browser/about_flags.cc b/chromium_src/chrome/browser/about_flags.cc index 5d9ceb8091b4..4503b7f4a3a4 100644 --- a/chromium_src/chrome/browser/about_flags.cc +++ b/chromium_src/chrome/browser/about_flags.cc @@ -17,13 +17,16 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "components/prefs/pref_service.h" -#include "third_party/blink/public/common/features.h" +#include "net/base/features.h" using brave_shields::features::kBraveAdblockCosmeticFiltering; using ntp_background_images::features::kBraveNTPBrandedWallpaper; using ntp_background_images::features::kBraveNTPBrandedWallpaperDemo; using ntp_background_images::features::kBraveNTPSuperReferralWallpaper; +// clang-format seems to have a lot of issues with the macros in this +// file so we turn it off for the macro sections. +// clang-format off #if BUILDFLAG(ENABLE_SPEEDREADER) #include "brave/components/speedreader/features.h" @@ -89,13 +92,15 @@ using ntp_background_images::features::kBraveNTPSuperReferralWallpaper; {"brave-ephemeral-storage", \ flag_descriptions::kBraveEphemeralStorageName, \ flag_descriptions::kBraveEphemeralStorageDescription, kOsAll, \ - FEATURE_VALUE_TYPE(blink::features::kBraveEphemeralStorage)}, + FEATURE_VALUE_TYPE(net::features::kBraveEphemeralStorage)}, #define SetFeatureEntryEnabled SetFeatureEntryEnabled_ChromiumImpl #include "../../../../chrome/browser/about_flags.cc" // NOLINT #undef SetFeatureEntryEnabled #undef BRAVE_FEATURE_ENTRIES +// clang-format on + namespace about_flags { void UpdateBraveMediaRouterPref(const std::string& internal_name, diff --git a/chromium_src/content/browser/browser_context.cc b/chromium_src/content/browser/browser_context.cc index e2bc57921c7b..5c31576da118 100644 --- a/chromium_src/content/browser/browser_context.cc +++ b/chromium_src/content/browser/browser_context.cc @@ -38,10 +38,12 @@ std::string GetSessionStorageNamespaceId(WebContents* web_contents) { } // namespace content -#include "../../../../content/browser/browser_context.cc" namespace content { bool BrowserContext::IsTor() const { return false; } } // namespace content + +#include "../../../../content/browser/browser_context.cc" +#include "content/browser/tld_ephemeral_lifetime.cc" diff --git a/chromium_src/content/browser/tld_ephemeral_lifetime.cc b/chromium_src/content/browser/tld_ephemeral_lifetime.cc new file mode 100644 index 000000000000..c1547c7db66c --- /dev/null +++ b/chromium_src/content/browser/tld_ephemeral_lifetime.cc @@ -0,0 +1,67 @@ +/* Copyright (c) 2020 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 "content/public/browser/tld_ephemeral_lifetime.h" + +#include +#include "base/no_destructor.h" +#include "services/network/public/mojom/cookie_manager.mojom.h" + +namespace content { + +namespace { + +using TLDEphemeralLifetimeMap = + std::map>; + +// This map allows TLDEphemeralLifetime to manage the lifetime of ephemeral +// storage. We use weak pointers so that we can catch misuse of more easily. +// With weak pointers, these entries will become null if they are destroyed, +// but not removed from the map. +TLDEphemeralLifetimeMap& active_tld_storage_areas() { + static base::NoDestructor active_storage_areas; + return *active_storage_areas.get(); +} + +} // namespace + +TLDEphemeralLifetime::TLDEphemeralLifetime(TLDEphemeralLifetimeKey key, + StoragePartition* storage_partition) + : key_(key), storage_partition_(storage_partition) { + DCHECK(active_tld_storage_areas().find(key) == + active_tld_storage_areas().end()); + active_tld_storage_areas().emplace(key, weak_factory_.GetWeakPtr()); +} + +TLDEphemeralLifetime::~TLDEphemeralLifetime() { + auto filter = network::mojom::CookieDeletionFilter::New(); + filter->ephemeral_storage_domain = key_.second; + storage_partition_->GetCookieManagerForBrowserProcess()->DeleteCookies( + std::move(filter), base::NullCallback()); + + active_tld_storage_areas().erase(key_); +} + +TLDEphemeralLifetime* TLDEphemeralLifetime::Get(BrowserContext* browser_context, + std::string storage_domain) { + TLDEphemeralLifetimeKey key = std::make_pair(browser_context, storage_domain); + auto it = active_tld_storage_areas().find(key); + DCHECK(it == active_tld_storage_areas().end() || it->second.get()); + return it != active_tld_storage_areas().end() ? it->second.get() : nullptr; +} + +scoped_refptr TLDEphemeralLifetime::GetOrCreate( + BrowserContext* browser_context, + StoragePartition* storage_partition, + std::string storage_domain) { + if (TLDEphemeralLifetime* existing = Get(browser_context, storage_domain)) { + return existing; + } + + TLDEphemeralLifetimeKey key = std::make_pair(browser_context, storage_domain); + return base::MakeRefCounted(key, storage_partition); +} + +} // namespace content diff --git a/chromium_src/content/public/browser/browser_context.h b/chromium_src/content/public/browser/browser_context.h index d5f552d015f4..b78fa9d2e219 100644 --- a/chromium_src/content/public/browser/browser_context.h +++ b/chromium_src/content/public/browser/browser_context.h @@ -15,6 +15,7 @@ #include "base/memory/ref_counted.h" #include "content/common/content_export.h" +#include "content/public/browser/tld_ephemeral_lifetime.h" namespace content { diff --git a/chromium_src/content/public/browser/tld_ephemeral_lifetime.h b/chromium_src/content/public/browser/tld_ephemeral_lifetime.h new file mode 100644 index 000000000000..c242fc452748 --- /dev/null +++ b/chromium_src/content/public/browser/tld_ephemeral_lifetime.h @@ -0,0 +1,59 @@ +/* Copyright (c) 2020 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_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_TLD_EPHEMERAL_LIFETIME_H_ +#define BRAVE_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_TLD_EPHEMERAL_LIFETIME_H_ + +#include +#include +#include "base/memory/ref_counted.h" +#include "base/memory/weak_ptr.h" +#include "content/common/content_export.h" + +namespace content { + +class BrowserContext; +class SessionStorageNamespace; +class StoragePartition; +class StoragePartition; +class WebContents; + +// TLD storage is keyed by the BrowserContext (profile) and the TLD-specific +// security domain. +using TLDEphemeralLifetimeKey = + std::pair; + +// This class is responsible for managing the lifetime of ephemeral storage +// cookies. Each instance is shared by each top-level frame with the same +// TLDEphemeralLifetimeKey. When the last top-level frame holding a reference +// is destroyed or navigates to a new storage domain, storage will be +// cleared. +// +// TODO(mrobinson): Have this class also manage ephemeral local storage and +// take care of handing out new instances of session storage. +class CONTENT_EXPORT TLDEphemeralLifetime + : public base::RefCounted { + public: + TLDEphemeralLifetime(TLDEphemeralLifetimeKey key, + StoragePartition* storage_partition); + static TLDEphemeralLifetime* Get(BrowserContext*, std::string storage_domain); + static scoped_refptr GetOrCreate( + BrowserContext* browser_context, + StoragePartition* storage_partition, + std::string storage_domain); + + private: + friend class RefCounted; + virtual ~TLDEphemeralLifetime(); + + TLDEphemeralLifetimeKey key_; + StoragePartition* storage_partition_; + + base::WeakPtrFactory weak_factory_{this}; +}; + +} // namespace content + +#endif // BRAVE_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_TLD_EPHEMERAL_LIFETIME_H_ diff --git a/chromium_src/third_party/blink/common/features.cc b/chromium_src/net/base/features.cc similarity index 81% rename from chromium_src/third_party/blink/common/features.cc rename to chromium_src/net/base/features.cc index 45e76b474a27..e181db847157 100644 --- a/chromium_src/third_party/blink/common/features.cc +++ b/chromium_src/net/base/features.cc @@ -3,11 +3,11 @@ * 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 "../../../../../third_party/blink/common/features.cc" +#include "../../../../../../../net/base/features.cc" -namespace blink { +namespace net { namespace features { const base::Feature kBraveEphemeralStorage{"EphemeralStorage", base::FEATURE_DISABLED_BY_DEFAULT}; } // namespace features -} // namespace blink +} // namespace net diff --git a/chromium_src/net/base/features.h b/chromium_src/net/base/features.h new file mode 100644 index 000000000000..07b6ec0c000b --- /dev/null +++ b/chromium_src/net/base/features.h @@ -0,0 +1,22 @@ +/* Copyright (c) 2020 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_CHROMIUM_SRC_NET_BASE_FEATURES_H_ +#define BRAVE_CHROMIUM_SRC_NET_BASE_FEATURES_H_ + +#include "base/feature_list.h" +#include "net/base/net_export.h" + +namespace net { +namespace features { + +NET_EXPORT extern const base::Feature kBraveEphemeralStorage; + +} // namespace features +} // namespace net + +#include "../../../../../../net/base/features.h" + +#endif // BRAVE_CHROMIUM_SRC_NET_BASE_FEATURES_H_ diff --git a/chromium_src/net/base/url_util.cc b/chromium_src/net/base/url_util.cc index bd7f498930d5..7908aa102ba1 100644 --- a/chromium_src/net/base/url_util.cc +++ b/chromium_src/net/base/url_util.cc @@ -8,6 +8,8 @@ #include #include "base/strings/string_piece.h" +#include "net/base/registry_controlled_domains/registry_controlled_domain.h" +#include "url/origin.h" #include "url/third_party/mozilla/url_parse.h" #include "url/url_canon_ip.h" @@ -80,4 +82,16 @@ bool ParseAuthHostAndPort(base::StringPiece input, return true; // Success. } +std::string URLToEphemeralStorageDomain(const GURL& url) { + std::string domain = registry_controlled_domains::GetDomainAndRegistry( + url, registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); + + // GetDomainAndRegistry might return an empty string if this host is an IP + // address or a file URL. + if (domain.empty()) + domain = url::Origin::Create(url.GetOrigin()).Serialize(); + + return domain; } + +} // namespace net diff --git a/chromium_src/net/base/url_util.h b/chromium_src/net/base/url_util.h index a120771b03ac..a181ac82d4ff 100644 --- a/chromium_src/net/base/url_util.h +++ b/chromium_src/net/base/url_util.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef BRAVE_NET_BASE_URL_AUTH_UTIL_H_ -#define BRAVE_NET_BASE_URL_AUTH_UTIL_H_ +#ifndef BRAVE_CHROMIUM_SRC_NET_BASE_URL_UTIL_H_ +#define BRAVE_CHROMIUM_SRC_NET_BASE_URL_UTIL_H_ #include "../../../../net/base/url_util.h" @@ -19,6 +19,10 @@ NET_EXPORT bool ParseAuthHostAndPort( std::string* host, int* port); -} +// Convert this URL into an encoded storage domain string, which is used +// to identify a particular storage domain uniquely in a BrowserContext. +NET_EXPORT std::string URLToEphemeralStorageDomain(const GURL& url); -#endif // BRAVE_NET_BASE_URL_AUTH_UTIL_H_ +} // namespace net + +#endif // BRAVE_CHROMIUM_SRC_NET_BASE_URL_UTIL_H_ diff --git a/chromium_src/net/cookies/cookie_deletion_info.h b/chromium_src/net/cookies/cookie_deletion_info.h new file mode 100644 index 000000000000..d0fa0e038327 --- /dev/null +++ b/chromium_src/net/cookies/cookie_deletion_info.h @@ -0,0 +1,16 @@ +/* Copyright (c) 2020 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_CHROMIUM_SRC_NET_COOKIES_COOKIE_DELETION_INFO_H_ +#define BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_DELETION_INFO_H_ + +#define BRAVE_COOKIE_DELETION_INFO_H \ + base::Optional ephemeral_storage_domain; + +#include "../../../../../../net/cookies/cookie_deletion_info.h" + +#undef BRAVE_COOKIE_DELETION_INFO_H + +#endif // BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_DELETION_INFO_H_ diff --git a/chromium_src/net/cookies/cookie_monster.cc b/chromium_src/net/cookies/cookie_monster.cc new file mode 100644 index 000000000000..e0f488585dd2 --- /dev/null +++ b/chromium_src/net/cookies/cookie_monster.cc @@ -0,0 +1,120 @@ +/* Copyright (c) 2020 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 https://mozilla.org/MPL/2.0/. */ + +#include "net/cookies/cookie_monster.h" + +#include +#include "net/base/url_util.h" + +#define CookieMonster ChromiumCookieMonster +#include "../../../../net/cookies/cookie_monster.cc" +#undef CookieMonster + +namespace net { + +CookieMonster::CookieMonster(scoped_refptr store, + NetLog* net_log) + : ChromiumCookieMonster(store, net_log), + net_log_( + NetLogWithSource::Make(net_log, NetLogSourceType::COOKIE_STORE)) {} + +CookieMonster::CookieMonster(scoped_refptr store, + base::TimeDelta last_access_threshold, + NetLog* net_log) + : ChromiumCookieMonster(store, last_access_threshold, net_log), + net_log_( + NetLogWithSource::Make(net_log, NetLogSourceType::COOKIE_STORE)) {} + +CookieMonster::~CookieMonster() {} + +ChromiumCookieMonster* +CookieMonster::GetOrCreateEphemeralCookieStoreForTopFrameURL( + const GURL& top_frame_url) { + std::string domain = URLToEphemeralStorageDomain(top_frame_url); + auto it = ephemeral_cookie_stores_.find(domain); + if (it != ephemeral_cookie_stores_.end()) + return it->second.get(); + + return ephemeral_cookie_stores_ + .emplace(domain, new ChromiumCookieMonster(nullptr /* store */, + net_log_.net_log())) + .first->second.get(); +} + +void CookieMonster::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, + DeleteCallback callback) { + for (auto& it : ephemeral_cookie_stores_) { + it.second->DeleteCanonicalCookieAsync(cookie, DeleteCallback()); + } + ChromiumCookieMonster::DeleteCanonicalCookieAsync(cookie, + std::move(callback)); +} + +void CookieMonster::DeleteAllCreatedInTimeRangeAsync( + const CookieDeletionInfo::TimeRange& creation_range, + DeleteCallback callback) { + for (auto& it : ephemeral_cookie_stores_) { + it.second->DeleteAllCreatedInTimeRangeAsync(creation_range, + DeleteCallback()); + } + ChromiumCookieMonster::DeleteAllCreatedInTimeRangeAsync(creation_range, + std::move(callback)); +} + +void CookieMonster::DeleteAllMatchingInfoAsync(CookieDeletionInfo delete_info, + DeleteCallback callback) { + if (delete_info.ephemeral_storage_domain.has_value()) { + ephemeral_cookie_stores_.erase(*delete_info.ephemeral_storage_domain); + std::move(callback).Run(0); + return; + } + + for (auto& it : ephemeral_cookie_stores_) { + it.second->DeleteAllMatchingInfoAsync(delete_info, DeleteCallback()); + } + ChromiumCookieMonster::DeleteAllMatchingInfoAsync(delete_info, + std::move(callback)); +} + +void CookieMonster::DeleteSessionCookiesAsync(DeleteCallback callback) { + for (auto& it : ephemeral_cookie_stores_) { + it.second->DeleteSessionCookiesAsync(DeleteCallback()); + } + ChromiumCookieMonster::DeleteSessionCookiesAsync(std::move(callback)); +} + +void CookieMonster::SetCookieableSchemes( + const std::vector& schemes, + SetCookieableSchemesCallback callback) { + for (auto& it : ephemeral_cookie_stores_) { + it.second->SetCookieableSchemes(schemes, SetCookieableSchemesCallback()); + } + ChromiumCookieMonster::SetCookieableSchemes(schemes, std::move(callback)); +} + +void CookieMonster::GetEphemeralCookieListWithOptionsAsync( + const GURL& url, + const GURL& top_frame_url, + const CookieOptions& options, + GetCookieListCallback callback) { + ChromiumCookieMonster* ephemeral_monster = + GetOrCreateEphemeralCookieStoreForTopFrameURL(top_frame_url); + ephemeral_monster->GetCookieListWithOptionsAsync(url, options, + std::move(callback)); +} + +void CookieMonster::SetEphemeralCanonicalCookieAsync( + std::unique_ptr cookie, + const GURL& source_url, + const GURL& top_frame_url, + const CookieOptions& options, + SetCookiesCallback callback) { + ChromiumCookieMonster* ephemeral_monster = + GetOrCreateEphemeralCookieStoreForTopFrameURL(top_frame_url); + ephemeral_monster->SetCanonicalCookieAsync(std::move(cookie), source_url, + options, std::move(callback)); +} + +} // namespace net diff --git a/chromium_src/net/cookies/cookie_monster.h b/chromium_src/net/cookies/cookie_monster.h new file mode 100644 index 000000000000..375ce3476024 --- /dev/null +++ b/chromium_src/net/cookies/cookie_monster.h @@ -0,0 +1,60 @@ +/* Copyright (c) 2020 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_CHROMIUM_SRC_NET_COOKIES_COOKIE_MONSTER_H_ +#define BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_MONSTER_H_ + +#define CookieMonster ChromiumCookieMonster +#include "../../../../../../net/cookies/cookie_monster.h" +#undef CookieMonster + +namespace net { + +class NET_EXPORT CookieMonster : public ChromiumCookieMonster { + public: + // These constructors and destructors must be kept in sync with those in + // Chromium's CookieMonster. + CookieMonster(scoped_refptr store, NetLog* net_log); + CookieMonster(scoped_refptr store, + base::TimeDelta last_access_threshold, + NetLog* net_log); + ~CookieMonster() override; + + // CookieStore implementation. + // + // This only includes methods that needs special behavior to deal with + // our collection of ephemeral monsters. + void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie, + DeleteCallback callback) override; + void DeleteAllCreatedInTimeRangeAsync( + const CookieDeletionInfo::TimeRange& creation_range, + DeleteCallback callback) override; + void DeleteAllMatchingInfoAsync(CookieDeletionInfo delete_info, + DeleteCallback callback) override; + void DeleteSessionCookiesAsync(DeleteCallback) override; + void SetCookieableSchemes(const std::vector& schemes, + SetCookieableSchemesCallback callback) override; + + void GetEphemeralCookieListWithOptionsAsync(const GURL& url, + const GURL& top_frame_url, + const CookieOptions& options, + GetCookieListCallback callback); + void SetEphemeralCanonicalCookieAsync(std::unique_ptr cookie, + const GURL& source_url, + const GURL& top_frame_url, + const CookieOptions& options, + SetCookiesCallback callback); + + private: + NetLogWithSource net_log_; + std::map> + ephemeral_cookie_stores_; + ChromiumCookieMonster* GetOrCreateEphemeralCookieStoreForTopFrameURL( + const GURL& top_frame_url); +}; + +} // namespace net + +#endif // BRAVE_CHROMIUM_SRC_NET_COOKIES_COOKIE_MONSTER_H_ diff --git a/chromium_src/services/network/cookie_manager.cc b/chromium_src/services/network/cookie_manager.cc new file mode 100644 index 000000000000..7d0c4d718a18 --- /dev/null +++ b/chromium_src/services/network/cookie_manager.cc @@ -0,0 +1,12 @@ +/* Copyright (c) 2020 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 "services/network/restricted_cookie_manager.h" + +#define BRAVE_DELETIONFILTERTOINFO \ + delete_info.ephemeral_storage_domain = \ + std::move(filter->ephemeral_storage_domain); + +#include "../../../../../services/network/cookie_manager.cc" diff --git a/chromium_src/services/network/restricted_cookie_manager.cc b/chromium_src/services/network/restricted_cookie_manager.cc new file mode 100644 index 000000000000..e43a45bdc709 --- /dev/null +++ b/chromium_src/services/network/restricted_cookie_manager.cc @@ -0,0 +1,48 @@ +/* Copyright (c) 2020 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 "services/network/restricted_cookie_manager.h" + +#include "net/base/features.h" +#include "net/cookies/cookie_monster.h" + +namespace { + +bool ShouldUseEphemeralStorage(const GURL& url, + const url::Origin& top_frame_origin) { + if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage)) + return false; + if (url::Origin::Create(url) == top_frame_origin) + return false; + return true; +} + +} // namespace + +#define BRAVE_GETALLFORURL \ + if (ShouldUseEphemeralStorage(url, top_frame_origin)) { \ + static_cast(cookie_store_) \ + ->GetEphemeralCookieListWithOptionsAsync( \ + url, top_frame_origin.GetURL(), net_options, \ + base::BindOnce( \ + &RestrictedCookieManager::CookieListToGetAllForUrlCallback, \ + weak_ptr_factory_.GetWeakPtr(), url, site_for_cookies, \ + top_frame_origin, net_options, std::move(options), \ + std::move(callback))); \ + } else // NOLINT + +#define BRAVE_SETCANONICALCOOKIE \ + if (ShouldUseEphemeralStorage(url, top_frame_origin)) { \ + static_cast(cookie_store_) \ + ->SetEphemeralCanonicalCookieAsync( \ + std::move(sanitized_cookie), origin_.GetURL(), \ + top_frame_origin.GetURL(), options, \ + base::BindOnce(&RestrictedCookieManager::SetCanonicalCookieResult, \ + weak_ptr_factory_.GetWeakPtr(), url, \ + site_for_cookies, cookie_copy, options, \ + std::move(callback))); \ + } else // NOLINT + +#include "../../../../../services/network/restricted_cookie_manager.cc" diff --git a/chromium_src/third_party/blink/public/common/features.h b/chromium_src/third_party/blink/public/common/features.h deleted file mode 100644 index 4c19a76945c4..000000000000 --- a/chromium_src/third_party/blink/public/common/features.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright (c) 2020 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_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURES_H_ -#define BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURES_H_ - -#include "base/feature_list.h" -#include "third_party/blink/public/common/common_export.h" - -namespace blink { -namespace features { - -BLINK_COMMON_EXPORT extern const base::Feature kBraveEphemeralStorage; - -} // namespace features -} // namespace blink - -#include "../../../../../../third_party/blink/public/common/features.h" - -#undef BRAVE_FEATURES_H - -#endif // BRAVE_CHROMIUM_SRC_THIRD_PARTY_BLINK_PUBLIC_COMMON_FEATURES_H_ diff --git a/chromium_src/third_party/blink/renderer/modules/storage/dom_window_storage.cc b/chromium_src/third_party/blink/renderer/modules/storage/dom_window_storage.cc index caf6e15a4ab7..3e03e94a2b55 100644 --- a/chromium_src/third_party/blink/renderer/modules/storage/dom_window_storage.cc +++ b/chromium_src/third_party/blink/renderer/modules/storage/dom_window_storage.cc @@ -4,8 +4,8 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "../../../../../../../third_party/blink/renderer/modules/storage/dom_window_storage.cc" +#include "net/base/features.h" #include "third_party/blink/public/common/dom_storage/session_storage_namespace_id.h" -#include "third_party/blink/public/common/features.h" #include "third_party/blink/public/web/web_view_client.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/exported/web_view_impl.h" @@ -170,7 +170,7 @@ StorageArea* BraveDOMWindowStorage::sessionStorage( DOMWindowStorage::From(*window).sessionStorage(exception_state); MaybeClearAccessDeniedException(storage, *window, &exception_state); - if (!base::FeatureList::IsEnabled(features::kBraveEphemeralStorage)) + if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage)) return storage; if (!window->IsCrossSiteSubframe()) @@ -210,7 +210,7 @@ StorageArea* BraveDOMWindowStorage::localStorage( auto* storage = DOMWindowStorage::From(*window).localStorage(exception_state); MaybeClearAccessDeniedException(storage, *window, &exception_state); - if (!base::FeatureList::IsEnabled(features::kBraveEphemeralStorage)) + if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage)) return storage; if (!window->IsCrossSiteSubframe()) diff --git a/patches/net-cookies-cookie_deletion_info.h.patch b/patches/net-cookies-cookie_deletion_info.h.patch new file mode 100644 index 000000000000..0bb402557577 --- /dev/null +++ b/patches/net-cookies-cookie_deletion_info.h.patch @@ -0,0 +1,12 @@ +diff --git a/net/cookies/cookie_deletion_info.h b/net/cookies/cookie_deletion_info.h +index be0bdaab1460fc6f4f54263c588e54822cc70884..7645f5721cbd96ca17436e5a5e901d1e7304b738 100644 +--- a/net/cookies/cookie_deletion_info.h ++++ b/net/cookies/cookie_deletion_info.h +@@ -137,6 +137,7 @@ struct NET_EXPORT CookieDeletionInfo { + + // Used only for testing purposes. + base::Optional value_for_testing; ++ BRAVE_COOKIE_DELETION_INFO_H + }; + + } // namespace net diff --git a/patches/services-network-cookie_manager.cc.patch b/patches/services-network-cookie_manager.cc.patch new file mode 100644 index 000000000000..82383d646130 --- /dev/null +++ b/patches/services-network-cookie_manager.cc.patch @@ -0,0 +1,12 @@ +diff --git a/services/network/cookie_manager.cc b/services/network/cookie_manager.cc +index 1d988375b00a73824341e46da45645d3d7e8c30e..bbb291a955e0c6397014a91b9ca0dff43f818384 100644 +--- a/services/network/cookie_manager.cc ++++ b/services/network/cookie_manager.cc +@@ -295,6 +295,7 @@ CookieDeletionInfo DeletionFilterToInfo(mojom::CookieDeletionFilterPtr filter) { + delete_info.name = std::move(filter->cookie_name); + delete_info.url = std::move(filter->url); + delete_info.host = std::move(filter->host_name); ++ BRAVE_DELETIONFILTERTOINFO + + switch (filter->session_control) { + case mojom::CookieDeletionSessionControl::IGNORE_CONTROL: diff --git a/patches/services-network-public-mojom-cookie_manager.mojom.patch b/patches/services-network-public-mojom-cookie_manager.mojom.patch new file mode 100644 index 000000000000..33e37269bc57 --- /dev/null +++ b/patches/services-network-public-mojom-cookie_manager.mojom.patch @@ -0,0 +1,12 @@ +diff --git a/services/network/public/mojom/cookie_manager.mojom b/services/network/public/mojom/cookie_manager.mojom +index efb5fa353efa87c39de48c477c0bddd8dc4d4b19..f6a9a246963cbad38b66ae21ca06341f8675b277 100644 +--- a/services/network/public/mojom/cookie_manager.mojom ++++ b/services/network/public/mojom/cookie_manager.mojom +@@ -250,6 +250,7 @@ struct CookieDeletionFilter { + + // Delete session/persistent cookies. + CookieDeletionSessionControl session_control = IGNORE_CONTROL; ++ string? ephemeral_storage_domain; + }; + + interface CookieChangeListener { diff --git a/patches/services-network-restricted_cookie_manager.cc.patch b/patches/services-network-restricted_cookie_manager.cc.patch new file mode 100644 index 000000000000..adbbbdadd24c --- /dev/null +++ b/patches/services-network-restricted_cookie_manager.cc.patch @@ -0,0 +1,20 @@ +diff --git a/services/network/restricted_cookie_manager.cc b/services/network/restricted_cookie_manager.cc +index 9c1e99cfef255e78942590298d7b7edc1946674e..1a02ecfec9c19973c8d5c977cbe44bd287eacd3e 100644 +--- a/services/network/restricted_cookie_manager.cc ++++ b/services/network/restricted_cookie_manager.cc +@@ -248,6 +248,7 @@ void RestrictedCookieManager::GetAllForUrl( + // removing deprecation warnings. + net_options.set_return_excluded_cookies(); + ++ BRAVE_GETALLFORURL + cookie_store_->GetCookieListWithOptionsAsync( + url, net_options, + base::BindOnce(&RestrictedCookieManager::CookieListToGetAllForUrlCallback, +@@ -393,6 +394,7 @@ void RestrictedCookieManager::SetCanonicalCookie( + + net::CookieOptions options = + MakeOptionsForSet(role_, url, site_for_cookies, cookie_settings()); ++ BRAVE_SETCANONICALCOOKIE + // TODO(chlily): |url| is validated to be the same origin as |origin_|, but + // the path is not checked. If we ever decide to enforce the path constraint + // for setting a cookie, we would need to validate the path of |url| somehow