From 2e1c4875639ab11f81989660eaaae007b1abca2b Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sun, 22 Dec 2024 20:27:41 +0100 Subject: [PATCH] Issue #2670 - Compute baseDomain when cookies are read from the database baseDomain is used as a key for cookies in a hashmap. For cookie operations to work properly, the baseDomain generation must be reliable. This is, however, not the case, because the result can change by updates to the public suffix list (PSL). Since the stored baseDomain is not reliable, the value must be recomputed when the database is read. This causes a minor performance hit but is needed if we want to keep abreast of PSL changes without clobbering the cookies database. Resolves #2670 --- netwerk/cookie/nsCookieService.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/netwerk/cookie/nsCookieService.cpp b/netwerk/cookie/nsCookieService.cpp index 4f6476bba8..516261fa22 100644 --- a/netwerk/cookie/nsCookieService.cpp +++ b/netwerk/cookie/nsCookieService.cpp @@ -2607,8 +2607,16 @@ nsCookieService::Read() if (!hasResult) break; - // Make sure we haven't already read the data. - stmt->GetUTF8String(IDX_BASE_DOMAIN, baseDomain); + // IDX_BASE_DOMAIN cannot be used, because updates to the public suffix list + // may invalidate the value of the stored baseDomain. + stmt->GetUTF8String(IDX_HOST, host); + + rv = GetBaseDomainFromHost(host, baseDomain); + if (NS_FAILED(rv)) { + COOKIE_LOGSTRING(LogLevel::Debug, + ("Read(): Ignoring invalid host '%s'", host.get())); + continue; + } nsAutoCString suffix; NeckoOriginAttributes attrs;