Skip to content

Commit

Permalink
Merge pull request #3705 from brave/pr3694_issues/6389_0.71.x
Browse files Browse the repository at this point in the history
set wildcard last so content settings observer picks up the right value (uplift to 0.71.x)
  • Loading branch information
bsclifton authored Oct 16, 2019
2 parents fb6bda0 + fce6ba2 commit a5439d7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
18 changes: 18 additions & 0 deletions browser/net/brave_network_delegate_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
10 changes: 5 additions & 5 deletions components/brave_shields/browser/brave_shields_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,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) {
Expand Down
1 change: 1 addition & 0 deletions test/data/nested_iframe_script.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html><head><title>nested iframe script test</title></head>
<body>
<script src="/cross-site/a.com/script_cookies.js"></script>
<iframe src="/cross-site/c.com/iframe_script_cookie.html" id="nested_iframe_script"></iframe>
</body></html>

0 comments on commit a5439d7

Please sign in to comment.