-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce PublicSuffixStore with cache
https://bugs.webkit.org/show_bug.cgi?id=271188 rdar://124971859 Reviewed by Per Arne Vollan and Chris Dumez. Intoduce a new class PublicSuffixStore and move existing public suffix related functions into it. PublicSuffixStore can have a cache for public suffix. When the cache is in use, PublicSuffixStore searches public suffix in it before invoking platform specific code (this may help us to tighten sandbox in some process later). Currently the cache is only enabled in web process on Cocoa platforms. Before this patch, web process has a cache for finding top privately controlled domain of a given host. UI process sends (host, domain) pair to web process on load time, and web process will add the entry in cache (256605@main). This patch makes UI process send the public suffix the to web process, and makes web process store it in the new public suffix cache, since the domain cache has a size limit, and it only benefits search for the given host. Also, this patch fixes the regression from 270762@main, that web process does not update the cache on receiving LoadParameters (since setTopPrivatelyControlledDomain is dropped from LoadParameters::decode), by adding addPublicSuffix to WebPage::platformDidReceiveLoadParameters. * Source/WebCore/Headers.cmake: * Source/WebCore/Sources.txt: * Source/WebCore/SourcesCocoa.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/dom/Document.cpp: (WebCore::Document::urlForBindings const): * Source/WebCore/loader/ResourceLoadStatistics.cpp: * Source/WebCore/loader/cache/MemoryCache.cpp: * Source/WebCore/page/Quirks.cpp: (WebCore::isYahooMail): (WebCore::Quirks::shouldHideSearchFieldResultsButton const): (WebCore::Quirks::isAmazon const): (WebCore::Quirks::isGoogleMaps const): * Source/WebCore/page/SecurityOrigin.cpp: (WebCore::SecurityOrigin::isSameSiteAs const): (WebCore::SecurityOrigin::isMatchingRegistrableDomainSuffix const): * Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp: (WebCore::ContentSecurityPolicySourceList::isValidSourceForExtensionMode): * Source/WebCore/platform/Curl.cmake: * Source/WebCore/platform/PublicSuffixStore.cpp: Added. (WebCore::PublicSuffixStore::singleton): (WebCore::PublicSuffixStore::clearHostTopPrivatelyControlledDomainCache): (WebCore::PublicSuffixStore::isPublicSuffix const): (WebCore::PublicSuffixStore::publicSuffix const): (WebCore::PublicSuffixStore::topPrivatelyControlledDomain const): * Source/WebCore/platform/PublicSuffixStore.h: Renamed from Source/WebCore/platform/PublicSuffix.h. * Source/WebCore/platform/RegistrableDomain.h: (WebCore::RegistrableDomain::uncheckedCreateFromHost): (WebCore::RegistrableDomain::registrableDomainFromHost): * Source/WebCore/platform/SourcesSoup.txt: * Source/WebCore/platform/cocoa/PublicSuffixCocoa.mm: Removed. * Source/WebCore/platform/cocoa/PublicSuffixStoreCocoa.mm: Added. (WebCore::isPublicSuffixCF): (WebCore::PublicSuffixStore::platformIsPublicSuffix const): (WebCore::PublicSuffixStore::platformTopPrivatelyControlledDomain const): (WebCore::PublicSuffixStore::enablePublicSuffixCache): (WebCore::PublicSuffixStore::addPublicSuffix): * Source/WebCore/platform/glib/UserAgentQuirks.cpp: (WebCore::UserAgentQuirks::quirksForURL): * Source/WebCore/platform/graphics/skia/PathSkia.cpp: * Source/WebCore/platform/network/NetworkStorageSession.cpp: * Source/WebCore/platform/network/ResourceRequestBase.cpp: (WebCore::ResourceRequestBase::partitionName): * Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp: * Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp: * Source/WebCore/platform/network/curl/CookieJarDB.cpp: (WebCore::CookieJarDB::hasCookies): (WebCore::CookieJarDB::canAcceptCookie): * Source/WebCore/platform/network/curl/PublicSuffixStoreCurl.cpp: Renamed from Source/WebCore/platform/network/curl/PublicSuffixCurl.cpp. (WebCore::PublicSuffixStore::platformIsPublicSuffix const): (WebCore::topPrivatelyControlledDomainInternal): (WebCore::PublicSuffixStore::platformTopPrivatelyControlledDomain const): * Source/WebCore/platform/soup/PublicSuffixStoreSoup.cpp: Renamed from Source/WebCore/platform/soup/PublicSuffixSoup.cpp. (WebCore::PublicSuffixStore::platformIsPublicSuffix const): (WebCore::permissiveTopPrivateDomain): (WebCore::PublicSuffixStore::platformTopPrivatelyControlledDomain const): * Source/WebKit/NetworkProcess/cocoa/NetworkProcessCocoa.mm: * Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp: (WebKit::NetworkDataTaskSoup::shouldAllowHSTSPolicySetting const): * Source/WebKit/Shared/GoToBackForwardItemParameters.h: * Source/WebKit/Shared/GoToBackForwardItemParameters.serialization.in: * Source/WebKit/Shared/LoadParameters.h: * Source/WebKit/Shared/LoadParameters.serialization.in: * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionMatchPatternCocoa.mm: (WebKit::WebExtensionMatchPattern::hostIsPublicSuffix const): * Source/WebKit/UIProcess/ProvisionalPageProxy.cpp: (WebKit::ProvisionalPageProxy::goToBackForwardItem): * Source/WebKit/UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::launchProcessForReload): (WebKit::WebPageProxy::loadRequestWithNavigationShared): (WebKit::WebPageProxy::loadFile): (WebKit::WebPageProxy::goToBackForwardItem): (WebKit::WebPageProxy::resetStateAfterProcessTermination): * Source/WebKit/UIProcess/WebProcessProxy.cpp: (WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch): (WebKit::WebProcessProxy::didExceedMemoryFootprintThreshold): * Source/WebKit/UIProcess/WebsiteData/WebsiteDataRecord.cpp: (WebKit::WebsiteDataRecord::displayNameForHostName): (WebKit::WebsiteDataRecord::displayNameForOrigin): (WebKit::WebsiteDataRecord::topPrivatelyControlledDomain): * Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm: (WebKit::WebPage::platformDidReceiveLoadParameters): * Source/WebKit/WebProcess/WebPage/WebPage.cpp: (WebKit::WebPage::goToBackForwardItem): * Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm: (WebKit::prewarmLogs): (WebKit::WebProcess::platformInitializeProcess): * Tools/TestWebKitAPI/Tests/WebCore/PublicSuffix.cpp: (TestWebKitAPI::TEST_F): Canonical link: https://commits.webkit.org/276505@main
- Loading branch information
Showing
41 changed files
with
436 additions
and
319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "PublicSuffixStore.h" | ||
|
||
#include <wtf/CrossThreadCopier.h> | ||
#include <wtf/NeverDestroyed.h> | ||
|
||
namespace WebCore { | ||
|
||
PublicSuffixStore& PublicSuffixStore::singleton() | ||
{ | ||
static LazyNeverDestroyed<PublicSuffixStore> store; | ||
static std::once_flag flag; | ||
std::call_once(flag, [&] { | ||
store.construct(); | ||
}); | ||
return store.get(); | ||
} | ||
|
||
void PublicSuffixStore::clearHostTopPrivatelyControlledDomainCache() | ||
{ | ||
Locker locker { m_HostTopPrivatelyControlledDomainCacheLock }; | ||
m_hostTopPrivatelyControlledDomainCache.clear(); | ||
} | ||
|
||
bool PublicSuffixStore::isPublicSuffix(StringView domain) const | ||
{ | ||
return platformIsPublicSuffix(domain); | ||
} | ||
|
||
String PublicSuffixStore::publicSuffix(const String& host) const | ||
{ | ||
// FIXME: if host is a URL, we could drop these checks. | ||
if (host.isEmpty() || !host.containsOnlyASCII()) | ||
return { }; | ||
|
||
const auto lowercaseHost = host.convertToASCIILowercase(); | ||
if (URL::hostIsIPAddress(lowercaseHost)) | ||
return { }; | ||
|
||
size_t separatorPosition; | ||
for (unsigned labelStart = 0; (separatorPosition = host.find('.', labelStart)) != notFound; labelStart = separatorPosition + 1) { | ||
auto candidate = lowercaseHost.substring(separatorPosition + 1); | ||
if (isPublicSuffix(candidate)) | ||
return candidate; | ||
} | ||
|
||
return { }; | ||
} | ||
|
||
String PublicSuffixStore::topPrivatelyControlledDomain(const String& host) const | ||
{ | ||
// FIXME: if host is a URL, we could drop these checks. | ||
if (host.isEmpty()) | ||
return { }; | ||
|
||
if (!host.containsOnlyASCII()) | ||
return host; | ||
|
||
Locker locker { m_HostTopPrivatelyControlledDomainCacheLock }; | ||
auto hostCopy = crossThreadCopy(host); | ||
auto& result = m_hostTopPrivatelyControlledDomainCache.ensure(hostCopy, [&] { | ||
const auto lowercaseHost = hostCopy.convertToASCIILowercase(); | ||
if (lowercaseHost == "localhost"_s || URL::hostIsIPAddress(lowercaseHost)) | ||
return lowercaseHost; | ||
|
||
return platformTopPrivatelyControlledDomain(lowercaseHost); | ||
}).iterator->value; | ||
|
||
constexpr auto maxHostTopPrivatelyControlledDomainCache = 128; | ||
if (m_hostTopPrivatelyControlledDomainCache.size() > maxHostTopPrivatelyControlledDomainCache) | ||
m_hostTopPrivatelyControlledDomainCache.remove(m_hostTopPrivatelyControlledDomainCache.random()); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
return result.isolatedCopy(); | ||
} | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This invalidates
auto& result
above I think, which is bad considering we're usingresult
later on.