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
This commit is contained in:
Moonchild 2024-12-22 20:27:41 +01:00 committed by roytam1
commit 2e1c487563

View file

@ -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;