From e213f859de3ce46bf69532640962d3ffd5cf84f1 Mon Sep 17 00:00:00 2001 From: Brian Johnson Date: Tue, 28 Apr 2020 08:03:06 -0700 Subject: [PATCH] Merge pull request #5390 from brave/3rd-party-cookie-registry-domains 3rd party cookie registry domains This excludes changes to `browser/net/brave_network_delegate_browsertest.cc` --- .../net/brave_network_delegate_browsertest.cc | 1 - .../brave_content_settings_pref_provider.cc | 31 +++++++++++-------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/browser/net/brave_network_delegate_browsertest.cc b/browser/net/brave_network_delegate_browsertest.cc index 2cff47395a01..1da510daed23 100644 --- a/browser/net/brave_network_delegate_browsertest.cc +++ b/browser/net/brave_network_delegate_browsertest.cc @@ -466,4 +466,3 @@ IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest, NavigateFrameTo(google_oauth_cookie_url_); ExpectCookiesOnHost(GURL("https://accounts.google.com"), ""); } - diff --git a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc index a285175bb46e..9702f543f490 100644 --- a/components/content_settings/core/browser/brave_content_settings_pref_provider.cc +++ b/components/content_settings/core/browser/brave_content_settings_pref_provider.cc @@ -22,30 +22,35 @@ #include "components/prefs/pref_service.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" +#include "net/base/registry_controlled_domains/registry_controlled_domain.h" namespace content_settings { namespace { Rule CloneRule(const Rule& rule, bool reverse_patterns = false) { - auto secondary_pattern = rule.secondary_pattern; - if (secondary_pattern == + // brave plugin rules incorrectly use first party url as primary + auto primary_pattern = reverse_patterns ? rule.secondary_pattern + : rule.primary_pattern; + auto secondary_pattern = reverse_patterns ? rule.primary_pattern + : rule.secondary_pattern; + + if (primary_pattern == ContentSettingsPattern::FromString("https://firstParty/*")) { - if (!rule.primary_pattern.MatchesAllHosts()) { - secondary_pattern = ContentSettingsPattern::FromString( - "*://[*.]" + rule.primary_pattern.GetHost() + "/*"); + DCHECK(reverse_patterns); // we should only hit this for brave plugin rules + if (!secondary_pattern.MatchesAllHosts()) { + primary_pattern = ContentSettingsPattern::FromString( + "*://[*.]" + + net::registry_controlled_domains::GetDomainAndRegistry( + secondary_pattern.GetHost(), + net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES) + + "/*"); } else { - secondary_pattern = rule.primary_pattern; + primary_pattern = secondary_pattern; } } - // brave plugin rules incorrectly use the embedded url as the primary - if (reverse_patterns) - return Rule(secondary_pattern, - rule.primary_pattern, - rule.value.Clone()); - - return Rule(rule.primary_pattern, + return Rule(primary_pattern, secondary_pattern, rule.value.Clone()); }