Changeset 56002 in webkit


Ignore:
Timestamp:
Mar 15, 2010 10:14:10 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-03-15 Patrik Persson <patrik.j.persson@ericsson.com>

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=32369

Revised test of storage/databases in sandboxed iframes.

Verify that SECURITY_ERR is raised on access to
window.localStorage or window.openDatabase(). Also verify that
window.sessionStorage is now allowed in sandboxed iframes.

WebKit would previously return null references in these cases. The
new behavior is in accordance with HTML5:

  • fast/frames/resources/sandboxed-iframe-storage-disallowed.html: expect exceptions, not null
  • fast/frames/sandboxed-iframe-storage-expected.txt: expect exceptions, not null

2010-03-15 Patrik Persson <patrik.j.persson@ericsson.com>

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=32369

Revise iframe sandbox behavior to match the updated HTML5 spec.

  • Enables window.sessionStorage in sandboxed iframes.
  • Raises SECURITY_ERR exceptions when window.localStorage or window.openDatabase() is blocked by iframe sandboxing.

Note: window.sessionStorage does not raise exceptions.

WebKit would previously return null references in these cases. The
new behavior is in accordance with HTML5:

http://dev.w3.org/html5/webstorage/ (sections 4.2 and 4.3)
http://dev.w3.org/html5/webdatabase/ (section 4.1)
http://www.mail-archive.com/whatwg@lists.whatwg.org/msg19786.html

  • inspector/InspectorController.cpp: (WebCore::InspectorController::selectDOMStorage): exception handling
  • inspector/InspectorDOMStorageResource.cpp: (WebCore::InspectorDOMStorageResource::handleEvent): exception handling
  • page/DOMWindow.cpp: (WebCore::DOMWindow::sessionStorage): re-enabled in iframe sandbox (WebCore::DOMWindow::localStorage): raise exception rather than return null (WebCore::DOMWindow::openDatabase): raise exception rather than return null
  • page/DOMWindow.h: added exceptions to interface
  • page/DOMWindow.idl: added exceptions to interface
  • page/SecurityOrigin.h: (WebCore::SecurityOrigin::canAccessLocalStorage): renamed function to reflect its purpose
  • storage/StorageEventDispatcher.cpp: (WebCore::StorageEventDispatcher::dispatch): exception handling

2010-03-15 Patrik Persson <patrik.j.persson@ericsson.com>

Reviewed by Darin Adler.

https://bugs.webkit.org/show_bug.cgi?id=32369

Revise iframe sandbox behavior to match the updated HTML5 spec.

  • Enables window.sessionStorage in sandboxed iframes.
  • Raises SECURITY_ERR exceptions when window.localStorage or window.openDatabase() is blocked by iframe sandboxing.

Note: window.sessionStorage does not raise exceptions.

WebKit would previously return null references in these cases. The
new behavior is in accordance with HTML5:

http://dev.w3.org/html5/webstorage/ (sections 4.2 and 4.3)
http://dev.w3.org/html5/webdatabase/ (section 4.1)
http://www.mail-archive.com/whatwg@lists.whatwg.org/msg19786.html

  • src/StorageAreaProxy.cpp: (WebCore::StorageAreaProxy::storageEvent): exception handling
  • src/StorageEventDispatcherImpl.cpp: (WebCore::StorageEventDispatcherImpl::dispatchStorageEvent): exception handling
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r55998 r56002  
     12010-03-15  Patrik Persson  <patrik.j.persson@ericsson.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=32369
     6
     7        Revised test of storage/databases in sandboxed iframes.
     8       
     9        Verify that SECURITY_ERR is raised on access to
     10        window.localStorage or window.openDatabase(). Also verify that
     11        window.sessionStorage is now allowed in sandboxed iframes.
     12
     13        WebKit would previously return null references in these cases.  The
     14        new behavior is in accordance with HTML5:
     15
     16        - http://dev.w3.org/html5/webstorage/   (sections 4.2 and 4.3)
     17        - http://dev.w3.org/html5/webdatabase/  (section 4.1)
     18        - http://www.mail-archive.com/whatwg@lists.whatwg.org/msg19786.html
     19
     20        * fast/frames/resources/sandboxed-iframe-storage-disallowed.html: expect exceptions, not null
     21        * fast/frames/sandboxed-iframe-storage-expected.txt: expect exceptions, not null
     22
    1232010-03-15  Tony Chang  <tony@chromium.org>
    224
  • trunk/LayoutTests/fast/frames/resources/sandboxed-iframe-storage-disallowed.html

    r55823 r56002  
    77
    88window.onload = function() {
    9     shouldBeTrue("window.openDatabase('SandboxedIframeStorageDisallowed', '1.0', '', 1) == null");
    10     shouldBeTrue("window.localStorage == null");
    11     shouldBeTrue("window.sessionStorage == null");
     9    shouldThrow("window.openDatabase('SandboxedIframeStorageDisallowed', '1.0', '', 1)", "'Error: SECURITY_ERR: DOM Exception 18'");
     10    shouldThrow("window.localStorage", "'Error: SECURITY_ERR: DOM Exception 18'");
     11    shouldBeTrue("window.sessionStorage != null");
    1212}
    1313
  • trunk/LayoutTests/fast/frames/sandboxed-iframe-storage-expected.txt

    r55823 r56002  
    1515Frame: '<!--framePath //<!--frame0-->-->'
    1616--------
    17 PASS window.openDatabase('SandboxedIframeStorageDisallowed', '1.0', '', 1) == null is true
    18 PASS window.localStorage == null is true
    19 PASS window.sessionStorage == null is true
     17PASS window.openDatabase('SandboxedIframeStorageDisallowed', '1.0', '', 1) threw exception Error: SECURITY_ERR: DOM Exception 18.
     18PASS window.localStorage threw exception Error: SECURITY_ERR: DOM Exception 18.
     19PASS window.sessionStorage != null is true
    2020
    2121
  • trunk/WebCore/ChangeLog

    r55999 r56002  
     12010-03-15  Patrik Persson  <patrik.j.persson@ericsson.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=32369
     6
     7        Revise iframe sandbox behavior to match the updated HTML5 spec.
     8
     9        - Enables window.sessionStorage in sandboxed iframes.
     10
     11        - Raises SECURITY_ERR exceptions when window.localStorage or
     12          window.openDatabase() is blocked by iframe sandboxing.
     13
     14          Note: window.sessionStorage does not raise exceptions.
     15
     16        WebKit would previously return null references in these cases.  The
     17        new behavior is in accordance with HTML5:
     18
     19          http://dev.w3.org/html5/webstorage/   (sections 4.2 and 4.3)
     20          http://dev.w3.org/html5/webdatabase/  (section 4.1)
     21          http://www.mail-archive.com/whatwg@lists.whatwg.org/msg19786.html
     22
     23        * inspector/InspectorController.cpp:
     24        (WebCore::InspectorController::selectDOMStorage): exception handling
     25        * inspector/InspectorDOMStorageResource.cpp:
     26        (WebCore::InspectorDOMStorageResource::handleEvent): exception handling
     27        * page/DOMWindow.cpp:
     28        (WebCore::DOMWindow::sessionStorage): re-enabled in iframe sandbox
     29        (WebCore::DOMWindow::localStorage): raise exception rather than return null
     30        (WebCore::DOMWindow::openDatabase): raise exception rather than return null
     31        * page/DOMWindow.h: added exceptions to interface
     32        * page/DOMWindow.idl: added exceptions to interface
     33        * page/SecurityOrigin.h:
     34        (WebCore::SecurityOrigin::canAccessLocalStorage): renamed function to reflect its purpose
     35        * storage/StorageEventDispatcher.cpp:
     36        (WebCore::StorageEventDispatcher::dispatch): exception handling
     37
    1382010-03-15  Alexander Pavlov  <apavlov@chromium.org>
    239
  • trunk/WebCore/inspector/InspectorController.cpp

    r55799 r56002  
    13641364
    13651365    Frame* frame = storage->frame();
    1366     bool isLocalStorage = (frame->domWindow()->localStorage() == storage);
     1366    ExceptionCode ec = 0;
     1367    bool isLocalStorage = (frame->domWindow()->localStorage(ec) == storage && !ec);
    13671368    int storageResourceId = 0;
    13681369    DOMStorageResourcesMap::iterator domStorageEnd = m_domStorageResources.end();
  • trunk/WebCore/inspector/InspectorDOMStorageResource.cpp

    r49830 r56002  
    105105    StorageEvent* storageEvent = static_cast<StorageEvent*>(event);
    106106    Storage* storage = storageEvent->storageArea();
    107     bool isLocalStorage = storage->frame()->domWindow()->localStorage() == storage;
     107    ExceptionCode ec = 0;
     108    bool isLocalStorage = (storage->frame()->domWindow()->localStorage(ec) == storage && !ec);
    108109    if (isSameHostAndType(storage->frame(), isLocalStorage))
    109110        m_frontend->updateDOMStorage(m_id);
  • trunk/WebCore/page/DOMWindow.cpp

    r55823 r56002  
    576576    if (!document)
    577577        return 0;
    578    
    579     if (!document->securityOrigin()->canAccessStorage())
    580         return 0;
    581578
    582579    Page* page = document->page();
     
    593590}
    594591
    595 Storage* DOMWindow::localStorage() const
     592Storage* DOMWindow::localStorage(ExceptionCode& ec) const
    596593{
    597594    if (m_localStorage)
     
    602599        return 0;
    603600   
    604     if (!document->securityOrigin()->canAccessStorage())
    605         return 0;
     601    if (!document->securityOrigin()->canAccessLocalStorage()) {
     602        ec = SECURITY_ERR;
     603        return 0;
     604    }
    606605       
    607606    Page* page = document->page();
     
    11881187
    11891188    Document* document = m_frame->document();
    1190     if (!document->securityOrigin()->canAccessDatabase())
    1191         return 0;
     1189    if (!document->securityOrigin()->canAccessDatabase()) {
     1190        ec = SECURITY_ERR;
     1191        return 0;
     1192    }
    11921193
    11931194    return Database::openDatabase(document, name, version, displayName, estimatedSize, creationCallback, ec);
  • trunk/WebCore/page/DOMWindow.h

    r55823 r56002  
    208208        // HTML 5 key/value storage
    209209        Storage* sessionStorage() const;
    210         Storage* localStorage() const;
     210        Storage* localStorage(ExceptionCode&) const;
    211211#endif
    212212
  • trunk/WebCore/page/DOMWindow.idl

    r55980 r56002  
    166166#if defined(ENABLE_DOM_STORAGE) && ENABLE_DOM_STORAGE
    167167        readonly attribute [EnabledAtRuntime] Storage sessionStorage;
    168         readonly attribute [EnabledAtRuntime] Storage localStorage;
     168        readonly attribute [EnabledAtRuntime] Storage localStorage
     169            getter raises(DOMException);
    169170#endif
    170171#if defined(ENABLE_NOTIFICATIONS) && ENABLE_NOTIFICATIONS
  • trunk/WebCore/page/SecurityOrigin.h

    r55335 r56002  
    118118
    119119    bool canAccessDatabase() const { return !isUnique(); }
    120     bool canAccessStorage() const { return !isUnique(); }
     120    bool canAccessLocalStorage() const { return !isUnique(); }
    121121    bool canAccessCookies() const { return !isUnique(); }
    122122
  • trunk/WebCore/storage/StorageEventDispatcher.cpp

    r53840 r56002  
    6868        }
    6969
    70         for (unsigned i = 0; i < frames.size(); ++i)
    71             frames[i]->document()->enqueueStorageEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->localStorage()));
     70        for (unsigned i = 0; i < frames.size(); ++i) {
     71            ExceptionCode ec = 0;
     72            Storage* storage = frames[i]->domWindow()->localStorage(ec);
     73            if (!ec)
     74                frames[i]->document()->enqueueStorageEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), storage));
     75        }
    7276    }
    7377}
  • trunk/WebKit/chromium/ChangeLog

    r55998 r56002  
     12010-03-15  Patrik Persson  <patrik.j.persson@ericsson.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=32369
     6
     7        Revise iframe sandbox behavior to match the updated HTML5 spec.
     8
     9        - Enables window.sessionStorage in sandboxed iframes.
     10
     11        - Raises SECURITY_ERR exceptions when window.localStorage or
     12          window.openDatabase() is blocked by iframe sandboxing.
     13
     14          Note: window.sessionStorage does not raise exceptions.
     15
     16        WebKit would previously return null references in these cases.  The
     17        new behavior is in accordance with HTML5:
     18
     19          http://dev.w3.org/html5/webstorage/   (sections 4.2 and 4.3)
     20          http://dev.w3.org/html5/webdatabase/  (section 4.1)
     21          http://www.mail-archive.com/whatwg@lists.whatwg.org/msg19786.html
     22
     23        * src/StorageAreaProxy.cpp:
     24        (WebCore::StorageAreaProxy::storageEvent): exception handling
     25        * src/StorageEventDispatcherImpl.cpp:
     26        (WebCore::StorageEventDispatcherImpl::dispatchStorageEvent): exception handling
     27
    1282010-03-15  Tony Chang  <tony@chromium.org>
    229
  • trunk/WebKit/chromium/src/StorageAreaProxy.cpp

    r55659 r56002  
    139139        }
    140140
    141         for (unsigned i = 0; i < frames.size(); ++i)
    142             frames[i]->document()->enqueueStorageEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), frames[i]->domWindow()->localStorage()));
     141        for (unsigned i = 0; i < frames.size(); ++i) {
     142            ExceptionCode ec = 0;
     143            Storage* storage = frames[i]->domWindow()->localStorage(ec);
     144            if (!ec)
     145                frames[i]->document()->enqueueStorageEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue, sourceFrame->document()->url(), storage));
     146        }
    143147    }
    144148}
  • trunk/WebKit/chromium/src/StorageEventDispatcherImpl.cpp

    r50746 r56002  
    7474    // FIXME: Figure out how to pass in the document URI.
    7575    for (unsigned i = 0; i < frames.size(); ++i) {
    76         frames[i]->document()->dispatchWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue,
    77                                                                         url, frames[i]->domWindow()->localStorage()));
     76        ExceptionCode ec = 0;
     77        Storage* storage = frames[i]->domWindow()->localStorage(ec);
     78        if (!ec)
     79            frames[i]->document()->dispatchWindowEvent(StorageEvent::create(eventNames().storageEvent, key, oldValue, newValue,
     80                                                                            url, storage));
    7881    }
    7982}
Note: See TracChangeset for help on using the changeset viewer.