Skip to content

Commit

Permalink
Merge pull request #5409 from brave/3rd-party-cookie-registry-domains…
Browse files Browse the repository at this point in the history
…-1.8.x

3rd party cookie registry domains (uplift to 1.8.x)
  • Loading branch information
kjozwiak authored May 4, 2020
2 parents 0067bca + e213f85 commit 93ec785
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion browser/net/brave_network_delegate_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,3 @@ IN_PROC_BROWSER_TEST_F(BraveNetworkDelegateBrowserTest,
NavigateFrameTo(google_oauth_cookie_url_);
ExpectCookiesOnHost(GURL("https://accounts.google.com"), "");
}

Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 93ec785

Please sign in to comment.