-
Notifications
You must be signed in to change notification settings - Fork 868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
only use ephemeral storage for block 3p setting #7647
Changes from all commits
54d02cc
64e699d
83a051b
2d2c856
83e12cf
8ed2e0d
3cabed1
0f70edb
11650e3
bed4ed0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
#include "base/feature_list.h" | ||
#include "base/hash/md5.h" | ||
#include "base/no_destructor.h" | ||
#include "base/optional.h" | ||
#include "content/public/browser/navigation_handle.h" | ||
#include "content/public/browser/session_storage_namespace.h" | ||
#include "content/public/browser/storage_partition.h" | ||
|
@@ -27,6 +28,10 @@ namespace ephemeral_storage { | |
|
||
namespace { | ||
|
||
// TODO(bridiver) - share these constants with DOMWindowStorage | ||
constexpr char kSessionStorageSuffix[] = "/ephemeral-session-storage"; | ||
constexpr char kLocalStorageSuffix[] = "/ephemeral-local-storage"; | ||
|
||
// Session storage ids are expected to be 36 character long GUID strings. Since | ||
// we are constructing our own ids, we convert our string into a 32 character | ||
// hash and then use that make up our own GUID-like string. Because of the way | ||
|
@@ -90,9 +95,9 @@ void EphemeralStorageTabHelper::CreateEphemeralStorageAreasForDomainAndURL( | |
// namespace, this will just give us a new reference. When the last tab helper | ||
// drops the reference, the namespace should be deleted. | ||
std::string local_partition_id = | ||
StringToSessionStorageId(new_domain, "/ephemeral-local-storage"); | ||
local_storage_namespace_ = | ||
content::CreateSessionStorageNamespace(partition, local_partition_id); | ||
StringToSessionStorageId(new_domain, kLocalStorageSuffix); | ||
local_storage_namespace_ = content::CreateSessionStorageNamespace( | ||
partition, local_partition_id, base::nullopt); | ||
|
||
// Session storage is always per-tab and never per-TLD, so we always delete | ||
// and recreate the session storage when switching domains. | ||
|
@@ -104,9 +109,18 @@ void EphemeralStorageTabHelper::CreateEphemeralStorageAreasForDomainAndURL( | |
|
||
std::string session_partition_id = StringToSessionStorageId( | ||
content::GetSessionStorageNamespaceId(web_contents()), | ||
"/ephemeral-session-storage"); | ||
session_storage_namespace_ = | ||
content::CreateSessionStorageNamespace(partition, session_partition_id); | ||
kSessionStorageSuffix); | ||
|
||
auto* rfh = web_contents()->GetOpener(); | ||
session_storage_namespace_ = content::CreateSessionStorageNamespace( | ||
partition, session_partition_id, | ||
// clone the namespace if there is an opener | ||
// https://html.spec.whatwg.org/multipage/browsers.html#copy-session-storage | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this clone copy non-ephemeral session storage data into the ephemeral session storage? I'm pretty sure that's why I didn't do this in the past. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it shouldn't be, I'm only passing the id of the parent session storage and it passes all the tests on https://dev-pages.brave.software/storage/ephemeral-storage.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and since the opener will be suppressed if it's not same domain the owner window will always have ephemeral storage enabled, but it might be worth adding a check in case there's some edge case with subdomains There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like it should be ok
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would be nice to have a browser test |
||
rfh ? base::make_optional<std::string>(StringToSessionStorageId( | ||
content::GetSessionStorageNamespaceId( | ||
WebContents::FromRenderFrameHost(rfh)), | ||
kSessionStorageSuffix)) | ||
: base::nullopt); | ||
|
||
tld_ephemeral_lifetime_ = content::TLDEphemeralLifetime::GetOrCreate( | ||
browser_context, partition, new_domain); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
#include "components/content_settings/core/common/content_settings.h" | ||
#include "components/content_settings/core/common/content_settings_pattern.h" | ||
#include "components/content_settings/core/common/features.h" | ||
#include "net/base/features.h" | ||
#include "net/base/registry_controlled_domains/registry_controlled_domain.h" | ||
#include "url/gurl.h" | ||
#include "url/origin.h" | ||
|
@@ -143,8 +144,46 @@ bool BraveIsAllowedThirdParty( | |
return false; | ||
} | ||
|
||
// TODO(bridiver) make this a common method that can be shared with | ||
// BraveContentSettingsAgentImpl | ||
bool ShouldUseEphemeralStorage( | ||
const GURL& url, | ||
const GURL& site_for_cookies, | ||
const base::Optional<url::Origin>& top_frame_origin, | ||
const CookieSettingsBase* const cookie_settings) { | ||
if (!base::FeatureList::IsEnabled(net::features::kBraveEphemeralStorage)) | ||
return false; | ||
|
||
if (!top_frame_origin || url::Origin::Create(url) == top_frame_origin) | ||
return false; | ||
|
||
bool block_3p = !cookie_settings->IsCookieAccessAllowed(url, site_for_cookies, | ||
top_frame_origin); | ||
bool block_1p = !cookie_settings->IsCookieAccessAllowed( | ||
url, url, url::Origin::Create(url)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a clever way of doing this. Nice! |
||
|
||
// only use ephemeral storage for block 3p | ||
return block_3p && !block_1p; | ||
} | ||
|
||
} // namespace | ||
|
||
bool CookieSettingsBase::IsEphemeralCookieAccessAllowed( | ||
const GURL& url, | ||
const GURL& first_party_url) const { | ||
return IsEphemeralCookieAccessAllowed(url, first_party_url, base::nullopt); | ||
} | ||
|
||
bool CookieSettingsBase::IsEphemeralCookieAccessAllowed( | ||
const GURL& url, | ||
const GURL& site_for_cookies, | ||
const base::Optional<url::Origin>& top_frame_origin) const { | ||
if (ShouldUseEphemeralStorage(url, site_for_cookies, top_frame_origin, this)) | ||
return true; | ||
|
||
return IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin); | ||
} | ||
|
||
bool CookieSettingsBase::IsCookieAccessAllowed( | ||
const GURL& url, const GURL& first_party_url) const { | ||
return IsCookieAccessAllowed(url, first_party_url, base::nullopt); | ||
|
@@ -154,7 +193,6 @@ 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( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,15 @@ | |
#define BRAVE_CHROMIUM_SRC_COMPONENTS_CONTENT_SETTINGS_CORE_COMMON_COOKIE_SETTINGS_BASE_H_ | ||
|
||
#define BRAVE_COOKIE_SETTINGS_BASE_H \ | ||
private: \ | ||
bool IsEphemeralCookieAccessAllowed(const GURL& url, \ | ||
const GURL& first_party_url) const; \ | ||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you could eliminate this method by giving the three-argument version a default argument: bool IsEphemeralCookieAccessAllowed( \
const GURL& url, const GURL& site_for_cookies, \
const base::Optional<url::Origin>& top_frame_origin = base::nullopt) const; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to stay consistent with the original methods for clarity There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and also when the two argument version is removed that might cause us to miss something |
||
bool IsEphemeralCookieAccessAllowed( \ | ||
const GURL& url, const GURL& site_for_cookies, \ | ||
const base::Optional<url::Origin>& top_frame_origin) const; \ | ||
bool IsChromiumCookieAccessAllowed(const GURL& url, \ | ||
const GURL& first_party_url) const; \ | ||
bool IsChromiumCookieAccessAllowed( \ | ||
const GURL& url, \ | ||
const GURL& site_for_cookies, \ | ||
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" | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really a nit, but the style guide wants us to use proper punctuation, i.e. start sentenses with a capital and end with a dot.
https://google.github.io/styleguide/cppguide.html#Punctuation,_Spelling_and_Grammar