From fce6ba2e6529b6b9c004c852f0b4f9e4bbf328cb Mon Sep 17 00:00:00 2001 From: bridiver Date: Mon, 14 Oct 2019 16:09:07 -0700 Subject: [PATCH] set wildcard last so content settings observer picks up the right value fix https://github.com/brave/brave-browser/issues/6389 --- .../net/brave_network_delegate_browsertest.cc | 18 ++++++++++++++++++ .../browser/brave_shields_util.cc | 10 +++++----- test/data/nested_iframe_script.html | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/browser/net/brave_network_delegate_browsertest.cc b/browser/net/brave_network_delegate_browsertest.cc index 9777d9a31ebf..e3a64668e8c3 100644 --- a/browser/net/brave_network_delegate_browsertest.cc +++ b/browser/net/brave_network_delegate_browsertest.cc @@ -47,6 +47,12 @@ class BraveNetworkDelegateBrowserTest : public InProcessBrowserTest { return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); } + void DefaultBlockAllCookies() { + brave_shields::SetCookieControlType(browser()->profile(), + brave_shields::ControlType::BLOCK, + GURL()); + } + void AllowCookies() { brave_shields::SetCookieControlType(browser()->profile(), brave_shields::ControlType::ALLOW, @@ -98,3 +104,15 @@ IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest, content::GetCookies(browser()->profile(), GURL("http://c.com/")); EXPECT_FALSE(cookie.empty()); } + +IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest, + DefaultCookiesBlocked) { + DefaultBlockAllCookies(); + ui_test_utils::NavigateToURL(browser(), nested_iframe_script_url_); + std::string cookie = + content::GetCookies(browser()->profile(), GURL("http://c.com/")); + EXPECT_TRUE(cookie.empty()) << "Actual cookie: " << cookie; + cookie = + content::GetCookies(browser()->profile(), GURL("http://a.com/")); + EXPECT_TRUE(cookie.empty()) << "Actual cookie: " << cookie; +} diff --git a/components/brave_shields/browser/brave_shields_util.cc b/components/brave_shields/browser/brave_shields_util.cc index c6d1dfa1a8b9..793886b156ea 100644 --- a/components/brave_shields/browser/brave_shields_util.cc +++ b/components/brave_shields/browser/brave_shields_util.cc @@ -210,16 +210,16 @@ void SetCookieControlType(HostContentSettingsMap* map, CONTENT_SETTINGS_TYPE_PLUGINS, kReferrers, GetDefaultBlockFromControlType(type)); - map->SetContentSettingCustomScope(primary_pattern, - ContentSettingsPattern::Wildcard(), - CONTENT_SETTINGS_TYPE_PLUGINS, kCookies, - GetDefaultBlockFromControlType(type)); - map->SetContentSettingCustomScope( primary_pattern, ContentSettingsPattern::FromString("https://firstParty/*"), CONTENT_SETTINGS_TYPE_PLUGINS, kCookies, GetDefaultAllowFromControlType(type)); + + map->SetContentSettingCustomScope(primary_pattern, + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_PLUGINS, kCookies, + GetDefaultBlockFromControlType(type)); } ControlType GetCookieControlType(HostContentSettingsMap* map, const GURL& url) { diff --git a/test/data/nested_iframe_script.html b/test/data/nested_iframe_script.html index c13ac626bebd..cd9c7c7ed311 100644 --- a/test/data/nested_iframe_script.html +++ b/test/data/nested_iframe_script.html @@ -1,5 +1,6 @@ nested iframe script test +