Title: [133006] trunk
Revision
133006
Author
[email protected]
Date
2012-10-31 02:59:45 -0700 (Wed, 31 Oct 2012)

Log Message

Script run from an isolated world should bypass a page's CSP.
https://bugs.webkit.org/show_bug.cgi?id=97398

Reviewed by Adam Barth.

Source/WebCore:

A page's Content Security Policy currently applies to all resources
loaded, regardless of their source. That generally makes sense, but
proves problematic when considering script run from an isolated
world (Chrome extensions, for instance). These scripts should be allowed
to inject resources into a page's DOM without eiher being restricted by
the page's active CSP, or generating violation reports that spam the
page owner.

Ideally, the isolated world could define its own Content Security Policy
which should be applied to resources it loads. For the moment, this
patch accepts a String that we can parse later on, but only uses it in
a binary way. If a non-empty policy String is provided, we bypass the
main world's CSP checks. If an empty String is provided, the main
world's CSP checks remain active.

Test: http/tests/security/isolatedWorld/bypass-main-world-csp.html

(WebCore::isolatedWorldContentSecurityPolicies):
(WebCore::DOMWrapperWorld::isolatedWorldHasContentSecurityPolicy):
(WebCore::DOMWrapperWorld::setIsolatedWorldContentSecurityPolicy):
(WebCore::DOMWrapperWorld::clearIsolatedWorldContentSecurityPolicy):
* bindings/v8/DOMWrapperWorld.h:
(DOMWrapperWorld):
    Mechanisms for setting and clearing Content Security Policies from
    isolated worlds; implemented in the same HashMappy way as
    SecurityOrigin.
* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::shouldBypassMainWorldContentSecurityPolicy):
(WebCore):
* bindings/v8/ScriptController.h:
(ScriptController):
    Adding a method to ScriptController to query the state of the
    current world's Content Security Policy. We'll drop this once we can
    apply a policy more directly, but for the moment it's necessary for
    the next bit.
* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::canRequest):
    Check the new ScriptController method, and only perform CSP checks
    when loading resources if we're executing code from the main world,
    or an isolated world with no Content Security Policy set.

Source/WebKit/chromium:

* public/WebFrame.h:
(WebFrame):
* src/WebFrameImpl.cpp:
(WebKit::WebFrameImpl::setIsolatedWorldSecurityOrigin):
(WebKit):
(WebKit::WebFrameImpl::setIsolatedWorldContentSecurityPolicy):
* src/WebFrameImpl.h:
(WebFrameImpl):
    Piping a Content Security Policy through WebFrame, in the same way
    we're currently doing for SecurityOrigin. As a drive-by, this also
    uses the static method on DOMWrapperWindow to set the security
    origin, rather than routing through the frame's ScriptController.

Tools:

* DumpRenderTree/chromium/DRTTestRunner.cpp:
(DRTTestRunner::DRTTestRunner):
(DRTTestRunner::setIsolatedWorldContentSecurityPolicy):
* DumpRenderTree/chromium/DRTTestRunner.h:
(DRTTestRunner):
    Adding a mechanism to set the Content Security Policy for an
    isolated world to Chromium's testRunner.

LayoutTests:

* http/tests/security/isolatedWorld/bypass-main-world-csp-expected.txt: Added.
* http/tests/security/isolatedWorld/bypass-main-world-csp.html: Added.
* platform/efl/TestExpectations:
* platform/mac/TestExpectations:
* platform/qt/TestExpectations:
* platform/win/TestExpectations:
    Skip the new tests on ports that don't support the new functionality

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (133005 => 133006)


--- trunk/LayoutTests/ChangeLog	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/LayoutTests/ChangeLog	2012-10-31 09:59:45 UTC (rev 133006)
@@ -1,3 +1,18 @@
+2012-10-31  Mike West  <[email protected]>
+
+        Script run from an isolated world should bypass a page's CSP.
+        https://bugs.webkit.org/show_bug.cgi?id=97398
+
+        Reviewed by Adam Barth.
+
+        * http/tests/security/isolatedWorld/bypass-main-world-csp-expected.txt: Added.
+        * http/tests/security/isolatedWorld/bypass-main-world-csp.html: Added.
+        * platform/efl/TestExpectations:
+        * platform/mac/TestExpectations:
+        * platform/qt/TestExpectations:
+        * platform/win/TestExpectations:
+            Skip the new tests on ports that don't support the new functionality
+
 2012-10-31  Pavel Podivilov  <[email protected]>
 
         [chromium] Rebaseline media/video-zoom.html.

Added: trunk/LayoutTests/http/tests/security/isolatedWorld/bypass-main-world-csp-expected.txt (0 => 133006)


--- trunk/LayoutTests/http/tests/security/isolatedWorld/bypass-main-world-csp-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/isolatedWorld/bypass-main-world-csp-expected.txt	2012-10-31 09:59:45 UTC (rev 133006)
@@ -0,0 +1,14 @@
+CONSOLE MESSAGE: Refused to load the image 'http://127.0.0.1:8000/security/resources/abe.png' because it violates the following Content Security Policy directive: "img-src 'none'".
+
+ALERT: BLOCKED in main world
+CONSOLE MESSAGE: Refused to load the image 'http://127.0.0.1:8000/security/resources/abe.png' because it violates the following Content Security Policy directive: "img-src 'none'".
+
+ALERT: BLOCKED in isolated world
+ALERT: Starting to bypass main world's CSP:
+ALERT: LOADED in isolated world
+CONSOLE MESSAGE: Refused to load the image 'http://127.0.0.1:8000/security/resources/abe.png' because it violates the following Content Security Policy directive: "img-src 'none'".
+
+ALERT: BLOCKED in main world
+This test ensures that scripts run in isolated worlds marked with their own Content Security Policy aren't affected by the page's content security policy. Extensions, for example, should be able to load any resource they like.
+
+

Added: trunk/LayoutTests/http/tests/security/isolatedWorld/bypass-main-world-csp.html (0 => 133006)


--- trunk/LayoutTests/http/tests/security/isolatedWorld/bypass-main-world-csp.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/isolatedWorld/bypass-main-world-csp.html	2012-10-31 09:59:45 UTC (rev 133006)
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="X-WebKit-CSP" content="img-src 'none'">
+<script>
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+    }
+
+    tests = 4;
+    window.addEventListener("message", function(message) {
+        tests -= 1;
+        test();
+    }, false);
+
+    function test() {
+        function setImgSrc(isolated) {
+            var img = document.createElement('img');
+            document.body.appendChild(img);
+            img._onload_ = function () {
+                alert('LOADED in ' + (isolated ? "isolated world" : "main world"));
+                window.postMessage("next", "*");
+            };
+            img._onerror_ = function () {
+                alert('BLOCKED in ' + (isolated ? "isolated world" : "main world"));
+                window.postMessage("next", "*");
+            };
+            img.src = ""
+        }
+
+        switch (tests) {
+            case 4:
+                setImgSrc(false);
+                break;
+            case 3:
+                testRunner.evaluateScriptInIsolatedWorld(1, String(eval("setImgSrc")) + "\nsetImgSrc(true);");
+                break;
+            case 2:
+                alert("Starting to bypass main world's CSP:");
+                testRunner.setIsolatedWorldContentSecurityPolicy(1, 'img-src *');
+                testRunner.evaluateScriptInIsolatedWorld(1, String(eval("setImgSrc")) + "\nsetImgSrc(true);");
+                break;
+            case 1:
+                setImgSrc(false);
+                break;
+            case 0:
+                testRunner.setIsolatedWorldContentSecurityPolicy(1, '');
+                testRunner.notifyDone();
+                break;
+        }
+    }
+</script>
+</head>
+<body _onload_='test();'>
+    <p>
+        This test ensures that scripts run in isolated worlds marked with their
+        own Content Security Policy aren't affected by the page's content
+        security policy. Extensions, for example, should be able to load any
+        resource they like.
+    </p>
+</body>
+</html>

Modified: trunk/LayoutTests/platform/efl/TestExpectations (133005 => 133006)


--- trunk/LayoutTests/platform/efl/TestExpectations	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/LayoutTests/platform/efl/TestExpectations	2012-10-31 09:59:45 UTC (rev 133006)
@@ -1022,6 +1022,9 @@
 webkit.org/b/61540 inspector/extensions/extensions-audits-content-script.html [ Failure ]
 webkit.org/b/61540 inspector/extensions/extensions-eval-content-script.html [ Failure ]
 
+# JSC also doesn't support setIsolatedWorldContentSecurityPolicy
+webkit.org/b/100815 http/tests/security/isolatedWorld/bypass-main-world-csp.html [ Failure ]
+
 #__worldID is undefined in isolated world
 Bug(EFL) http/tests/security/isolatedWorld/didClearWindowObject.html
 

Modified: trunk/LayoutTests/platform/mac/TestExpectations (133005 => 133006)


--- trunk/LayoutTests/platform/mac/TestExpectations	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2012-10-31 09:59:45 UTC (rev 133006)
@@ -428,6 +428,9 @@
 # JSC does not support setIsolatedWorldSecurityOrigin (http://webkit.org/b/61540)
 http/tests/security/isolatedWorld/cross-origin-xhr.html
 
+# JSC also doesn't support setIsolatedWorldContentSecurityPolicy (webkit.org/b/100815)
+http/tests/security/isolatedWorld/bypass-main-world-csp.html
+
 # https://bugs.webkit.org/show_bug.cgi?id=63282 layerTreeAsText doesn't work for iframes
 compositing/rtl/rtl-iframe-absolute-overflow-scrolled.html
 compositing/rtl/rtl-iframe-absolute-overflow.html

Modified: trunk/LayoutTests/platform/qt/TestExpectations (133005 => 133006)


--- trunk/LayoutTests/platform/qt/TestExpectations	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/LayoutTests/platform/qt/TestExpectations	2012-10-31 09:59:45 UTC (rev 133006)
@@ -340,6 +340,9 @@
 # JSC does not support setIsolatedWorldSecurityOrigin, (http://webkit.org/b/61540)
 http/tests/security/isolatedWorld/cross-origin-xhr.html
 
+# JSC also doesn't support setIsolatedWorldContentSecurityPolicy (webkit.org/b/100815)
+http/tests/security/isolatedWorld/bypass-main-world-csp.html
+
 # This test is for clients that choose to make the missing plugin indicator a button
 plugins/clicking-missing-plugin-fires-delegate.html
 

Modified: trunk/LayoutTests/platform/win/TestExpectations (133005 => 133006)


--- trunk/LayoutTests/platform/win/TestExpectations	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/LayoutTests/platform/win/TestExpectations	2012-10-31 09:59:45 UTC (rev 133006)
@@ -1482,6 +1482,9 @@
 # JSC does not support setIsolatedWorldSecurityOrigin (http://webkit.org/b/61540)
 http/tests/security/isolatedWorld/cross-origin-xhr.html
 
+# JSC also doesn't support setIsolatedWorldContentSecurityPolicy (webkit.org/b/100815)
+http/tests/security/isolatedWorld/bypass-main-world-csp.html
+
 # ENABLE(WEBGL) is disabled
 compositing/backface-visibility/backface-visibility-webgl.html
 compositing/visibility/visibility-simple-webgl-layer.html

Modified: trunk/Source/WebCore/ChangeLog (133005 => 133006)


--- trunk/Source/WebCore/ChangeLog	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebCore/ChangeLog	2012-10-31 09:59:45 UTC (rev 133006)
@@ -1,3 +1,51 @@
+2012-10-31  Mike West  <[email protected]>
+
+        Script run from an isolated world should bypass a page's CSP.
+        https://bugs.webkit.org/show_bug.cgi?id=97398
+
+        Reviewed by Adam Barth.
+
+        A page's Content Security Policy currently applies to all resources
+        loaded, regardless of their source. That generally makes sense, but
+        proves problematic when considering script run from an isolated
+        world (Chrome extensions, for instance). These scripts should be allowed
+        to inject resources into a page's DOM without eiher being restricted by
+        the page's active CSP, or generating violation reports that spam the
+        page owner.
+
+        Ideally, the isolated world could define its own Content Security Policy
+        which should be applied to resources it loads. For the moment, this
+        patch accepts a String that we can parse later on, but only uses it in
+        a binary way. If a non-empty policy String is provided, we bypass the
+        main world's CSP checks. If an empty String is provided, the main
+        world's CSP checks remain active.
+
+        Test: http/tests/security/isolatedWorld/bypass-main-world-csp.html
+
+        (WebCore::isolatedWorldContentSecurityPolicies):
+        (WebCore::DOMWrapperWorld::isolatedWorldHasContentSecurityPolicy):
+        (WebCore::DOMWrapperWorld::setIsolatedWorldContentSecurityPolicy):
+        (WebCore::DOMWrapperWorld::clearIsolatedWorldContentSecurityPolicy):
+        * bindings/v8/DOMWrapperWorld.h:
+        (DOMWrapperWorld):
+            Mechanisms for setting and clearing Content Security Policies from
+            isolated worlds; implemented in the same HashMappy way as
+            SecurityOrigin.
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::shouldBypassMainWorldContentSecurityPolicy):
+        (WebCore):
+        * bindings/v8/ScriptController.h:
+        (ScriptController):
+            Adding a method to ScriptController to query the state of the
+            current world's Content Security Policy. We'll drop this once we can
+            apply a policy more directly, but for the moment it's necessary for
+            the next bit.
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::canRequest):
+            Check the new ScriptController method, and only perform CSP checks
+            when loading resources if we're executing code from the main world,
+            or an isolated world with no Content Security Policy set.
+
 2012-10-31  Tim Horton  <[email protected]>
 
         Unreviewed, attempt to fix the release build by not exporting symbols that aren't defined there.

Modified: trunk/Source/WebCore/bindings/js/ScriptController.h (133005 => 133006)


--- trunk/Source/WebCore/bindings/js/ScriptController.h	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebCore/bindings/js/ScriptController.h	2012-10-31 09:59:45 UTC (rev 133006)
@@ -160,6 +160,9 @@
     NPObject* windowScriptNPObject();
 #endif
 
+    // FIXME: Stub for parity with V8 implementation. http://webkit.org/b/100815
+    bool shouldBypassMainWorldContentSecurityPolicy() { return false; }
+
 private:
     JSDOMWindowShell* initScript(DOMWrapperWorld* world);
 

Modified: trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp (133005 => 133006)


--- trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp	2012-10-31 09:59:45 UTC (rev 133006)
@@ -143,4 +143,35 @@
     isolatedWorldSecurityOrigins().remove(worldID);
 }
 
+typedef HashMap<int, bool> IsolatedWorldContentSecurityPolicyMap;
+static IsolatedWorldContentSecurityPolicyMap& isolatedWorldContentSecurityPolicies()
+{
+    ASSERT(isMainThread());
+    DEFINE_STATIC_LOCAL(IsolatedWorldContentSecurityPolicyMap, map, ());
+    return map;
+}
+
+bool DOMWrapperWorld::isolatedWorldHasContentSecurityPolicy()
+{
+    ASSERT(this->isIsolatedWorld());
+    IsolatedWorldContentSecurityPolicyMap& policies = isolatedWorldContentSecurityPolicies();
+    IsolatedWorldContentSecurityPolicyMap::iterator it = policies.find(worldId());
+    return it == policies.end() ? false : it->value;
+}
+
+void DOMWrapperWorld::setIsolatedWorldContentSecurityPolicy(int worldID, const String& policy)
+{
+    ASSERT(DOMWrapperWorld::isIsolatedWorldId(worldID));
+    if (!policy.isEmpty())
+        isolatedWorldContentSecurityPolicies().set(worldID, true);
+    else
+        isolatedWorldContentSecurityPolicies().remove(worldID);
+}
+
+void DOMWrapperWorld::clearIsolatedWorldContentSecurityPolicy(int worldID)
+{
+    ASSERT(DOMWrapperWorld::isIsolatedWorldId(worldID));
+    isolatedWorldContentSecurityPolicies().remove(worldID);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h (133005 => 133006)


--- trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h	2012-10-31 09:59:45 UTC (rev 133006)
@@ -37,6 +37,7 @@
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -57,6 +58,19 @@
     static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin>);
     static void clearIsolatedWorldSecurityOrigin(int worldID);
     SecurityOrigin* isolatedWorldSecurityOrigin();
+
+    // Associated an isolated world with a Content Security Policy. Resources
+    // embedded into the main world's DOM from script executed in an isolated
+    // world should be restricted based on the isolated world's DOM, not the
+    // main world's.
+    //
+    // FIXME: Right now, resource injection simply bypasses the main world's
+    // DOM. More work is necessary to allow the isolated world's policy to be
+    // applied correctly.
+    static void setIsolatedWorldContentSecurityPolicy(int worldID, const String& policy);
+    static void clearIsolatedWorldContentSecurityPolicy(int worldID);
+    bool isolatedWorldHasContentSecurityPolicy();
+
     // FIXME: this is a workaround for a problem in WebViewImpl.
     // Do not use this anywhere else!!
     static PassRefPtr<DOMWrapperWorld> createUninitializedWorld();

Modified: trunk/Source/WebCore/bindings/v8/ScriptController.cpp (133005 => 133006)


--- trunk/Source/WebCore/bindings/v8/ScriptController.cpp	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.cpp	2012-10-31 09:59:45 UTC (rev 133006)
@@ -396,6 +396,13 @@
     }
 }
 
+bool ScriptController::shouldBypassMainWorldContentSecurityPolicy()
+{
+    if (V8DOMWindowShell* isolatedWorldShell = V8DOMWindowShell::getEntered())
+        return isolatedWorldShell->world()->isolatedWorldHasContentSecurityPolicy();
+    return false;
+}
+
 TextPosition ScriptController::eventHandlerPosition() const
 {
     ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();

Modified: trunk/Source/WebCore/bindings/v8/ScriptController.h (133005 => 133006)


--- trunk/Source/WebCore/bindings/v8/ScriptController.h	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.h	2012-10-31 09:59:45 UTC (rev 133006)
@@ -107,6 +107,11 @@
     // FIXME: Get rid of extensionGroup here.
     void evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results);
 
+    // Returns true if the current world is isolated, and has its own Content
+    // Security Policy. In this case, the policy of the main world should be
+    // ignored when evaluating resources injected into the DOM.
+    bool shouldBypassMainWorldContentSecurityPolicy();
+
     // FIXME: Remove references to this call in chromium and delete it.
     inline static void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin> origin)
     {

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (133005 => 133006)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2012-10-31 09:59:45 UTC (rev 133006)
@@ -301,7 +301,7 @@
 {
     if (document() && !document()->securityOrigin()->canDisplay(url)) {
         if (!forPreload)
-            FrameLoader::reportLocalLoadFailed(document()->frame(), url.string());
+            FrameLoader::reportLocalLoadFailed(frame(), url.string());
         LOG(ResourceLoading, "CachedResourceLoader::requestResource URL was not allowed by SecurityOrigin::canDisplay");
         return 0;
     }
@@ -311,6 +311,8 @@
         return false;
 #endif
 
+    bool shouldBypassMainWorldContentSecurityPolicy = (frame() && frame()->script()->shouldBypassMainWorldContentSecurityPolicy());
+
     // Some types of resources can be loaded only from the same origin.  Other
     // types of resources, like Images, Scripts, and CSS, can be loaded from
     // any URL.
@@ -352,7 +354,7 @@
     case CachedResource::XSLStyleSheet:
 #endif
     case CachedResource::Script:
-        if (!m_document->contentSecurityPolicy()->allowScriptFromSource(url))
+        if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentSecurityPolicy()->allowScriptFromSource(url))
             return false;
 
         if (frame()) {
@@ -368,18 +370,18 @@
         // Since shaders are referenced from CSS Styles use the same rules here.
 #endif
     case CachedResource::CSSStyleSheet:
-        if (!m_document->contentSecurityPolicy()->allowStyleFromSource(url))
+        if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentSecurityPolicy()->allowStyleFromSource(url))
             return false;
         break;
 #if ENABLE(SVG)
     case CachedResource::SVGDocumentResource:
 #endif
     case CachedResource::ImageResource:
-        if (!m_document->contentSecurityPolicy()->allowImageFromSource(url))
+        if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentSecurityPolicy()->allowImageFromSource(url))
             return false;
         break;
     case CachedResource::FontResource: {
-        if (!m_document->contentSecurityPolicy()->allowFontFromSource(url))
+        if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentSecurityPolicy()->allowFontFromSource(url))
             return false;
         break;
     }
@@ -394,7 +396,7 @@
     case CachedResource::TextTrackResource:
         // Cues aren't called out in the CPS spec yet, but they only work with a media element
         // so use the media policy.
-        if (!m_document->contentSecurityPolicy()->allowMediaFromSource(url))
+        if (!shouldBypassMainWorldContentSecurityPolicy && !m_document->contentSecurityPolicy()->allowMediaFromSource(url))
             return false;
         break;
 #endif

Modified: trunk/Source/WebKit/chromium/ChangeLog (133005 => 133006)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-10-31 09:59:45 UTC (rev 133006)
@@ -1,3 +1,23 @@
+2012-10-31  Mike West  <[email protected]>
+
+        Script run from an isolated world should bypass a page's CSP.
+        https://bugs.webkit.org/show_bug.cgi?id=97398
+
+        Reviewed by Adam Barth.
+
+        * public/WebFrame.h:
+        (WebFrame):
+        * src/WebFrameImpl.cpp:
+        (WebKit::WebFrameImpl::setIsolatedWorldSecurityOrigin):
+        (WebKit):
+        (WebKit::WebFrameImpl::setIsolatedWorldContentSecurityPolicy):
+        * src/WebFrameImpl.h:
+        (WebFrameImpl):
+            Piping a Content Security Policy through WebFrame, in the same way
+            we're currently doing for SecurityOrigin. As a drive-by, this also
+            uses the static method on DOMWrapperWindow to set the security
+            origin, rather than routing through the frame's ScriptController.
+
 2012-10-30  W. James MacLean  <[email protected]>
 
         [chromium] Transform mouse/gesture event coordinates to account for pinch-zoom in compositor.

Modified: trunk/Source/WebKit/chromium/public/WebFrame.h (133005 => 133006)


--- trunk/Source/WebKit/chromium/public/WebFrame.h	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebKit/chromium/public/WebFrame.h	2012-10-31 09:59:45 UTC (rev 133006)
@@ -252,6 +252,16 @@
     virtual void setIsolatedWorldSecurityOrigin(
         int worldID, const WebSecurityOrigin&) = 0;
 
+    // Associates a content security policy with an isolated world. This policy
+    // should be used when evaluating script in the isolated world, and should
+    // also replace a protected resource's CSP when evaluating resources
+    // injected into the DOM.
+    //
+    // FIXME: Setting this simply bypasses the protected resource's CSP. It
+    //     doesn't yet restrict the isolated world to the provided policy.
+    virtual void setIsolatedWorldContentSecurityPolicy(
+        int worldID, const WebString&) = 0;
+
     // Logs to the console associated with this frame.
     virtual void addMessageToConsole(const WebConsoleMessage&) = 0;
 

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp (133005 => 133006)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp	2012-10-31 09:59:45 UTC (rev 133006)
@@ -82,6 +82,7 @@
 #include "DOMUtilitiesPrivate.h"
 #include "DOMWindow.h"
 #include "DOMWindowIntents.h"
+#include "DOMWrapperWorld.h"
 #include "DeliveredIntent.h"
 #include "DeliveredIntentClientImpl.h"
 #include "DirectoryEntry.h"
@@ -826,9 +827,15 @@
 void WebFrameImpl::setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin& securityOrigin)
 {
     ASSERT(frame());
-    frame()->script()->setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get());
+    DOMWrapperWorld::setIsolatedWorldSecurityOrigin(worldID, securityOrigin.get());
 }
 
+void WebFrameImpl::setIsolatedWorldContentSecurityPolicy(int worldID, const WebString& policy)
+{
+    ASSERT(frame());
+    DOMWrapperWorld::setIsolatedWorldContentSecurityPolicy(worldID, policy);
+}
+
 void WebFrameImpl::addMessageToConsole(const WebConsoleMessage& message)
 {
     ASSERT(frame());

Modified: trunk/Source/WebKit/chromium/src/WebFrameImpl.h (133005 => 133006)


--- trunk/Source/WebKit/chromium/src/WebFrameImpl.h	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Source/WebKit/chromium/src/WebFrameImpl.h	2012-10-31 09:59:45 UTC (rev 133006)
@@ -114,6 +114,7 @@
         int worldID, const WebScriptSource* sources, unsigned numSources,
         int extensionGroup);
     virtual void setIsolatedWorldSecurityOrigin(int worldID, const WebSecurityOrigin&);
+    virtual void setIsolatedWorldContentSecurityPolicy(int worldID, const WebString&);
     virtual void addMessageToConsole(const WebConsoleMessage&);
     virtual void collectGarbage();
     virtual bool checkIfRunInsecureContent(const WebURL&) const;

Modified: trunk/Tools/ChangeLog (133005 => 133006)


--- trunk/Tools/ChangeLog	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Tools/ChangeLog	2012-10-31 09:59:45 UTC (rev 133006)
@@ -1,3 +1,18 @@
+2012-10-31  Mike West  <[email protected]>
+
+        Script run from an isolated world should bypass a page's CSP.
+        https://bugs.webkit.org/show_bug.cgi?id=97398
+
+        Reviewed by Adam Barth.
+
+        * DumpRenderTree/chromium/DRTTestRunner.cpp:
+        (DRTTestRunner::DRTTestRunner):
+        (DRTTestRunner::setIsolatedWorldContentSecurityPolicy):
+        * DumpRenderTree/chromium/DRTTestRunner.h:
+        (DRTTestRunner):
+            Adding a mechanism to set the Content Security Policy for an
+            isolated world to Chromium's testRunner.
+
 2012-10-31  Michał Pakuła vel Rutka  <[email protected]>
 
         [EFL][DRT] EventSender requires contextClick implementation

Modified: trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp (133005 => 133006)


--- trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.cpp	2012-10-31 09:59:45 UTC (rev 133006)
@@ -157,6 +157,7 @@
     bindMethod("evaluateScriptInIsolatedWorld", &DRTTestRunner::evaluateScriptInIsolatedWorld);
     bindMethod("evaluateScriptInIsolatedWorldAndReturnValue", &DRTTestRunner::evaluateScriptInIsolatedWorldAndReturnValue);
     bindMethod("setIsolatedWorldSecurityOrigin", &DRTTestRunner::setIsolatedWorldSecurityOrigin);
+    bindMethod("setIsolatedWorldContentSecurityPolicy", &DRTTestRunner::setIsolatedWorldContentSecurityPolicy);
     bindMethod("execCommand", &DRTTestRunner::execCommand);
     bindMethod("forceRedSelectionColors", &DRTTestRunner::forceRedSelectionColors);
 #if ENABLE(NOTIFICATIONS)
@@ -1403,6 +1404,16 @@
     m_shell->webView()->focusedFrame()->setIsolatedWorldSecurityOrigin(arguments[0].toInt32(), origin);
 }
 
+void DRTTestRunner::setIsolatedWorldContentSecurityPolicy(const CppArgumentList& arguments, CppVariant* result)
+{
+    result->setNull();
+
+    if (arguments.size() != 2 || !arguments[0].isNumber() || !arguments[1].isString())
+        return;
+
+    m_shell->webView()->focusedFrame()->setIsolatedWorldContentSecurityPolicy(arguments[0].toInt32(), cppVariantToWebString(arguments[1]));
+}
+
 void DRTTestRunner::setAllowUniversalAccessFromFileURLs(const CppArgumentList& arguments, CppVariant* result)
 {
     if (arguments.size() > 0 && arguments[0].isBool()) {

Modified: trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.h (133005 => 133006)


--- trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.h	2012-10-31 09:48:16 UTC (rev 133005)
+++ trunk/Tools/DumpRenderTree/chromium/DRTTestRunner.h	2012-10-31 09:59:45 UTC (rev 133006)
@@ -297,6 +297,7 @@
     void evaluateScriptInIsolatedWorldAndReturnValue(const CppArgumentList&, CppVariant*);
     void evaluateScriptInIsolatedWorld(const CppArgumentList&, CppVariant*);
     void setIsolatedWorldSecurityOrigin(const CppArgumentList&, CppVariant*);
+    void setIsolatedWorldContentSecurityPolicy(const CppArgumentList&, CppVariant*);
 
     // The fallback method is called when a nonexistent method is called on
     // the layout test controller object.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to