-
Notifications
You must be signed in to change notification settings - Fork 920
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow first party iframes embedded in 3rd-party origins plus exceptio…
…ns for wp/wordpress and playstation/sonyentertainmentnetwork fix brave/brave-browser#8629 fix brave/brave-browser#9564
- Loading branch information
Showing
5 changed files
with
185 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
chromium_src/components/content_settings/core/common/cookie_settings_base.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "components/content_settings/core/common/cookie_settings_base.h" | ||
|
||
#include "base/containers/flat_map.h" | ||
#include "base/no_destructor.h" | ||
#include "base/optional.h" | ||
#include "net/base/registry_controlled_domains/registry_controlled_domain.h" | ||
#include "components/content_settings/core/common/content_settings.h" | ||
#include "components/content_settings/core/common/content_settings_pattern.h" | ||
#include "url/gurl.h" | ||
#include "url/origin.h" | ||
|
||
namespace content_settings { | ||
|
||
namespace { | ||
|
||
constexpr char kWp[] = "https://[*.]wp.com/*"; | ||
constexpr char kWordpress[] = "https://[*.]wordpress.com/*"; | ||
constexpr char kPlaystation[] = "https://[*.]playstation.com/*"; | ||
constexpr char kSonyentertainmentnetwork[] = | ||
"https://[*.]sonyentertainmentnetwork.com/*"; | ||
|
||
bool BraveIsAllowedThirdParty( | ||
const GURL& url, | ||
const GURL& site_for_cookies, | ||
const base::Optional<url::Origin>& top_frame_origin) { | ||
static const base::NoDestructor< | ||
// url -> first_party_url allow map | ||
std::vector<std::pair<ContentSettingsPattern, | ||
ContentSettingsPattern>>> entity_list({ | ||
{ | ||
ContentSettingsPattern::FromString(kWp), | ||
ContentSettingsPattern::FromString(kWordpress) | ||
}, | ||
{ | ||
ContentSettingsPattern::FromString(kWordpress), | ||
ContentSettingsPattern::FromString(kWp) | ||
}, | ||
{ | ||
ContentSettingsPattern::FromString(kPlaystation), | ||
ContentSettingsPattern::FromString(kSonyentertainmentnetwork)}, | ||
{ | ||
ContentSettingsPattern::FromString(kSonyentertainmentnetwork), | ||
ContentSettingsPattern::FromString(kPlaystation) | ||
}, | ||
}); | ||
|
||
GURL first_party_url = site_for_cookies; | ||
|
||
if (!first_party_url.is_valid() && top_frame_origin) | ||
first_party_url = top_frame_origin->GetURL(); | ||
|
||
if (net::registry_controlled_domains::GetDomainAndRegistry( | ||
url, | ||
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES) == | ||
net::registry_controlled_domains::GetDomainAndRegistry( | ||
first_party_url, | ||
net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)) | ||
return true; | ||
|
||
for (auto i = entity_list->begin(); | ||
i != entity_list->end(); | ||
++i) { | ||
if (i->first.Matches(url) && i->second.Matches(first_party_url)) | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace | ||
|
||
bool CookieSettingsBase::IsCookieAccessAllowed( | ||
const GURL& url, const GURL& first_party_url) const { | ||
return IsCookieAccessAllowed(url, first_party_url, base::nullopt); | ||
} | ||
|
||
bool CookieSettingsBase::IsCookieAccessAllowed( | ||
const GURL& url, | ||
const GURL& site_for_cookies, | ||
const base::Optional<url::Origin>& top_frame_origin) const { | ||
|
||
// get content settings only - do not consider default 3rd-party blocking | ||
ContentSetting setting; | ||
GetCookieSettingInternal( | ||
url, top_frame_origin ? top_frame_origin->GetURL() : site_for_cookies, | ||
false, nullptr, &setting); | ||
|
||
// content settings should always override any defaults | ||
if (!IsAllowed(setting)) | ||
return false; | ||
|
||
if (BraveIsAllowedThirdParty(url, site_for_cookies, top_frame_origin)) | ||
return true; | ||
|
||
return IsChromiumCookieAccessAllowed(url, site_for_cookies, top_frame_origin); | ||
} | ||
|
||
} // namespce content_settings | ||
|
||
#define IsCookieAccessAllowed IsChromiumCookieAccessAllowed | ||
#include "../../../../../../components/content_settings/core/common/cookie_settings_base.cc" // NOLINT | ||
#undef IsCookieAccessAllowed |
22 changes: 22 additions & 0 deletions
22
chromium_src/components/content_settings/core/common/cookie_settings_base.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Copyright (c) 2020 The Brave Authors. All rights reserved. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_COOKIE_SETTINGS_BASE_H_ | ||
#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_COOKIE_SETTINGS_BASE_H_ | ||
|
||
#define BRAVE_COOKIE_SETTINGS_BASE_H \ | ||
private: \ | ||
bool IsChromiumCookieAccessAllowed(const GURL& url, \ | ||
const GURL& first_party_url) const; \ | ||
bool IsChromiumCookieAccessAllowed( \ | ||
const GURL& url, \ | ||
const GURL& site_for_cookies, \ | ||
const base::Optional<url::Origin>& top_frame_origin) const; | ||
|
||
#include "../../../../../../components/content_settings/core/common/cookie_settings_base.h" | ||
|
||
#undef BRAVE_COOKIE_SETTINGS_BASE_H | ||
|
||
#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_COOKIE_SETTINGS_BASE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
patches/components-content_settings-core-common-cookie_settings_base.h.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/components/content_settings/core/common/cookie_settings_base.h b/components/content_settings/core/common/cookie_settings_base.h | ||
index fb41bd86314482bb8f9116e4da454c7913b74158..987040b59709fc7cca7a28ea75a880fc5bc6171a 100644 | ||
--- a/components/content_settings/core/common/cookie_settings_base.h | ||
+++ b/components/content_settings/core/common/cookie_settings_base.h | ||
@@ -169,6 +169,7 @@ class CookieSettingsBase { | ||
// Determines whether |setting| is a valid content setting for legacy cookie | ||
// access. | ||
static bool IsValidSettingForLegacyAccess(ContentSetting setting); | ||
+ BRAVE_COOKIE_SETTINGS_BASE_H | ||
|
||
private: | ||
virtual void GetCookieSettingInternal( |