Commit 06b5f213 authored by Dylan Cutler's avatar Dylan Cutler Committed by Commit Bot

Use CanonicalCookie::FromStorage in cookie_fetcher_util.cc.

Using this factory method instead of CreateSanitizedCookie better
expresses the intent of this code: to deserialize cookies that were
already added to the cookie store.

This mitigates a bug in the current code where cookies with a __Host-
prefix would fail the check below. I believe this is what causes the
crashes that causd us to change a DCHECK to an early return in
http://crrev.com/c/2335554.

Also since CanonicalCookie::FromStorage will DCHECK IsCanonical(), we do
not need to check the CanonicalCookie's validity in this file.

Bug: 1102874
Change-Id: I0759ecc155d9be84b0bae13064d8218702d4c8d4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2456630
Commit-Queue: Dylan Cutler <dylancutler@google.com>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#815139}
parent 2133e7d7
...@@ -95,12 +95,12 @@ static void JNI_CookiesFetcher_RestoreCookies( ...@@ -95,12 +95,12 @@ static void JNI_CookiesFetcher_RestoreCookies(
std::string domain_str(base::android::ConvertJavaStringToUTF8(env, domain)); std::string domain_str(base::android::ConvertJavaStringToUTF8(env, domain));
std::string path_str(base::android::ConvertJavaStringToUTF8(env, path)); std::string path_str(base::android::ConvertJavaStringToUTF8(env, path));
GURL url = net::cookie_util::CookieDomainAndPathToURL(
domain_str, path_str, // This factory method will DCHECK IsCanonical() to check if the cookie is
static_cast<net::CookieSourceScheme>(source_scheme)); // valid.
std::unique_ptr<net::CanonicalCookie> cookie = std::unique_ptr<net::CanonicalCookie> cookie =
net::CanonicalCookie::CreateSanitizedCookie( net::CanonicalCookie::FromStorage(
url, base::android::ConvertJavaStringToUTF8(env, name), base::android::ConvertJavaStringToUTF8(env, name),
base::android::ConvertJavaStringToUTF8(env, value), domain_str, base::android::ConvertJavaStringToUTF8(env, value), domain_str,
path_str, path_str,
base::Time::FromDeltaSinceWindowsEpoch( base::Time::FromDeltaSinceWindowsEpoch(
...@@ -110,13 +110,8 @@ static void JNI_CookiesFetcher_RestoreCookies( ...@@ -110,13 +110,8 @@ static void JNI_CookiesFetcher_RestoreCookies(
base::Time::FromDeltaSinceWindowsEpoch( base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds(last_access)), base::TimeDelta::FromMicroseconds(last_access)),
secure, httponly, static_cast<net::CookieSameSite>(same_site), secure, httponly, static_cast<net::CookieSameSite>(same_site),
static_cast<net::CookiePriority>(priority)); static_cast<net::CookiePriority>(priority),
static_cast<net::CookieSourceScheme>(source_scheme));
// These cookies were in the cookie store already so they should be valid.
// TODO(dylancutler) This early return should be removed when the condition is
// no longer met.
if (!cookie)
return;
// Assume HTTPS - since the cookies are being restored from another store, // Assume HTTPS - since the cookies are being restored from another store,
// they have already gone through the strict secure check. // they have already gone through the strict secure check.
...@@ -128,6 +123,9 @@ static void JNI_CookiesFetcher_RestoreCookies( ...@@ -128,6 +123,9 @@ static void JNI_CookiesFetcher_RestoreCookies(
net::CookieOptions::SameSiteCookieContext::MakeInclusive()); net::CookieOptions::SameSiteCookieContext::MakeInclusive());
options.set_do_not_update_access_time(); options.set_do_not_update_access_time();
GetCookieServiceClient()->SetCanonicalCookie( GetCookieServiceClient()->SetCanonicalCookie(
*cookie, url, options, *cookie,
network::mojom::CookieManager::SetCanonicalCookieCallback()); net::cookie_util::CookieDomainAndPathToURL(
domain_str, path_str,
static_cast<net::CookieSourceScheme>(source_scheme)),
options, network::mojom::CookieManager::SetCanonicalCookieCallback());
} }
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