Title: [141418] trunk
Revision
141418
Author
[email protected]
Date
2013-01-31 06:57:55 -0800 (Thu, 31 Jan 2013)

Log Message

Allow blocking of IndexedDB in third-party contexts
https://bugs.webkit.org/show_bug.cgi?id=94171

Reviewed by Jochen Eisinger.

Source/WebCore:

This patch ensures that the origin of the top window is passed into
SecurityOrigin::canAccessDatabase when working with IndexedDB. Giving
SecurityOrigin access to this data means that it can properly check
whether the database is being opened in a third-party context, and
therefore properly enforce the third-party access checks that were
added in http://trac.webkit.org/changeset/125736.

Third-party checks are added to IDBFactory::open,
IDBFactory::deleteDatabase, and IDBFactory::getDatabaseNames; each will
now throw a SECURITY_ERR exception when access in a third-party context
if third-party access checks are enabled.

To make this process slightly more clear, and avoid some ugly casting
logic, this patch adds a 'topOrigin'  method to ScriptExecutionContext,
and implements it on both WorkerContext and Document.

Tests: http/tests/security/cross-origin-indexeddb-allowed.html
       http/tests/security/cross-origin-indexeddb.html
       http/tests/security/cross-origin-worker-indexeddb-allowed.html
       http/tests/security/cross-origin-worker-indexeddb.html

* Modules/indexeddb/IDBFactory.cpp:
(WebCore::IDBFactory::getDatabaseNames):
(WebCore::IDBFactory::openInternal):
(WebCore::IDBFactory::deleteDatabase):
    Grab the SecurityOrigin of the current context's top-level origin,
    and pass it to SecurityOrigin::canAccessDatabase to ensure that
    access checks are properly applied to these three methods.
* dom/Document.cpp:
(WebCore::Document::topOrigin):
(WebCore):
* dom/Document.h:
(Document):
* dom/ScriptExecutionContext.h:
(ScriptExecutionContext):
    Add a topOrigin() method to ScriptExecutionContext, and implement it
    on Document in order to give callers access to the top document's
    SecurityOrigin without casting ScriptExecutionContext.
* workers/WorkerContext.h:
    Change the existing topOrigin() method to override the new method
    on ScriptExecutionContext.

LayoutTests:

Add tests to ensure that IndexedDB can be blocked in a third-party
context in both normal documents and in workers. These tests are
modeled after the existing cross-origin-websql* tests; it might be
possible to reuse some code in the future.

* http/tests/security/cross-origin-indexeddb-allowed-expected.txt: Added.
* http/tests/security/cross-origin-indexeddb-allowed.html: Added.
* http/tests/security/cross-origin-indexeddb-expected.txt: Added.
* http/tests/security/cross-origin-indexeddb.html: Added.
* http/tests/security/cross-origin-worker-indexeddb-allowed-expected.txt: Added.
* http/tests/security/cross-origin-worker-indexeddb-allowed.html: Added.
* http/tests/security/cross-origin-worker-indexeddb-expected.txt: Added.
* http/tests/security/cross-origin-worker-indexeddb.html: Added.
* http/tests/security/resources/cross-origin-iframe-for-indexeddb.html: Added.
* http/tests/security/resources/cross-origin-iframe-for-worker-indexeddb.html: Added.
* http/tests/security/resources/document-for-cross-origin-worker-indexeddb.html: Added.
* http/tests/security/resources/worker-for-indexeddb.js: Added.
(self.onmessage):
    Add exciting new tests, with more boilerplate than I expected!
* platform/efl/TestExpectations:
* platform/mac-snowleopard/TestExpectations:
* platform/mac/TestExpectations:
* platform/qt/TestExpectations:
* platform/win/TestExpectations:
* platform/wincairo/TestExpectations:
    Skip these IndexedDB tests on platforms where the feature isn't
    enabled.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (141417 => 141418)


--- trunk/LayoutTests/ChangeLog	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/LayoutTests/ChangeLog	2013-01-31 14:57:55 UTC (rev 141418)
@@ -1,3 +1,38 @@
+2013-01-31  Mike West  <[email protected]>
+
+        Allow blocking of IndexedDB in third-party contexts
+        https://bugs.webkit.org/show_bug.cgi?id=94171
+
+        Reviewed by Jochen Eisinger.
+
+        Add tests to ensure that IndexedDB can be blocked in a third-party
+        context in both normal documents and in workers. These tests are
+        modeled after the existing cross-origin-websql* tests; it might be
+        possible to reuse some code in the future.
+
+        * http/tests/security/cross-origin-indexeddb-allowed-expected.txt: Added.
+        * http/tests/security/cross-origin-indexeddb-allowed.html: Added.
+        * http/tests/security/cross-origin-indexeddb-expected.txt: Added.
+        * http/tests/security/cross-origin-indexeddb.html: Added.
+        * http/tests/security/cross-origin-worker-indexeddb-allowed-expected.txt: Added.
+        * http/tests/security/cross-origin-worker-indexeddb-allowed.html: Added.
+        * http/tests/security/cross-origin-worker-indexeddb-expected.txt: Added.
+        * http/tests/security/cross-origin-worker-indexeddb.html: Added.
+        * http/tests/security/resources/cross-origin-iframe-for-indexeddb.html: Added.
+        * http/tests/security/resources/cross-origin-iframe-for-worker-indexeddb.html: Added.
+        * http/tests/security/resources/document-for-cross-origin-worker-indexeddb.html: Added.
+        * http/tests/security/resources/worker-for-indexeddb.js: Added.
+        (self.onmessage):
+            Add exciting new tests, with more boilerplate than I expected!
+        * platform/efl/TestExpectations:
+        * platform/mac-snowleopard/TestExpectations:
+        * platform/mac/TestExpectations:
+        * platform/qt/TestExpectations:
+        * platform/win/TestExpectations:
+        * platform/wincairo/TestExpectations:
+            Skip these IndexedDB tests on platforms where the feature isn't
+            enabled.
+
 2013-01-31  Ádám Kallai  <[email protected]>
 
         [Qt] Unreviewed gardening. Skip two compositing tests, because They hit assertion fail after 140999.

Added: trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-allowed-expected.txt (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-allowed-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-allowed-expected.txt	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,19 @@
+Both of these frames should successfully open the database:
+
+  
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+Successfully called window.webkitIndexedDB.deleteDatabase().
+Successfully called window.webkitIndexedDB.open().
+Successfully called window.webkitIndexedDB.webkitGetDatabaseNames().
+
+
+--------
+Frame: '<!--framePath //<!--frame1-->-->'
+--------
+Successfully called window.webkitIndexedDB.deleteDatabase().
+Successfully called window.webkitIndexedDB.open().
+Successfully called window.webkitIndexedDB.webkitGetDatabaseNames().
+

Added: trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-allowed.html (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-allowed.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-allowed.html	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.dumpChildFramesAsText();
+        }
+    </script>
+</head>
+<body>
+    <p>Both of these frames should successfully open the database:</p>
+    <iframe src=""
+    <iframe src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-expected.txt (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-indexeddb-expected.txt	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,19 @@
+The first iframe below should return a security error, and the second should successfully open the database.
+
+  
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+window.webkitIndexedDB.deleteDatabase() threw an exception: SecurityError
+window.webkitIndexedDB.open() threw an exception: SecurityError
+window.webkitIndexedDB.webkitGetDatabaseNames() threw an exception: SecurityError
+
+
+--------
+Frame: '<!--framePath //<!--frame1-->-->'
+--------
+Successfully called window.webkitIndexedDB.deleteDatabase().
+Successfully called window.webkitIndexedDB.open().
+Successfully called window.webkitIndexedDB.webkitGetDatabaseNames().
+

Added: trunk/LayoutTests/http/tests/security/cross-origin-indexeddb.html (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-indexeddb.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-indexeddb.html	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        var frames = 2;
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.dumpChildFramesAsText();
+            internals.settings.setStorageBlockingPolicy('BlockThirdParty');
+        }
+
+        function decrement() {
+            --frames;
+            if (!frames && window.testRunner)
+                internals.settings.setStorageBlockingPolicy('AllowAll');
+        }
+    </script>
+</head>
+<body>
+    <p>The first iframe below should return a security error, and the second should successfully open the database.</p>
+    <iframe src="" _onload_="decrement()"></iframe>
+    <iframe src="" _onload_="decrement()"></iframe>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-allowed-expected.txt (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-allowed-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-allowed-expected.txt	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,19 @@
+Both of these frames should successfully open the database:
+
+  
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+Successfully called self.webkitIndexedDB.deleteDatabase().
+Successfully called self.webkitIndexedDB.open().
+Successfully called self.webkitIndexedDB.webkitGetDatabaseNames().
+
+
+--------
+Frame: '<!--framePath //<!--frame1-->-->'
+--------
+Successfully called self.webkitIndexedDB.deleteDatabase().
+Successfully called self.webkitIndexedDB.open().
+Successfully called self.webkitIndexedDB.webkitGetDatabaseNames().
+

Added: trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-allowed.html (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-allowed.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-allowed.html	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        var frames = 2;
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.dumpChildFramesAsText();
+            testRunner.waitUntilDone();
+        }
+
+        function decrement() {
+            --frames;
+            if (!frames && window.testRunner)
+                testRunner.notifyDone();
+        }
+
+        window._onmessage_ = decrement;
+    </script>
+</head>
+<body>
+    <p>Both of these frames should successfully open the database:</p>
+    <iframe src=""
+    <iframe src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-expected.txt (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb-expected.txt	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,19 @@
+The first iframe below should return a security error, and the second should successfully open the database.
+
+  
+
+--------
+Frame: '<!--framePath //<!--frame0-->-->'
+--------
+self.webkitIndexedDB.deleteDatabase() threw an exception: SecurityError
+self.webkitIndexedDB.open() threw an exception: SecurityError
+self.webkitIndexedDB.webkitGetDatabaseNames() threw an exception: SecurityError
+
+
+--------
+Frame: '<!--framePath //<!--frame1-->-->'
+--------
+Successfully called self.webkitIndexedDB.deleteDatabase().
+Successfully called self.webkitIndexedDB.open().
+Successfully called self.webkitIndexedDB.webkitGetDatabaseNames().
+

Added: trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb.html (0 => 141418)


--- trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/cross-origin-worker-indexeddb.html	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+    <script>
+        if (window.testRunner) {
+            testRunner.dumpAsText();
+            testRunner.dumpChildFramesAsText();
+            testRunner.waitUntilDone();
+            testRunner.setCanOpenWindows(true);
+            testRunner.setCloseRemainingWindowsWhenComplete(true);
+            internals.settings.setStorageBlockingPolicy('BlockThirdParty');
+        }
+
+        document.location = "resources/document-for-cross-origin-worker-indexeddb.html"
+    </script>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/resources/cross-origin-iframe-for-indexeddb.html (0 => 141418)


--- trunk/LayoutTests/http/tests/security/resources/cross-origin-iframe-for-indexeddb.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/resources/cross-origin-iframe-for-indexeddb.html	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+    <script>
+        function test(method, args) {
+            try {
+                var request = window.webkitIndexedDB[method].call(window.webkitIndexedDB, args);
+                document.write('Successfully called window.webkitIndexedDB.' + method + '().<br>');
+            } catch (exception) {
+                document.write('window.webkitIndexedDB.' + method + '() threw an exception: ' + exception.name + '<br>');
+            }
+        }
+        test('deleteDatabase', 'testDBName');
+        test('open', 'testDBName');
+        test('webkitGetDatabaseNames');
+    </script>
+</body>
+</head>

Added: trunk/LayoutTests/http/tests/security/resources/cross-origin-iframe-for-worker-indexeddb.html (0 => 141418)


--- trunk/LayoutTests/http/tests/security/resources/cross-origin-iframe-for-worker-indexeddb.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/resources/cross-origin-iframe-for-worker-indexeddb.html	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        window._onload_ = function() {
+            var worker = new Worker('worker-for-indexeddb.js');
+            worker.postMessage(true);
+            worker._onmessage_ = function(event) {
+                for (var i = 0; i < event.data.result.length; i++)
+                    document.write(event.data.result[i]);
+                window.parent.postMessage('DONE', '*');
+            };
+        };
+    </script>
+</head>
+<body>
+</body>
+</head>

Added: trunk/LayoutTests/http/tests/security/resources/document-for-cross-origin-worker-indexeddb.html (0 => 141418)


--- trunk/LayoutTests/http/tests/security/resources/document-for-cross-origin-worker-indexeddb.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/resources/document-for-cross-origin-worker-indexeddb.html	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <script>
+        var frames = 2;
+
+        function decrement() {
+            --frames;
+            if (!frames && window.testRunner) {
+                internals.settings.setStorageBlockingPolicy('AllowAll');
+                testRunner.notifyDone();
+            }
+        }
+
+        window._onmessage_ = decrement;
+    </script>
+</head>
+<body>
+    <p>The first iframe below should return a security error, and the second should successfully open the database.</p>
+    <iframe src=""
+    <iframe src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/resources/worker-for-indexeddb.js (0 => 141418)


--- trunk/LayoutTests/http/tests/security/resources/worker-for-indexeddb.js	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/resources/worker-for-indexeddb.js	2013-01-31 14:57:55 UTC (rev 141418)
@@ -0,0 +1,17 @@
+self._onmessage_ = function() {
+    function test(method, args) {
+        try {
+            var request = self.webkitIndexedDB[method].call(self.webkitIndexedDB, args);
+            return 'Successfully called self.webkitIndexedDB.' + method + '().<br>';
+        } catch (exception) {
+            return 'self.webkitIndexedDB.' + method + '() threw an exception: ' + exception.name + '<br>';
+        }
+    }
+    self.postMessage({
+        'result': [
+            test('deleteDatabase', 'testDBName'),
+            test('open', 'testDBName'),
+            test('webkitGetDatabaseNames')
+        ]
+    });
+};

Modified: trunk/LayoutTests/platform/efl/TestExpectations (141417 => 141418)


--- trunk/LayoutTests/platform/efl/TestExpectations	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/LayoutTests/platform/efl/TestExpectations	2013-01-31 14:57:55 UTC (rev 141418)
@@ -1115,6 +1115,10 @@
 # IndexedDB is not yet enabled.
 Bug(EFL) storage/indexeddb
 Bug(EFL) http/tests/inspector/indexeddb
+Bug(EFL) http/tests/security/cross-origin-indexeddb-allowed.html
+Bug(EFL) http/tests/security/cross-origin-indexeddb.html
+Bug(EFL) http/tests/security/cross-origin-worker-indexeddb-allowed.html
+Bug(EFL) http/tests/security/cross-origin-worker-indexeddb.html
 
 # Quota API is not supported.
 Bug(EFL) storage/storageinfo-missing-arguments.html

Modified: trunk/LayoutTests/platform/mac/TestExpectations (141417 => 141418)


--- trunk/LayoutTests/platform/mac/TestExpectations	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2013-01-31 14:57:55 UTC (rev 141418)
@@ -135,6 +135,10 @@
 # IndexedDB is not yet enabled.
 storage/indexeddb
 http/tests/inspector/indexeddb
+http/tests/security/cross-origin-indexeddb-allowed.html
+http/tests/security/cross-origin-indexeddb.html
+http/tests/security/cross-origin-worker-indexeddb-allowed.html
+http/tests/security/cross-origin-worker-indexeddb.html
 
 # This port doesn't support DeviceMotion or DeviceOrientation.
 fast/dom/DeviceMotion

Modified: trunk/LayoutTests/platform/mac-snowleopard/TestExpectations (141417 => 141418)


--- trunk/LayoutTests/platform/mac-snowleopard/TestExpectations	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/LayoutTests/platform/mac-snowleopard/TestExpectations	2013-01-31 14:57:55 UTC (rev 141418)
@@ -134,6 +134,10 @@
 # IndexedDB is not yet enabled.
 storage/indexeddb
 http/tests/inspector/indexeddb
+http/tests/security/cross-origin-indexeddb-allowed.html
+http/tests/security/cross-origin-indexeddb.html
+http/tests/security/cross-origin-worker-indexeddb-allowed.html
+http/tests/security/cross-origin-worker-indexeddb.html
 
 # Philip's canvas tests that fail on SnowLeopard only
 canvas/philip/tests/2d.gradient.interpolate.overlap.html

Modified: trunk/LayoutTests/platform/qt/TestExpectations (141417 => 141418)


--- trunk/LayoutTests/platform/qt/TestExpectations	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/LayoutTests/platform/qt/TestExpectations	2013-01-31 14:57:55 UTC (rev 141418)
@@ -114,6 +114,10 @@
 # ENABLE(INDEXED_DATABASE) is disabled.
 storage/indexeddb
 http/tests/inspector/indexeddb
+http/tests/security/cross-origin-indexeddb-allowed.html
+http/tests/security/cross-origin-indexeddb.html
+http/tests/security/cross-origin-worker-indexeddb-allowed.html
+http/tests/security/cross-origin-worker-indexeddb.html
 
 inspector/timeline/timeline-animation-frame.html
 

Modified: trunk/LayoutTests/platform/win/TestExpectations (141417 => 141418)


--- trunk/LayoutTests/platform/win/TestExpectations	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/LayoutTests/platform/win/TestExpectations	2013-01-31 14:57:55 UTC (rev 141418)
@@ -1093,6 +1093,10 @@
 # IndexedDB is not yet enabled.
 storage/indexeddb
 http/tests/inspector/indexeddb
+http/tests/security/cross-origin-indexeddb-allowed.html
+http/tests/security/cross-origin-indexeddb.html
+http/tests/security/cross-origin-worker-indexeddb-allowed.html
+http/tests/security/cross-origin-worker-indexeddb.html
 
 # StorageTracker is not enabled.
 storage/domstorage/localstorage/storagetracker

Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (141417 => 141418)


--- trunk/LayoutTests/platform/wincairo/TestExpectations	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations	2013-01-31 14:57:55 UTC (rev 141418)
@@ -1618,6 +1618,10 @@
 # IndexedDB is not yet enabled.
 storage/indexeddb
 http/tests/inspector/indexeddb
+http/tests/security/cross-origin-indexeddb-allowed.html
+http/tests/security/cross-origin-indexeddb.html
+http/tests/security/cross-origin-worker-indexeddb-allowed.html
+http/tests/security/cross-origin-worker-indexeddb.html
 
 # StorageTracker is not enabled.
 storage/domstorage/localstorage/storagetracker

Modified: trunk/Source/WebCore/ChangeLog (141417 => 141418)


--- trunk/Source/WebCore/ChangeLog	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/Source/WebCore/ChangeLog	2013-01-31 14:57:55 UTC (rev 141418)
@@ -1,3 +1,52 @@
+2013-01-31  Mike West  <[email protected]>
+
+        Allow blocking of IndexedDB in third-party contexts
+        https://bugs.webkit.org/show_bug.cgi?id=94171
+
+        Reviewed by Jochen Eisinger.
+
+        This patch ensures that the origin of the top window is passed into
+        SecurityOrigin::canAccessDatabase when working with IndexedDB. Giving
+        SecurityOrigin access to this data means that it can properly check
+        whether the database is being opened in a third-party context, and
+        therefore properly enforce the third-party access checks that were
+        added in http://trac.webkit.org/changeset/125736.
+
+        Third-party checks are added to IDBFactory::open,
+        IDBFactory::deleteDatabase, and IDBFactory::getDatabaseNames; each will
+        now throw a SECURITY_ERR exception when access in a third-party context
+        if third-party access checks are enabled.
+
+        To make this process slightly more clear, and avoid some ugly casting
+        logic, this patch adds a 'topOrigin'  method to ScriptExecutionContext,
+        and implements it on both WorkerContext and Document.
+
+        Tests: http/tests/security/cross-origin-indexeddb-allowed.html
+               http/tests/security/cross-origin-indexeddb.html
+               http/tests/security/cross-origin-worker-indexeddb-allowed.html
+               http/tests/security/cross-origin-worker-indexeddb.html
+
+        * Modules/indexeddb/IDBFactory.cpp:
+        (WebCore::IDBFactory::getDatabaseNames):
+        (WebCore::IDBFactory::openInternal):
+        (WebCore::IDBFactory::deleteDatabase):
+            Grab the SecurityOrigin of the current context's top-level origin,
+            and pass it to SecurityOrigin::canAccessDatabase to ensure that
+            access checks are properly applied to these three methods.
+        * dom/Document.cpp:
+        (WebCore::Document::topOrigin):
+        (WebCore):
+        * dom/Document.h:
+        (Document):
+        * dom/ScriptExecutionContext.h:
+        (ScriptExecutionContext):
+            Add a topOrigin() method to ScriptExecutionContext, and implement it
+            on Document in order to give callers access to the top document's
+            SecurityOrigin without casting ScriptExecutionContext.
+        * workers/WorkerContext.h:
+            Change the existing topOrigin() method to override the new method
+            on ScriptExecutionContext.
+
 2013-01-31  Eugene Klyuchnikov  <[email protected]>
 
         Web Inspector: [Network] Add cookie column to show presence of request/response cookies.

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp (141417 => 141418)


--- trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBFactory.cpp	2013-01-31 14:57:55 UTC (rev 141418)
@@ -95,10 +95,14 @@
 }
 }
 
-PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ScriptExecutionContext* context, ExceptionCode&)
+PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ScriptExecutionContext* context, ExceptionCode& ec)
 {
     if (!isContextValid(context))
         return 0;
+    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) {
+        ec = SECURITY_ERR;
+        return 0;
+    }
 
     RefPtr<IDBRequest> request = IDBRequest::create(context, IDBAny::create(this), 0);
     m_backend->getDatabaseNames(request, context->securityOrigin(), context, getIndexedDBDatabasePath(context));
@@ -125,6 +129,10 @@
     }
     if (!isContextValid(context))
         return 0;
+    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) {
+        ec = SECURITY_ERR;
+        return 0;
+    }
 
     RefPtr<IDBDatabaseCallbacksImpl> databaseCallbacks = IDBDatabaseCallbacksImpl::create();
     int64_t transactionId = IDBDatabase::nextTransactionId();
@@ -146,6 +154,10 @@
     }
     if (!isContextValid(context))
         return 0;
+    if (!context->securityOrigin()->canAccessDatabase(context->topOrigin())) {
+        ec = SECURITY_ERR;
+        return 0;
+    }
 
     RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, IDBDatabaseMetadata::DefaultIntVersion);
     m_backend->deleteDatabase(name, request, context->securityOrigin(), context, getIndexedDBDatabasePath(context));

Modified: trunk/Source/WebCore/dom/Document.cpp (141417 => 141418)


--- trunk/Source/WebCore/dom/Document.cpp	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/Source/WebCore/dom/Document.cpp	2013-01-31 14:57:55 UTC (rev 141418)
@@ -4776,6 +4776,11 @@
     }
 }
 
+const SecurityOrigin* Document::topOrigin() const
+{
+    return topDocument()->securityOrigin();
+}
+
 struct PerformTaskContext {
     WTF_MAKE_NONCOPYABLE(PerformTaskContext); WTF_MAKE_FAST_ALLOCATED;
 public:

Modified: trunk/Source/WebCore/dom/Document.h (141417 => 141418)


--- trunk/Source/WebCore/dom/Document.h	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/Source/WebCore/dom/Document.h	2013-01-31 14:57:55 UTC (rev 141418)
@@ -1199,6 +1199,8 @@
 
     virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0);
 
+    virtual const SecurityOrigin* topOrigin() const OVERRIDE;
+
 protected:
     Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
 

Modified: trunk/Source/WebCore/dom/ScriptExecutionContext.h (141417 => 141418)


--- trunk/Source/WebCore/dom/ScriptExecutionContext.h	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/Source/WebCore/dom/ScriptExecutionContext.h	2013-01-31 14:57:55 UTC (rev 141418)
@@ -89,6 +89,8 @@
     void addConsoleMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, ScriptState* = 0, unsigned long requestIdentifier = 0);
     virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0) = 0;
 
+    virtual const SecurityOrigin* topOrigin() const = 0;
+
 #if ENABLE(BLOB)
     PublicURLManager& publicURLManager();
 #endif

Modified: trunk/Source/WebCore/workers/WorkerContext.h (141417 => 141418)


--- trunk/Source/WebCore/workers/WorkerContext.h	2013-01-31 14:52:58 UTC (rev 141417)
+++ trunk/Source/WebCore/workers/WorkerContext.h	2013-01-31 14:57:55 UTC (rev 141418)
@@ -138,7 +138,7 @@
         void unregisterObserver(Observer*);
         void notifyObserversOfStop();
 
-        const SecurityOrigin* topOrigin() const { return m_topOrigin.get(); }
+        virtual const SecurityOrigin* topOrigin() const OVERRIDE { return m_topOrigin.get(); }
 
     protected:
         WorkerContext(const KURL&, const String& userAgent, PassOwnPtr<GroupSettings>, WorkerThread*, PassRefPtr<SecurityOrigin> topOrigin);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to