Commit 1754b352 authored by Caleb Raitto's avatar Caleb Raitto Committed by Commit Bot

Map SameSite=Extended DB values to unspecified.

Bug: 953995
Change-Id: I8c62dcb938c044195b5260bee49463135c38f850
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1884091
Commit-Queue: Caleb Raitto <caraitto@chromium.org>
Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarLily Chen <chlily@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710108}
parent d1333152
......@@ -172,8 +172,10 @@ namespace {
// Version 11 renames the "firstpartyonly" column to "samesite", and changes any
// stored values of kCookieSameSiteNoRestriction into
// kCookieSameSiteUnspecified to reflect the fact that those cookies were set
// without a SameSite attribute specified. A value of kCookieSameSiteExtended
// for "samesite" is now also supported.
// without a SameSite attribute specified. Support for a value of
// kCookieSameSiteExtended for "samesite" was added, however, that value is now
// deprecated and is mapped to CookieSameSite::UNSPECIFIED when loading from the
// database.
//
// Version 10 removes the uniqueness constraint on the creation time (which
// was not propagated up the stack and caused problems in
......@@ -508,9 +510,8 @@ CookieSameSite DBCookieSameSiteToCookieSameSite(DBCookieSameSite value) {
case kCookieSameSiteStrict:
samesite = CookieSameSite::STRICT_MODE;
break;
// SameSite=Extended is deprecated, so we map to UNSPECIFIED.
case kCookieSameSiteExtended:
samesite = CookieSameSite::EXTENDED_MODE;
break;
case kCookieSameSiteUnspecified:
samesite = CookieSameSite::UNSPECIFIED;
break;
......
......@@ -807,6 +807,47 @@ TEST_F(SQLitePersistentCookieStoreTest, SameSiteIsPersistent) {
EXPECT_EQ(CookieSameSite::STRICT_MODE, cookie_map[kStrictName]->SameSite());
}
TEST_F(SQLitePersistentCookieStoreTest, SameSiteExtendedTreatedAsUnspecified) {
constexpr char kDomain[] = "sessioncookie.com";
constexpr char kExtendedName[] = "extended";
constexpr char kCookieValue[] = "value";
constexpr char kCookiePath[] = "/";
InitializeStore(false, true);
// Add an extended-samesite persistent cookie by first adding a strict-same
// site cookie, then turning that into the legacy extended-samesite state with
// direct SQL DB access.
store_->AddCookie(CanonicalCookie(
kExtendedName, kCookieValue, kDomain, kCookiePath,
base::Time::Now() - base::TimeDelta::FromMinutes(1),
base::Time::Now() + base::TimeDelta::FromDays(1), base::Time(), false,
false, CookieSameSite::STRICT_MODE, COOKIE_PRIORITY_DEFAULT));
// Force the store to write its data to the disk.
DestroyStore();
// Open db
sql::Database connection;
ASSERT_TRUE(connection.Open(temp_dir_.GetPath().Append(kCookieFilename)));
std::string update_stmt(
"UPDATE cookies SET samesite=3" // 3 is Extended.
" WHERE samesite=2" // 2 is Strict.
);
ASSERT_TRUE(connection.Execute(update_stmt.c_str()));
connection.Close();
// Create a store that loads session cookie and test that the
// SameSite=Extended attribute values is ignored.
CanonicalCookieVector cookies;
CreateAndLoad(false, true, &cookies);
ASSERT_EQ(1U, cookies.size());
// Validate that the cookie has the correct SameSite.
EXPECT_EQ(kExtendedName, cookies[0]->Name());
EXPECT_EQ(CookieSameSite::UNSPECIFIED, cookies[0]->SameSite());
}
TEST_F(SQLitePersistentCookieStoreTest, UpdateToEncryption) {
CanonicalCookieVector cookies;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment