Determine "always allowed" cookies non-third-party
The `is_third_party_request` metadata is only used externally in the CookieSettings to determine whether a 3PC related cookie access should result in an issue in DevTools. Bug: 371586244 Change-Id: If2a3135b3e8800e3d4e89ce61a37adb0ec51ed02 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5920217 Reviewed-by: Dylan Cutler <dylancutler@google.com> Commit-Queue: Shuran Huang <shuuran@chromium.org> Cr-Commit-Position: refs/heads/main@{#1373466}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4996dea0fc
commit
bb246fedf7
components/content_settings/core/common
services/network
@ -619,9 +619,6 @@ CookieSettingsBase::GetCookieSettingInternal(
|
||||
url = websocket_mapped_url;
|
||||
}
|
||||
|
||||
const bool is_third_party_request =
|
||||
IsThirdPartyRequest(url, site_for_cookies);
|
||||
|
||||
// Auto-allow in extensions or for WebUI embedding a secure origin.
|
||||
if (ShouldAlwaysAllowCookies(url, first_party_url)) {
|
||||
if (info) {
|
||||
@ -632,9 +629,12 @@ CookieSettingsBase::GetCookieSettingInternal(
|
||||
/*is_explicit_setting=*/false,
|
||||
/*third_party_cookie_allow_mechanism=*/
|
||||
ThirdPartyCookieAllowMechanism::kNone,
|
||||
is_third_party_request};
|
||||
/*is_third_party_request=*/false};
|
||||
}
|
||||
|
||||
const bool is_third_party_request =
|
||||
IsThirdPartyRequest(url, site_for_cookies);
|
||||
|
||||
SettingInfo setting_info;
|
||||
ContentSetting cookie_setting = GetContentSetting(
|
||||
url, first_party_url, ContentSettingsType::COOKIES, &setting_info);
|
||||
|
@ -461,4 +461,10 @@ bool CookieSettings::IsStorageAccessHeadersEnabled(
|
||||
/*info=*/nullptr) == CONTENT_SETTING_ALLOW;
|
||||
}
|
||||
|
||||
bool CookieSettings::ShouldAlwaysAllowCookiesForTesting(
|
||||
const GURL& url,
|
||||
const GURL& first_party_url) const {
|
||||
return ShouldAlwaysAllowCookies(url, first_party_url);
|
||||
}
|
||||
|
||||
} // namespace network
|
||||
|
@ -163,6 +163,9 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) CookieSettings
|
||||
const GURL& url,
|
||||
base::optional_ref<const url::Origin> top_frame_origin) const;
|
||||
|
||||
bool ShouldAlwaysAllowCookiesForTesting(const GURL& url,
|
||||
const GURL& first_party_url) const;
|
||||
|
||||
private:
|
||||
// content_settings::CookieSettingsBase:
|
||||
bool ShouldAlwaysAllowCookies(const GURL& url,
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "testing/gmock/include/gmock/gmock.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "url/origin.h"
|
||||
#include "url/url_util.h"
|
||||
|
||||
namespace network {
|
||||
namespace {
|
||||
@ -48,6 +49,7 @@ constexpr char kAllowedRequestsHistogram[] =
|
||||
|
||||
constexpr char kDomainURL[] = "http://example.com";
|
||||
constexpr char kURL[] = "http://foo.com";
|
||||
constexpr char kSecureSchemedURL[] = "https://foo.com";
|
||||
constexpr char kOtherURL[] = "http://other.com";
|
||||
constexpr char kSubDomainURL[] = "http://www.corp.example.com";
|
||||
constexpr char kDomain[] = "example.com";
|
||||
@ -58,6 +60,8 @@ constexpr char kDomainWildcardPattern[] = "[*.]example.com";
|
||||
constexpr char kRwsOwnerURL[] = "https://rws-owner.test";
|
||||
constexpr char kRwsMemberURL[] = "https://rws-member.test";
|
||||
constexpr char kUnrelatedURL[] = "http://unrelated.com";
|
||||
constexpr char kChromeScheme[] = "chrome";
|
||||
constexpr char kChromeSchemedURL[] = "chrome://new-tab-page/";
|
||||
|
||||
std::unique_ptr<net::CanonicalCookie> MakeCanonicalCookie(
|
||||
const std::string& name,
|
||||
@ -468,6 +472,42 @@ TEST_F(CookieSettingsTest, GetCookieSettingBlockThirdParty) {
|
||||
CONTENT_SETTING_BLOCK);
|
||||
}
|
||||
|
||||
TEST_F(CookieSettingsTest, ShouldAlwaysAllowCookies) {
|
||||
CookieSettings settings;
|
||||
settings.set_secure_origin_cookies_allowed_schemes({kChromeScheme});
|
||||
settings.set_block_third_party_cookies(false);
|
||||
ASSERT_FALSE(settings.ShouldAlwaysAllowCookiesForTesting(
|
||||
GURL(kURL), GURL(kChromeSchemedURL)));
|
||||
ASSERT_TRUE(settings.ShouldAlwaysAllowCookiesForTesting(
|
||||
GURL(kSecureSchemedURL), GURL(kChromeSchemedURL)));
|
||||
|
||||
settings.set_block_third_party_cookies(true);
|
||||
EXPECT_FALSE(settings.ShouldAlwaysAllowCookiesForTesting(
|
||||
GURL(kURL), GURL(kChromeSchemedURL)));
|
||||
EXPECT_TRUE(settings.ShouldAlwaysAllowCookiesForTesting(
|
||||
GURL(kSecureSchemedURL), GURL(kChromeSchemedURL)));
|
||||
}
|
||||
|
||||
TEST_F(CookieSettingsTest, IsCookieAccessible_AlwaysAllowCookieNotAffected) {
|
||||
url::ScopedSchemeRegistryForTests scoped_registry;
|
||||
url::AddStandardScheme(kChromeScheme, url::SCHEME_WITH_HOST);
|
||||
|
||||
CookieSettings settings;
|
||||
settings.set_block_third_party_cookies(false);
|
||||
settings.set_secure_origin_cookies_allowed_schemes({kChromeScheme});
|
||||
net::CookieInclusionStatus status;
|
||||
|
||||
std::unique_ptr<net::CanonicalCookie> cookie =
|
||||
MakeCanonicalSameSiteNoneCookie("name", kSecureSchemedURL);
|
||||
|
||||
EXPECT_TRUE(settings.IsCookieAccessible(
|
||||
*cookie, GURL(kSecureSchemedURL), net::SiteForCookies(),
|
||||
url::Origin::Create(GURL(kChromeSchemedURL)),
|
||||
net::FirstPartySetMetadata(), net::CookieSettingOverrides(), &status));
|
||||
EXPECT_FALSE(status.HasWarningReason(
|
||||
net::CookieInclusionStatus::WARN_THIRD_PARTY_PHASEOUT));
|
||||
}
|
||||
|
||||
TEST_P(CookieSettingsTestP,
|
||||
GetCookieSettingOverridePreservesSessionOnlySetting) {
|
||||
CookieSettings settings;
|
||||
|
Reference in New Issue
Block a user