Diff
Modified: trunk/Source/WebCore/ChangeLog (292676 => 292677)
--- trunk/Source/WebCore/ChangeLog 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/ChangeLog 2022-04-09 08:28:32 UTC (rev 292677)
@@ -1,3 +1,84 @@
+2022-04-09 Sihui Liu <[email protected]>
+
+ Move canAccessStorage() check from SecurityOrigin to ScriptExecutionContext
+ https://bugs.webkit.org/show_bug.cgi?id=238524
+ <rdar://problem/91318259>
+
+ Reviewed by Chris Dumez.
+
+ Add canAccessResource() to ScriptExecutionContext because ScriptExecutionContext, instead of SecurityOrigin,
+ should be the place that holds StorageBlockingPolicy (otherwise it's confusing that the origin and top origin
+ disagrees with each other on policy). Also, because ScriptExecutionContext has access to origin and topOrigin,
+ callers don't need to explicitly get them before the access check.
+
+ * Modules/encryptedmedia/CDM.cpp:
+ (WebCore::CDM::getSupportedConfiguration):
+ * Modules/geolocation/Geolocation.cpp:
+ (WebCore::Geolocation::shouldBlockGeolocationRequests):
+ * Modules/indexeddb/IDBFactory.cpp:
+ (WebCore::shouldThrowSecurityException):
+ (WebCore::IDBFactory::openInternal):
+ (WebCore::IDBFactory::deleteDatabase):
+ * Modules/storage/StorageManager.cpp:
+ (WebCore::connectionInfo):
+ * Modules/webdatabase/DOMWindowWebDatabase.cpp:
+ (WebCore::DOMWindowWebDatabase::openDatabase):
+ * dom/Document.cpp:
+ (WebCore::m_whitespaceCache):
+ (WebCore::Document::cookie):
+ (WebCore::Document::setCookie):
+ (WebCore::Document::storageBlockingStateDidChange):
+ (WebCore::Document::initSecurityContext):
+ (WebCore::Document::applyQuickLookSandbox):
+ * dom/ScriptExecutionContext.cpp:
+ (WebCore::ScriptExecutionContext::domainForCachePartition const):
+ (WebCore::isOriginEquivalentToLocal):
+ (WebCore::ScriptExecutionContext::canAccessResource const):
+ * dom/ScriptExecutionContext.h:
+ (WebCore::ScriptExecutionContext::setStorageBlockingPolicy):
+ * loader/DocumentLoader.cpp:
+ (WebCore::DocumentLoader::loadMainResource):
+ * loader/appcache/ApplicationCacheGroup.cpp:
+ (WebCore::ApplicationCacheGroup::selectCache):
+ (WebCore::ApplicationCacheGroup::selectCacheWithoutManifestURL):
+ (WebCore::ApplicationCacheGroup::update):
+ * loader/appcache/ApplicationCacheHost.cpp:
+ (WebCore::ApplicationCacheHost::isApplicationCacheBlockedForRequest):
+ * page/DOMWindow.cpp:
+ * page/Page.cpp:
+ (WebCore::Page::setupForRemoteWorker):
+ * page/SecurityOrigin.cpp:
+ (WebCore::SecurityOrigin::domainForCachePartition const):
+ (WebCore::SecurityOrigin::canAccessStorage const): Deleted.
+ * page/SecurityOrigin.h:
+ (WebCore::SecurityOrigin::encode const):
+ (WebCore::SecurityOrigin::decode):
+ (WebCore::SecurityOrigin::setStorageBlockingPolicy): Deleted.
+ (WebCore::SecurityOrigin::canAccessDatabase const): Deleted.
+ (WebCore::SecurityOrigin::canAccessSessionStorage const): Deleted.
+ (WebCore::SecurityOrigin::canAccessLocalStorage const): Deleted.
+ (WebCore::SecurityOrigin::canAccessStorageManager const): Deleted.
+ (WebCore::SecurityOrigin::canAccessPluginStorage const): Deleted.
+ (WebCore::SecurityOrigin::canAccessApplicationCache const): Deleted.
+ (WebCore::SecurityOrigin::canAccessCookies const): Deleted.
+ (WebCore::SecurityOrigin::canRequestGeolocation const): Deleted.
+ * storage/StorageNamespaceProvider.cpp:
+ (WebCore::StorageNamespaceProvider::localStorageArea):
+ * workers/WorkerGlobalScope.cpp:
+ (WebCore::m_credentials):
+ * workers/service/ServiceWorkerContainer.cpp:
+ (WebCore::ServiceWorkerContainer::addRegistration):
+ (WebCore::ServiceWorkerContainer::updateRegistration):
+ * workers/service/ServiceWorkerJobData.cpp:
+ (WebCore::ServiceWorkerJobData::isolatedCopy const):
+ * workers/service/ServiceWorkerJobData.h:
+ (WebCore::ServiceWorkerJobData::encode const):
+ (WebCore::ServiceWorkerJobData::decode):
+ * workers/service/server/SWServer.cpp:
+ (WebCore::SWServer::startScriptFetch):
+ * worklets/WorkletGlobalScope.cpp:
+ (WebCore::WorkletGlobalScope::WorkletGlobalScope):
+
2022-04-08 Kate Cheney <[email protected]>
Sharing services picker menu Mail presents in the wrong place when compose web view is scrolled
Modified: trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp (292676 => 292677)
--- trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/Modules/encryptedmedia/CDM.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -96,11 +96,10 @@
return;
}
+ auto access = CDMPrivate::LocalStorageAccess::Allowed;
bool isEphemeral = !document->page() || document->page()->sessionID().isEphemeral();
-
- SecurityOrigin& origin = document->securityOrigin();
- SecurityOrigin& topOrigin = document->topOrigin();
- CDMPrivate::LocalStorageAccess access = !isEphemeral && origin.canAccessLocalStorage(&topOrigin) ? CDMPrivate::LocalStorageAccess::Allowed : CDMPrivate::LocalStorageAccess::NotAllowed;
+ if (isEphemeral || document->canAccessResource(ScriptExecutionContext::ResourceType::LocalStorage) == ScriptExecutionContext::HasResourceAccess::No)
+ access = CDMPrivate::LocalStorageAccess::NotAllowed;
m_private->getSupportedConfiguration(WTFMove(candidateConfiguration), access, WTFMove(callback));
}
Modified: trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp (292676 => 292677)
--- trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -371,7 +371,7 @@
bool isSecure = SecurityOrigin::isSecure(document()->url()) || document()->isSecureContext();
bool hasMixedContent = !document()->foundMixedContent().isEmpty();
bool isLocalOrigin = securityOrigin()->isLocal();
- if (securityOrigin()->canRequestGeolocation()) {
+ if (document()->canAccessResource(ScriptExecutionContext::ResourceType::Geolocation) != ScriptExecutionContext::HasResourceAccess::No) {
if (isLocalOrigin || (isSecure && !hasMixedContent) || isRequestFromIBooks())
return false;
}
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp (292676 => 292677)
--- trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -54,10 +54,7 @@
return true;
}
- if (!context.securityOrigin()->canAccessDatabase(nullptr))
- return true;
-
- return false;
+ return context.canAccessResource(ScriptExecutionContext::ResourceType::IndexedDB) == ScriptExecutionContext::HasResourceAccess::No;
}
Ref<IDBFactory> IDBFactory::create(IDBClient::IDBConnectionProxy& connectionProxy)
@@ -91,7 +88,7 @@
return Exception { SecurityError, "IDBFactory.open() called in an invalid security context"_s };
ASSERT(context.securityOrigin());
- bool isTransient = !context.securityOrigin()->canAccessDatabase(&context.topOrigin());
+ bool isTransient = (context.canAccessResource(ScriptExecutionContext::ResourceType::IndexedDB) == ScriptExecutionContext::HasResourceAccess::DefaultForThirdParty);
IDBDatabaseIdentifier databaseIdentifier(name, SecurityOriginData { context.securityOrigin()->data() }, SecurityOriginData { context.topOrigin().data() }, isTransient);
if (!databaseIdentifier.isValid())
return Exception { TypeError, "IDBFactory.open() called with an invalid security origin"_s };
@@ -112,7 +109,7 @@
return Exception { SecurityError, "IDBFactory.deleteDatabase() called in an invalid security context"_s };
ASSERT(context.securityOrigin());
- bool isTransient = !context.securityOrigin()->canAccessDatabase(&context.topOrigin());
+ bool isTransient = (context.canAccessResource(ScriptExecutionContext::ResourceType::IndexedDB) == ScriptExecutionContext::HasResourceAccess::DefaultForThirdParty);
IDBDatabaseIdentifier databaseIdentifier(name, SecurityOriginData { context.securityOrigin()->data() }, SecurityOriginData { context.topOrigin().data() }, isTransient);
if (!databaseIdentifier.isValid())
return Exception { TypeError, "IDBFactory.deleteDatabase() called with an invalid security origin"_s };
Modified: trunk/Source/WebCore/Modules/storage/StorageManager.cpp (292676 => 292677)
--- trunk/Source/WebCore/Modules/storage/StorageManager.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/Modules/storage/StorageManager.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -67,13 +67,12 @@
if (!context)
return Exception { InvalidStateError, "Context is invalid"_s };
+ if (context->canAccessResource(ScriptExecutionContext::ResourceType::StorageManager) == ScriptExecutionContext::HasResourceAccess::No)
+ return Exception { TypeError, "Context not access storage"_s };
+
auto* origin = context->securityOrigin();
- if (!origin)
- return Exception { InvalidStateError, "Origin is invalid"_s };
+ ASSERT(origin);
- if (!origin->canAccessStorageManager())
- return Exception { TypeError, "Origin should not access storage"_s };
-
if (is<Document>(context)) {
if (auto* connection = downcast<Document>(context)->storageConnection())
return ConnectionInfo { *connection, { context->topOrigin().data(), origin->data() } };
Modified: trunk/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp (292676 => 292677)
--- trunk/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/Modules/webdatabase/DOMWindowWebDatabase.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -47,9 +47,9 @@
return Exception { SecurityError };
document->addConsoleMessage(MessageSource::Storage, MessageLevel::Warning, "Web SQL is deprecated. Please use IndexedDB instead."_s);
- auto& securityOrigin = document->securityOrigin();
- if (!securityOrigin.canAccessDatabase(&document->topOrigin()))
+ if (document->canAccessResource(ScriptExecutionContext::ResourceType::WebSQL) != ScriptExecutionContext::HasResourceAccess::Yes)
return Exception { SecurityError };
+
auto result = manager.openDatabase(*window.document(), name, version, displayName, estimatedSize, WTFMove(creationCallback));
if (result.hasException()) {
// FIXME: To preserve our past behavior, this discards the error string in the exception.
Modified: trunk/Source/WebCore/dom/Document.cpp (292676 => 292677)
--- trunk/Source/WebCore/dom/Document.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/dom/Document.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -632,6 +632,7 @@
nodeListAndCollectionCount = 0;
InspectorInstrumentation::addEventListenersToNode(*this);
+ setStorageBlockingPolicy(m_settings->storageBlockingPolicy());
}
void Document::createNewIdentifier()
@@ -5340,7 +5341,7 @@
if (isCookieAverse())
return String();
- if (!securityOrigin().canAccessCookies())
+ if (canAccessResource(ScriptExecutionContext::ResourceType::Cookies) == ScriptExecutionContext::HasResourceAccess::No)
return Exception { SecurityError };
URL cookieURL = this->cookieURL();
@@ -5361,7 +5362,7 @@
if (isCookieAverse())
return { };
- if (!securityOrigin().canAccessCookies())
+ if (canAccessResource(ScriptExecutionContext::ResourceType::Cookies) == ScriptExecutionContext::HasResourceAccess::No)
return Exception { SecurityError };
URL cookieURL = this->cookieURL();
@@ -5791,7 +5792,7 @@
void Document::storageBlockingStateDidChange()
{
- securityOrigin().setStorageBlockingPolicy(settings().storageBlockingPolicy());
+ setStorageBlockingPolicy(settings().storageBlockingPolicy());
}
// Used only by WebKitLegacy.
@@ -6347,7 +6348,6 @@
securityOrigin().setEnforcesFilePathSeparation();
}
}
- securityOrigin().setStorageBlockingPolicy(settings().storageBlockingPolicy());
RefPtr parentDocument = ownerElement() ? &ownerElement()->document() : nullptr;
if (parentDocument && m_frame->loader().shouldTreatURLAsSrcdocDocument(url())) {
@@ -7888,8 +7888,8 @@
ASSERT(!documentURL.protocolIs(QLPreviewProtocol));
ASSERT(responseURL.protocolIs(QLPreviewProtocol));
+ setStorageBlockingPolicy(StorageBlockingPolicy::BlockAll);
auto securityOrigin = SecurityOrigin::createNonLocalWithAllowedFilePath(responseURL, documentURL.fileSystemPath());
- securityOrigin->setStorageBlockingPolicy(StorageBlockingPolicy::BlockAll);
setSecurityOriginPolicy(SecurityOriginPolicy::create(WTFMove(securityOrigin)));
static NeverDestroyed<String> quickLookCSP = makeString("default-src ", QLPreviewProtocol, ": 'unsafe-inline'; base-uri 'none'; sandbox allow-same-origin allow-scripts");
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.cpp (292676 => 292677)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -578,7 +578,13 @@
String ScriptExecutionContext::domainForCachePartition() const
{
- return m_domainForCachePartition.isNull() ? topOrigin().domainForCachePartition() : m_domainForCachePartition;
+ if (!m_domainForCachePartition.isNull())
+ return m_domainForCachePartition;
+
+ if (m_storageBlockingPolicy != StorageBlockingPolicy::BlockThirdParty)
+ return emptyString();
+
+ return topOrigin().domainForCachePartition();
}
bool ScriptExecutionContext::allowsMediaDevices() const
@@ -709,4 +715,37 @@
callback(*document);
}
+static bool isOriginEquivalentToLocal(const SecurityOrigin& origin)
+{
+ return origin.isLocal() && !origin.needsStorageAccessFromFileURLsQuirk() && !origin.hasUniversalAccess();
+}
+
+ScriptExecutionContext::HasResourceAccess ScriptExecutionContext::canAccessResource(ResourceType type) const
+{
+ auto* origin = securityOrigin();
+ if (!origin || origin->isUnique())
+ return HasResourceAccess::No;
+
+ switch (type) {
+ case ResourceType::Cookies:
+ case ResourceType::Geolocation:
+ return HasResourceAccess::Yes;
+ case ResourceType::ApplicationCache:
+ case ResourceType::Plugin:
+ case ResourceType::WebSQL:
+ case ResourceType::IndexedDB:
+ case ResourceType::LocalStorage:
+ case ResourceType::StorageManager:
+ if (isOriginEquivalentToLocal(*origin))
+ return HasResourceAccess::No;
+ FALLTHROUGH;
+ case ResourceType::SessionStorage:
+ if (m_storageBlockingPolicy == StorageBlockingPolicy::BlockAll)
+ return HasResourceAccess::No;
+ if ((m_storageBlockingPolicy == StorageBlockingPolicy::BlockThirdParty) && !topOrigin().isSameOriginAs(*origin) && !origin->hasUniversalAccess())
+ return HasResourceAccess::DefaultForThirdParty;
+ return HasResourceAccess::Yes;
+ }
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (292676 => 292677)
--- trunk/Source/WebCore/dom/ScriptExecutionContext.h 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h 2022-04-09 08:28:32 UTC (rev 292677)
@@ -34,6 +34,7 @@
#include "SecurityContext.h"
#include "ServiceWorkerIdentifier.h"
#include "Settings.h"
+#include "StorageBlockingPolicy.h"
#include <_javascript_Core/ConsoleTypes.h>
#include <_javascript_Core/HandleTypes.h>
#include <pal/SessionID.h>
@@ -297,6 +298,21 @@
bool hasLoggedAuthenticatedEncryptionWarning() const { return m_hasLoggedAuthenticatedEncryptionWarning; }
void setHasLoggedAuthenticatedEncryptionWarning(bool value) { m_hasLoggedAuthenticatedEncryptionWarning = value; }
+ void setStorageBlockingPolicy(StorageBlockingPolicy policy) { m_storageBlockingPolicy = policy; }
+ enum class ResourceType : uint8_t {
+ ApplicationCache,
+ Cookies,
+ Geolocation,
+ IndexedDB,
+ LocalStorage,
+ Plugin,
+ SessionStorage,
+ StorageManager,
+ WebSQL
+ };
+ enum class HasResourceAccess : uint8_t { No, Yes, DefaultForThirdParty };
+ WEBCORE_EXPORT HasResourceAccess canAccessResource(ResourceType) const;
+
protected:
class AddConsoleMessageTask : public Task {
public:
@@ -378,6 +394,7 @@
mutable ScriptExecutionContextIdentifier m_identifier;
bool m_hasLoggedAuthenticatedEncryptionWarning { false };
+ StorageBlockingPolicy m_storageBlockingPolicy { StorageBlockingPolicy::AllowAll };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (292676 => 292677)
--- trunk/Source/WebCore/loader/DocumentLoader.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -2148,9 +2148,12 @@
// If we are loading the main resource of a subframe, use the cache partition of the main document.
mainResourceRequest.setDomainForCachePartition(*m_frame->document());
} else {
- auto origin = SecurityOrigin::create(mainResourceRequest.resourceRequest().url());
- origin->setStorageBlockingPolicy(frameLoader()->frame().settings().storageBlockingPolicy());
- mainResourceRequest.setDomainForCachePartition(origin->domainForCachePartition());
+ if (frameLoader()->frame().settings().storageBlockingPolicy() != StorageBlockingPolicy::BlockThirdParty)
+ mainResourceRequest.setDomainForCachePartition(emptyString());
+ else {
+ auto origin = SecurityOrigin::create(mainResourceRequest.resourceRequest().url());
+ mainResourceRequest.setDomainForCachePartition(origin->domainForCachePartition());
+ }
}
m_mainResource = m_cachedResourceLoader->requestMainResource(WTFMove(mainResourceRequest)).value_or(nullptr);
Modified: trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp (292676 => 292677)
--- trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/loader/appcache/ApplicationCacheGroup.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -138,7 +138,7 @@
}
// Don't access anything on disk if private browsing is enabled.
- if (frame.page()->usesEphemeralSession() || !frame.document()->securityOrigin().canAccessApplicationCache(frame.tree().top().document()->securityOrigin())) {
+ if (frame.page()->usesEphemeralSession() || frame.document()->canAccessResource(ScriptExecutionContext::ResourceType::ApplicationCache) != ScriptExecutionContext::HasResourceAccess::Yes) {
postListenerTask(eventNames().checkingEvent, documentLoader);
postListenerTask(eventNames().errorEvent, documentLoader);
return;
@@ -212,7 +212,7 @@
ASSERT(!documentLoader.applicationCacheHost().applicationCache());
// Don't access anything on disk if private browsing is enabled.
- if (frame.page()->usesEphemeralSession() || !frame.document()->securityOrigin().canAccessApplicationCache(frame.tree().top().document()->securityOrigin())) {
+ if (frame.page()->usesEphemeralSession() || frame.document()->canAccessResource(ScriptExecutionContext::ResourceType::ApplicationCache) != ScriptExecutionContext::HasResourceAccess::Yes) {
postListenerTask(eventNames().checkingEvent, documentLoader);
postListenerTask(eventNames().errorEvent, documentLoader);
return;
@@ -407,7 +407,7 @@
}
// Don't access anything on disk if private browsing is enabled.
- if (frame.page()->usesEphemeralSession() || !frame.document()->securityOrigin().canAccessApplicationCache(frame.tree().top().document()->securityOrigin())) {
+ if (frame.page()->usesEphemeralSession() || frame.document()->canAccessResource(ScriptExecutionContext::ResourceType::ApplicationCache) != ScriptExecutionContext::HasResourceAccess::Yes) {
ASSERT(m_pendingMasterResourceLoaders.isEmpty());
ASSERT(m_pendingEntries.isEmpty());
ASSERT(!m_cacheBeingUpdated);
Modified: trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.cpp (292676 => 292677)
--- trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -561,7 +561,7 @@
return m_documentLoader.frame() && m_documentLoader.frame()->settings().offlineWebApplicationCacheEnabled() && !m_documentLoader.frame()->page()->usesEphemeralSession();
}
-bool ApplicationCacheHost::isApplicationCacheBlockedForRequest(const ResourceRequest& request)
+bool ApplicationCacheHost::isApplicationCacheBlockedForRequest(const ResourceRequest&)
{
auto* frame = m_documentLoader.frame();
if (!frame)
@@ -568,7 +568,7 @@
return false;
if (frame->isMainFrame())
return false;
- return !SecurityOrigin::create(request.url())->canAccessApplicationCache(frame->document()->topOrigin());
+ return frame->document()->canAccessResource(ScriptExecutionContext::ResourceType::ApplicationCache) != ScriptExecutionContext::HasResourceAccess::Yes;
}
} // namespace WebCore
Modified: trunk/Source/WebCore/page/DOMWindow.cpp (292676 => 292677)
--- trunk/Source/WebCore/page/DOMWindow.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/page/DOMWindow.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -837,7 +837,7 @@
if (!document)
return nullptr;
- if (!document->securityOrigin().canAccessSessionStorage(document->topOrigin()))
+ if (document->canAccessResource(ScriptExecutionContext::ResourceType::SessionStorage) == ScriptExecutionContext::HasResourceAccess::No)
return Exception { SecurityError };
if (m_sessionStorage)
@@ -863,7 +863,7 @@
if (!document)
return nullptr;
- if (!document->securityOrigin().canAccessLocalStorage(nullptr))
+ if (document->canAccessResource(ScriptExecutionContext::ResourceType::LocalStorage) == ScriptExecutionContext::HasResourceAccess::No)
return Exception { SecurityError };
auto* page = document->page();
Modified: trunk/Source/WebCore/page/Page.cpp (292676 => 292677)
--- trunk/Source/WebCore/page/Page.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/page/Page.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -3972,17 +3972,18 @@
mainFrame().loader().initForSynthesizedDocument({ });
auto document = Document::createNonRenderedPlaceholder(mainFrame(), scriptURL);
document->createDOMWindow();
-
document->storageBlockingStateDidChange();
auto origin = topOrigin.securityOrigin();
- origin->setStorageBlockingPolicy(settings().storageBlockingPolicy());
-
auto originAsURL = origin->toURL();
document->setSiteForCookies(originAsURL);
document->setFirstPartyForCookies(originAsURL);
- document->setDomainForCachePartition(origin->domainForCachePartition());
+ if (document->settings().storageBlockingPolicy() != StorageBlockingPolicy::BlockThirdParty)
+ document->setDomainForCachePartition(String { emptyString() });
+ else
+ document->setDomainForCachePartition(origin->domainForCachePartition());
+
if (auto policy = parseReferrerPolicy(referrerPolicy, ReferrerPolicySource::HTTPHeader))
document->setReferrerPolicy(*policy);
Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (292676 => 292677)
--- trunk/Source/WebCore/page/SecurityOrigin.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -208,7 +208,6 @@
, m_universalAccess { other->m_universalAccess }
, m_domainWasSetInDOM { other->m_domainWasSetInDOM }
, m_canLoadLocalResources { other->m_canLoadLocalResources }
- , m_storageBlockingPolicy { other->m_storageBlockingPolicy }
, m_enforcesFilePathSeparation { other->m_enforcesFilePathSeparation }
, m_needsStorageAccessFromFileURLsQuirk { other->m_needsStorageAccessFromFileURLsQuirk }
, m_isPotentiallyTrustworthy { other->m_isPotentiallyTrustworthy }
@@ -418,36 +417,6 @@
return true;
}
-bool SecurityOrigin::canAccessStorage(const SecurityOrigin* topOrigin, ShouldAllowFromThirdParty shouldAllowFromThirdParty) const
-{
- if (isUnique())
- return false;
-
- if (isLocal() && !needsStorageAccessFromFileURLsQuirk() && !m_universalAccess && shouldAllowFromThirdParty != AlwaysAllowFromThirdParty)
- return false;
-
- if (m_storageBlockingPolicy == StorageBlockingPolicy::BlockAll)
- return false;
-
- // FIXME: This check should be replaced with an ASSERT once we can guarantee that topOrigin is not null.
- if (!topOrigin)
- return true;
-
- if (topOrigin->m_storageBlockingPolicy == StorageBlockingPolicy::BlockAll)
- return false;
-
- if (shouldAllowFromThirdParty == AlwaysAllowFromThirdParty)
- return true;
-
- if (m_universalAccess)
- return true;
-
- if ((m_storageBlockingPolicy == StorageBlockingPolicy::BlockThirdParty || topOrigin->m_storageBlockingPolicy == StorageBlockingPolicy::BlockThirdParty) && !topOrigin->isSameOriginAs(*this))
- return false;
-
- return true;
-}
-
SecurityOrigin::Policy SecurityOrigin::canShowNotifications() const
{
if (m_universalAccess)
@@ -517,9 +486,6 @@
String SecurityOrigin::domainForCachePartition() const
{
- if (m_storageBlockingPolicy != StorageBlockingPolicy::BlockThirdParty)
- return emptyString();
-
if (isHTTPFamily())
return host();
Modified: trunk/Source/WebCore/page/SecurityOrigin.h (292676 => 292677)
--- trunk/Source/WebCore/page/SecurityOrigin.h 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/page/SecurityOrigin.h 2022-04-09 08:28:32 UTC (rev 292677)
@@ -29,7 +29,6 @@
#pragma once
#include "SecurityOriginData.h"
-#include "StorageBlockingPolicy.h"
#include <wtf/EnumTraits.h>
#include <wtf/Hasher.h>
#include <wtf/ThreadSafeRefCounted.h>
@@ -139,21 +138,10 @@
void grantUniversalAccess();
bool hasUniversalAccess() const { return m_universalAccess; }
- void setStorageBlockingPolicy(StorageBlockingPolicy policy) { m_storageBlockingPolicy = policy; }
-
void grantStorageAccessFromFileURLsQuirk();
bool needsStorageAccessFromFileURLsQuirk() const { return m_needsStorageAccessFromFileURLsQuirk; }
WEBCORE_EXPORT String domainForCachePartition() const;
-
- bool canAccessDatabase(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin); };
- bool canAccessSessionStorage(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin, AlwaysAllowFromThirdParty); }
- bool canAccessLocalStorage(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin); };
- bool canAccessStorageManager() const { return canAccessStorage(nullptr); }
- bool canAccessPluginStorage(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin); }
- bool canAccessApplicationCache(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin); }
- bool canAccessCookies() const { return !isUnique(); }
- bool canRequestGeolocation() const { return !isUnique(); }
Policy canShowNotifications() const;
// The local SecurityOrigin is the most privileged SecurityOrigin.
@@ -244,7 +232,6 @@
bool m_universalAccess { false };
bool m_domainWasSetInDOM { false };
bool m_canLoadLocalResources { false };
- StorageBlockingPolicy m_storageBlockingPolicy { StorageBlockingPolicy::AllowAll };
bool m_enforcesFilePathSeparation { false };
bool m_needsStorageAccessFromFileURLsQuirk { false };
mutable std::optional<bool> m_isPotentiallyTrustworthy;
@@ -266,7 +253,6 @@
encoder << m_universalAccess;
encoder << m_domainWasSetInDOM;
encoder << m_canLoadLocalResources;
- encoder << m_storageBlockingPolicy;
encoder << m_enforcesFilePathSeparation;
encoder << m_needsStorageAccessFromFileURLsQuirk;
encoder << m_isPotentiallyTrustworthy;
@@ -295,8 +281,6 @@
return nullptr;
if (!decoder.decode(origin->m_canLoadLocalResources))
return nullptr;
- if (!decoder.decode(origin->m_storageBlockingPolicy))
- return nullptr;
if (!decoder.decode(origin->m_enforcesFilePathSeparation))
return nullptr;
if (!decoder.decode(origin->m_needsStorageAccessFromFileURLsQuirk))
Modified: trunk/Source/WebCore/storage/StorageNamespaceProvider.cpp (292676 => 292677)
--- trunk/Source/WebCore/storage/StorageNamespaceProvider.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/storage/StorageNamespaceProvider.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -51,11 +51,8 @@
// so the Document had better still actually have a Page.
ASSERT(document.page());
- bool transient = !document.securityOrigin().canAccessLocalStorage(&document.topOrigin());
-
RefPtr<StorageNamespace> storageNamespace;
-
- if (transient)
+ if (document.canAccessResource(ScriptExecutionContext::ResourceType::LocalStorage) == ScriptExecutionContext::HasResourceAccess::DefaultForThirdParty)
storageNamespace = &transientLocalStorageNamespace(document.topOrigin(), document.page()->sessionID());
else
storageNamespace = &localStorageNamespace(document.page()->sessionID());
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (292676 => 292677)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -116,6 +116,7 @@
if (m_topOrigin->needsStorageAccessFromFileURLsQuirk())
origin->grantStorageAccessFromFileURLsQuirk();
+ setStorageBlockingPolicy(m_settingsValues.storageBlockingPolicy);
setSecurityOriginPolicy(SecurityOriginPolicy::create(WTFMove(origin)));
setContentSecurityPolicy(makeUnique<ContentSecurityPolicy>(URL { m_url }, *this));
setCrossOriginEmbedderPolicy(params.crossOriginEmbedderPolicy);
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (292676 => 292677)
--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -204,6 +204,7 @@
jobData.topOrigin = context->topOrigin().data();
jobData.workerType = options.type;
jobData.type = ServiceWorkerJobType::Register;
+ jobData.domainForCachePartition = context->domainForCachePartition();
jobData.registrationOptions = options;
scheduleJob(makeUnique<ServiceWorkerJob>(*this, WTFMove(promise), WTFMove(jobData)));
@@ -252,6 +253,7 @@
jobData.topOrigin = context.topOrigin().data();
jobData.workerType = workerType;
jobData.type = ServiceWorkerJobType::Update;
+ jobData.domainForCachePartition = context.domainForCachePartition();
jobData.scopeURL = scopeURL;
jobData.scriptURL = scriptURL;
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp (292676 => 292677)
--- trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobData.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -78,6 +78,7 @@
result.clientCreationURL = clientCreationURL.isolatedCopy();
result.topOrigin = topOrigin.isolatedCopy();
result.scopeURL = scopeURL.isolatedCopy();
+ result.domainForCachePartition = domainForCachePartition.isolatedCopy();
result.registrationOptions = registrationOptions.isolatedCopy();
return result;
Modified: trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h (292676 => 292677)
--- trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerJobData.h 2022-04-09 08:28:32 UTC (rev 292677)
@@ -55,6 +55,7 @@
ServiceWorkerOrClientIdentifier sourceContext;
WorkerType workerType;
ServiceWorkerJobType type;
+ String domainForCachePartition;
bool isFromServiceWorkerPage { false };
ServiceWorkerRegistrationOptions registrationOptions;
@@ -75,7 +76,7 @@
template<class Encoder>
void ServiceWorkerJobData::encode(Encoder& encoder) const
{
- encoder << identifier() << scriptURL << clientCreationURL << topOrigin << scopeURL << sourceContext << workerType << isFromServiceWorkerPage;
+ encoder << identifier() << scriptURL << clientCreationURL << topOrigin << scopeURL << sourceContext << workerType << domainForCachePartition << isFromServiceWorkerPage;
encoder << type;
switch (type) {
case ServiceWorkerJobType::Register:
@@ -115,6 +116,8 @@
return std::nullopt;
if (!decoder.decode(jobData.workerType))
return std::nullopt;
+ if (!decoder.decode(jobData.domainForCachePartition))
+ return std::nullopt;
if (!decoder.decode(jobData.isFromServiceWorkerPage))
return std::nullopt;
if (!decoder.decode(jobData.type))
Modified: trunk/Source/WebCore/workers/service/server/SWServer.cpp (292676 => 292677)
--- trunk/Source/WebCore/workers/service/server/SWServer.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/workers/service/server/SWServer.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -510,7 +510,7 @@
auto topOrigin = jobData.topOrigin.securityOrigin();
auto origin = SecurityOrigin::create(jobData.scriptURL);
- request.setDomainForCachePartition(topOrigin->domainForCachePartition());
+ request.setDomainForCachePartition(jobData.domainForCachePartition);
request.setAllowCookies(true);
request.setFirstPartyForCookies(originURL(topOrigin));
Modified: trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp (292676 => 292677)
--- trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebCore/worklets/WorkletGlobalScope.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -58,6 +58,7 @@
{
++gNumberOfWorkletGlobalScopes;
+ setStorageBlockingPolicy(parameters.settingsValues.storageBlockingPolicy);
setSecurityOriginPolicy(SecurityOriginPolicy::create(SecurityOrigin::create(this->url())));
setContentSecurityPolicy(makeUnique<ContentSecurityPolicy>(URL { this->url() }, *this));
}
@@ -75,6 +76,7 @@
ASSERT(document.page());
+ setStorageBlockingPolicy(m_document->settings().storageBlockingPolicy());
setSecurityOriginPolicy(SecurityOriginPolicy::create(SecurityOrigin::create(this->url())));
setContentSecurityPolicy(makeUnique<ContentSecurityPolicy>(URL { this->url() }, *this));
}
Modified: trunk/Source/WebKit/ChangeLog (292676 => 292677)
--- trunk/Source/WebKit/ChangeLog 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebKit/ChangeLog 2022-04-09 08:28:32 UTC (rev 292677)
@@ -1,3 +1,14 @@
+2022-04-09 Sihui Liu <[email protected]>
+
+ Move canAccessStorage() check from SecurityOrigin to ScriptExecutionContext
+ https://bugs.webkit.org/show_bug.cgi?id=238524
+ <rdar://problem/91318259>
+
+ Reviewed by Chris Dumez.
+
+ * WebProcess/Plugins/PluginView.cpp:
+ (WebKit::PluginView::storageBlockingStateChanged):
+
2022-04-08 Chris Dumez <[email protected]>
Drop unused pluginReplacementScriptObject
Modified: trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp (292676 => 292677)
--- trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp 2022-04-09 06:29:20 UTC (rev 292676)
+++ trunk/Source/WebKit/WebProcess/Plugins/PluginView.cpp 2022-04-09 08:28:32 UTC (rev 292677)
@@ -597,8 +597,7 @@
if (!m_isInitialized || !m_plugin)
return;
- bool storageBlockingPolicy = !frame()->document()->securityOrigin().canAccessPluginStorage(frame()->document()->topOrigin());
-
+ bool storageBlockingPolicy = frame()->document()->canAccessResource(ScriptExecutionContext::ResourceType::Plugin) != ScriptExecutionContext::HasResourceAccess::Yes;
m_plugin->storageBlockingStateChanged(storageBlockingPolicy);
}