Changeset 291726 in webkit


Ignore:
Timestamp:
Mar 22, 2022 4:53:16 PM (4 months ago)
Author:
sihui_liu@apple.com
Message:

Check if origin can access storage in Storage API
https://bugs.webkit.org/show_bug.cgi?id=238158

Reviewed by Chris Dumez.

LayoutTests/imported/w3c:

  • web-platform-tests/file-system-access/opaque-origin.https.window-expected.txt:
  • web-platform-tests/storage/opaque-origin.https.window-expected.txt:

Source/WebCore:

According to spec https://storage.spec.whatwg.org/#obtain-a-storage-key, origin should not access Storage API if
it's opaque. Also, origin should not access storage if it's blocked by storage policy, so we use
SecurityOrigin::canAccessStorage to perform the origin check, like what we do for the other storage APIs.

Updated expectation for imported tests.

  • Modules/storage/StorageManager.cpp:

(WebCore::connectionInfo):

  • page/SecurityOrigin.h:

(WebCore::SecurityOrigin::canAccessStorageManager const):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r291690 r291726  
     12022-03-22  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Check if origin can access storage in Storage API
     4        https://bugs.webkit.org/show_bug.cgi?id=238158
     5
     6        Reviewed by Chris Dumez.
     7
     8        * web-platform-tests/file-system-access/opaque-origin.https.window-expected.txt:
     9        * web-platform-tests/storage/opaque-origin.https.window-expected.txt:
     10
    1112022-03-22  Commit Queue  <commit-queue@webkit.org>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/opaque-origin.https.window-expected.txt

    r283029 r291726  
    33PASS FileSystemDirectoryHandle must be undefined for data URI iframes.
    44FAIL 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 "showDirectoryPicker(): EXCEPTION: TypeError"
     5FAIL 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"
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/storage/opaque-origin.https.window-expected.txt

    r282130 r291726  
    11
    22PASS navigator.storage.persisted() in non-sandboxed iframe should not reject
    3 FAIL navigator.storage.persisted() in sandboxed iframe should reject with TypeError assert_equals: navigator.storage.persisted() should reject with TypeError expected "correct rejection" but got "no rejection"
     3PASS navigator.storage.persisted() in sandboxed iframe should reject with TypeError
    44FAIL navigator.storage.estimate() in non-sandboxed iframe should not reject assert_equals: navigator.storage.estimate() should not reject expected "no rejection" but got "API access threw"
    55FAIL navigator.storage.estimate() in sandboxed iframe should reject with TypeError assert_equals: navigator.storage.estimate() should reject with TypeError expected "correct rejection" but got "API access threw"
    66PASS navigator.storage.persist() in non-sandboxed iframe should not reject
    7 FAIL navigator.storage.persist() in sandboxed iframe should reject with TypeError assert_equals: navigator.storage.persist() should reject with TypeError expected "correct rejection" but got "no rejection"
     7PASS navigator.storage.persist() in sandboxed iframe should reject with TypeError
    88
  • trunk/Source/WebCore/ChangeLog

    r291725 r291726  
     12022-03-22  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Check if origin can access storage in Storage API
     4        https://bugs.webkit.org/show_bug.cgi?id=238158
     5
     6        Reviewed by Chris Dumez.
     7
     8        According to spec https://storage.spec.whatwg.org/#obtain-a-storage-key, origin should not access Storage API if
     9        it's opaque. Also, origin should not access storage if it's blocked by storage policy, so we use
     10        SecurityOrigin::canAccessStorage to perform the origin check, like what we do for the other storage APIs.
     11
     12        Updated expectation for imported tests.
     13
     14        * Modules/storage/StorageManager.cpp:
     15        (WebCore::connectionInfo):
     16        * page/SecurityOrigin.h:
     17        (WebCore::SecurityOrigin::canAccessStorageManager const):
     18
    1192022-03-22  Alan Bujtas  <zalan@apple.com>
    220
  • trunk/Source/WebCore/Modules/storage/StorageManager.cpp

    r291123 r291726  
    7171    if (!origin)
    7272        return Exception { InvalidStateError, "Origin is invalid"_s };
    73    
     73
     74    if (!origin->canAccessStorageManager())
     75        return Exception { TypeError, "Origin should not access storage" };
     76
    7477    if (is<Document>(context)) {
    7578        if (auto* connection = downcast<Document>(context)->storageConnection())
  • trunk/Source/WebCore/page/SecurityOrigin.h

    r290349 r291726  
    150150    bool canAccessSessionStorage(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin, AlwaysAllowFromThirdParty); }
    151151    bool canAccessLocalStorage(const SecurityOrigin* topOrigin) const { return canAccessStorage(topOrigin); };
     152    bool canAccessStorageManager() const { return canAccessStorage(nullptr); }
    152153    bool canAccessPluginStorage(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin); }
    153154    bool canAccessApplicationCache(const SecurityOrigin& topOrigin) const { return canAccessStorage(&topOrigin); }
Note: See TracChangeset for help on using the changeset viewer.