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()); }