Skip to content

Commit d59f05a

Browse files
committed
StorageManager::getDirectory should throw SecurityError for opaque origin
rdar://152269409 https://bugs.webkit.org/show_bug.cgi?id=293763 Reviewed by Per Arne Vollan. To match the behavior in other browsers. * LayoutTests/imported/w3c/web-platform-tests/file-system-access/opaque-origin.https.window-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/fs/opaque-origin.https.window-expected.txt: * Source/WebCore/Modules/storage/StorageManager.cpp: (WebCore::connectionInfo): (WebCore::StorageManager::persisted): (WebCore::StorageManager::persist): (WebCore::StorageManager::estimate): (WebCore::StorageManager::fileSystemAccessGetDirectory): Canonical link: https://commits.webkit.org/295843@main
1 parent d0428fe commit d59f05a

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

LayoutTests/imported/w3c/web-platform-tests/file-system-access/opaque-origin.https.window-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
PASS showDirectoryPicker() must be undefined for data URI iframes.
33
PASS FileSystemDirectoryHandle must be undefined for data URI iframes.
44
FAIL navigator.storage.getDirectory() and showDirectoryPicker() must reject in a sandboxed iframe. assert_equals: expected "showDirectoryPicker(): REJECTED: SecurityError" but got "showDirectoryPicker(): EXCEPTION: TypeError"
5-
FAIL navigator.storage.getDirectory() and showDirectoryPicker() must reject in a sandboxed opened window. assert_equals: expected "showDirectoryPicker(): REJECTED: SecurityError" but got "navigator.storage.getDirectory(): REJECTED: TypeError"
5+
FAIL navigator.storage.getDirectory() and showDirectoryPicker() must reject in a sandboxed opened window. assert_equals: expected "showDirectoryPicker(): REJECTED: SecurityError" but got "navigator.storage.getDirectory(): REJECTED: SecurityError"
66

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
FAIL FileSystemDirectoryHandle must be defined for data URI iframes. assert_true: Data URI iframes must define 'FileSystemDirectoryHandle'. expected true got false
3-
FAIL navigator.storage.getDirectory() must reject in a sandboxed iframe. assert_equals: expected "navigator.storage.getDirectory(): REJECTED: SecurityError" but got "navigator.storage.getDirectory(): REJECTED: TypeError"
4-
FAIL navigator.storage.getDirectory() must reject in a sandboxed opened window. assert_equals: expected "navigator.storage.getDirectory(): REJECTED: SecurityError" but got "navigator.storage.getDirectory(): REJECTED: TypeError"
3+
PASS navigator.storage.getDirectory() must reject in a sandboxed iframe.
4+
PASS navigator.storage.getDirectory() must reject in a sandboxed opened window.
55

Source/WebCore/Modules/storage/StorageManager.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ struct ConnectionInfo {
6262
ClientOrigin origin;
6363
};
6464

65-
static ExceptionOr<ConnectionInfo> connectionInfo(NavigatorBase* navigator)
65+
static ExceptionOr<ConnectionInfo> connectionInfo(NavigatorBase* navigator, ExceptionCode exceptionCodeForNoAccess)
6666
{
6767
if (!navigator)
6868
return Exception { ExceptionCode::InvalidStateError, "Navigator does not exist"_s };
@@ -72,7 +72,7 @@ static ExceptionOr<ConnectionInfo> connectionInfo(NavigatorBase* navigator)
7272
return Exception { ExceptionCode::InvalidStateError, "Context is invalid"_s };
7373

7474
if (context->canAccessResource(ScriptExecutionContext::ResourceType::StorageManager) == ScriptExecutionContext::HasResourceAccess::No)
75-
return Exception { ExceptionCode::TypeError, "Context not access storage"_s };
75+
return Exception { exceptionCodeForNoAccess, "Context not access storage"_s };
7676

7777
RefPtr origin = context->securityOrigin();
7878
ASSERT(origin);
@@ -92,7 +92,7 @@ static ExceptionOr<ConnectionInfo> connectionInfo(NavigatorBase* navigator)
9292

9393
void StorageManager::persisted(DOMPromiseDeferred<IDLBoolean>&& promise)
9494
{
95-
auto connectionInfoOrException = connectionInfo(m_navigator.get());
95+
auto connectionInfoOrException = connectionInfo(m_navigator.get(), ExceptionCode::TypeError);
9696
if (connectionInfoOrException.hasException())
9797
return promise.reject(connectionInfoOrException.releaseException());
9898

@@ -104,7 +104,7 @@ void StorageManager::persisted(DOMPromiseDeferred<IDLBoolean>&& promise)
104104

105105
void StorageManager::persist(DOMPromiseDeferred<IDLBoolean>&& promise)
106106
{
107-
auto connectionInfoOrException = connectionInfo(m_navigator.get());
107+
auto connectionInfoOrException = connectionInfo(m_navigator.get(), ExceptionCode::TypeError);
108108
if (connectionInfoOrException.hasException())
109109
return promise.reject(connectionInfoOrException.releaseException());
110110

@@ -116,7 +116,7 @@ void StorageManager::persist(DOMPromiseDeferred<IDLBoolean>&& promise)
116116

117117
void StorageManager::estimate(DOMPromiseDeferred<IDLDictionary<StorageEstimate>>&& promise)
118118
{
119-
auto connectionInfoOrException = connectionInfo(m_navigator.get());
119+
auto connectionInfoOrException = connectionInfo(m_navigator.get(), ExceptionCode::TypeError);
120120
if (connectionInfoOrException.hasException())
121121
return promise.reject(connectionInfoOrException.releaseException());
122122

@@ -128,7 +128,7 @@ void StorageManager::estimate(DOMPromiseDeferred<IDLDictionary<StorageEstimate>>
128128

129129
void StorageManager::fileSystemAccessGetDirectory(DOMPromiseDeferred<IDLInterface<FileSystemDirectoryHandle>>&& promise)
130130
{
131-
auto connectionInfoOrException = connectionInfo(m_navigator.get());
131+
auto connectionInfoOrException = connectionInfo(m_navigator.get(), ExceptionCode::SecurityError);
132132
if (connectionInfoOrException.hasException())
133133
return promise.reject(connectionInfoOrException.releaseException());
134134

0 commit comments

Comments
 (0)