Title: [126194] trunk
Revision
126194
Author
[email protected]
Date
2012-08-21 15:23:00 -0700 (Tue, 21 Aug 2012)

Log Message

Blocking a resource via Content Security Policy should trigger an Error event.
https://bugs.webkit.org/show_bug.cgi?id=89440

Patch by Mike West <[email protected]> on 2012-08-21
Reviewed by Jochen Eisinger.

Source/WebCore:

If a CSP directive is violated, CachedResourceLoader will trigger a
console error, and return a null image. In that case, we now dispatch
an error on the relevant element.

Adjusted http/tests/security/contentSecurityPolicy/image-blocked.html
and http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html
to test the new behavior.

This has the side-effect of also generating errors for images blocked by
Chromium's content settings. Adjusted
platform/chromium/permissionclient/image-permissions.html to agree with
the new behavior.

* loader/ImageLoader.cpp:
(WebCore::ImageLoader::updateFromElement):

LayoutTests:

* http/tests/security/contentSecurityPolicy/image-blocked-expected.txt:
* http/tests/security/contentSecurityPolicy/image-blocked.html:
* http/tests/security/contentSecurityPolicy/register-bypassing-scheme-expected.txt:
* http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html:
    Adjusting existing tests to use the error event, as opposed to
    hacking around the fact that it wasn't triggered.
* platform/chromium/permissionclient/image-permissions-expected.txt:
* platform/chromium/permissionclient/image-permissions.html:
    Error events are now also generated for images blocked by Chromium's
    content settings.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (126193 => 126194)


--- trunk/LayoutTests/ChangeLog	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/LayoutTests/ChangeLog	2012-08-21 22:23:00 UTC (rev 126194)
@@ -1,3 +1,21 @@
+2012-08-21  Mike West  <[email protected]>
+
+        Blocking a resource via Content Security Policy should trigger an Error event.
+        https://bugs.webkit.org/show_bug.cgi?id=89440
+
+        Reviewed by Jochen Eisinger.
+
+        * http/tests/security/contentSecurityPolicy/image-blocked-expected.txt:
+        * http/tests/security/contentSecurityPolicy/image-blocked.html:
+        * http/tests/security/contentSecurityPolicy/register-bypassing-scheme-expected.txt:
+        * http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html:
+            Adjusting existing tests to use the error event, as opposed to
+            hacking around the fact that it wasn't triggered.
+        * platform/chromium/permissionclient/image-permissions-expected.txt:
+        * platform/chromium/permissionclient/image-permissions.html:
+            Error events are now also generated for images blocked by Chromium's
+            content settings.
+
 2012-08-21  Sudarsana Nagineni  <[email protected]>
 
         canvas/philip/tests/2d.fillStyle.parse.invalid.rgba-6.html fails

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked-expected.txt (126193 => 126194)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked-expected.txt	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked-expected.txt	2012-08-21 22:23:00 UTC (rev 126194)
@@ -1,3 +1,4 @@
 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'".
 
-This test passes if it doesn't alert fail. 
+ALERT: PASS
+This test passes if it doesn't alert FAIL and does alert PASS. 

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked.html (126193 => 126194)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked.html	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked.html	2012-08-21 22:23:00 UTC (rev 126194)
@@ -8,7 +8,7 @@
 </script>
 </head>
 <body>
-This test passes if it doesn't alert fail.
-<img src="" _onload_="alert('FAIL')">
+This test passes if it doesn't alert FAIL and does alert PASS.
+<img src="" _onload_="alert('FAIL')" _onerror_="alert('PASS')">
 </body>
 </html>

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme-expected.txt (126193 => 126194)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme-expected.txt	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme-expected.txt	2012-08-21 22:23:00 UTC (rev 126194)
@@ -1,6 +1,8 @@
 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 https:".
 
+ALERT: PASS (1/3)
 ALERT: PASS (2/3)
 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 https:".
 
+ALERT: PASS (3/3)
 This test ensures that registering a scheme as bypassing CSP actually bypasses CSP. This test passes if three PASSes are generated.

Modified: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html (126193 => 126194)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html	2012-08-21 22:23:00 UTC (rev 126194)
@@ -10,14 +10,15 @@
 
     function test1() {
         var img = document.createElement('img');
-        img._onload_ = function () { alert('FAIL'); };
-        img._onerror_ = function () { alert('PASS (1/3)'); };
-        try {
-            img.src = ""
-        } catch (e) {
-            alert("PASS (1/3)");
-        }
-        test2();
+        img._onload_ = function () {
+            alert('FAIL (1/3)');
+            test2();
+        };
+        img._onerror_ = function () {
+            alert('PASS (1/3)');
+            test2();
+        };
+        img.src = ""
     }
 
     function test2() {
@@ -27,25 +28,25 @@
             alert('PASS (2/3)');
             test3();
         };
-        try {
-            img.src = ""
-        } catch (e) {
-            alert('FAIL');
+        img._onerror_ = function () {
+            alert('FAIL (2/3)');
             test3();
-        }
+        };
+        img.src = ""
     }
 
     function test3() {
         internals.removeURLSchemeRegisteredAsBypassingContentSecurityPolicy('http');
         var img = document.createElement('img');
-        img._onload_ = function () { alert('FAIL'); };
-        img._onerror_ = function () { alert('PASS (2/3)'); };
-        try {
-            img.src = ""
-        } catch (e) {
-            alert("PASS (3/3)");
-        }
-        finishTesting();
+        img._onload_ = function () {
+            alert('FAIL (3/3)');
+            finishTesting();
+        };
+        img._onerror_ = function () {
+            alert('PASS (3/3)');
+            finishTesting();
+        };
+        img.src = ""
     }
 
     function finishTesting() {

Modified: trunk/LayoutTests/platform/chromium/permissionclient/image-permissions-expected.txt (126193 => 126194)


--- trunk/LayoutTests/platform/chromium/permissionclient/image-permissions-expected.txt	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/LayoutTests/platform/chromium/permissionclient/image-permissions-expected.txt	2012-08-21 22:23:00 UTC (rev 126194)
@@ -5,4 +5,6 @@
 
 
 PASS: first image loaded
+PASS: error event for not cached image
+PASS: error event for image from cache
 

Modified: trunk/LayoutTests/platform/chromium/permissionclient/image-permissions.html (126193 => 126194)


--- trunk/LayoutTests/platform/chromium/permissionclient/image-permissions.html	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/LayoutTests/platform/chromium/permissionclient/image-permissions.html	2012-08-21 22:23:00 UTC (rev 126194)
@@ -21,14 +21,14 @@
 
     // Load an image not in cache.
     var img = document.createElement('img');
-    img._onerror_ = function () { log("FAIL: error event for not cached image"); }
+    img._onerror_ = function () { log("PASS: error event for not cached image"); }
     img._onload_ = function () { log("FAIL: not cached image loaded"); }
     img.src = ""
     document.getElementById("img").appendChild(img);
 
     // Load an image from cache.
     var imgFromCache = document.createElement('img');
-    imgFromCache._onerror_ = function () { log("FAIL: error event for image from cache"); }
+    imgFromCache._onerror_ = function () { log("PASS: error event for image from cache"); }
     imgFromCache._onload_ = function () { log("FAIL: image from cache loaded"); }
     imgFromCache.src = ""
     document.getElementById("img").appendChild(imgFromCache);

Modified: trunk/Source/WebCore/ChangeLog (126193 => 126194)


--- trunk/Source/WebCore/ChangeLog	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/Source/WebCore/ChangeLog	2012-08-21 22:23:00 UTC (rev 126194)
@@ -1,3 +1,26 @@
+2012-08-21  Mike West  <[email protected]>
+
+        Blocking a resource via Content Security Policy should trigger an Error event.
+        https://bugs.webkit.org/show_bug.cgi?id=89440
+
+        Reviewed by Jochen Eisinger.
+
+        If a CSP directive is violated, CachedResourceLoader will trigger a
+        console error, and return a null image. In that case, we now dispatch
+        an error on the relevant element.
+
+        Adjusted http/tests/security/contentSecurityPolicy/image-blocked.html
+        and http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html
+        to test the new behavior.
+
+        This has the side-effect of also generating errors for images blocked by
+        Chromium's content settings. Adjusted
+        platform/chromium/permissionclient/image-permissions.html to agree with
+        the new behavior.
+
+        * loader/ImageLoader.cpp:
+        (WebCore::ImageLoader::updateFromElement):
+
 2012-08-21  Taiju Tsuiki  <[email protected]>
 
         Web Inspector: Split out crumb list part of styles from elementsPanel.css

Modified: trunk/Source/WebCore/loader/ImageLoader.cpp (126193 => 126194)


--- trunk/Source/WebCore/loader/ImageLoader.cpp	2012-08-21 22:05:33 UTC (rev 126193)
+++ trunk/Source/WebCore/loader/ImageLoader.cpp	2012-08-21 22:23:00 UTC (rev 126194)
@@ -197,8 +197,14 @@
             newImage = document()->cachedResourceLoader()->requestImage(request);
 
         // If we do not have an image here, it means that a cross-site
-        // violation occurred.
-        m_failedLoadURL = !newImage ? attr : AtomicString();
+        // violation occurred, or that the image was blocked via Content
+        // Security Policy. Either way, trigger an error event.
+        if (!newImage) {
+            m_failedLoadURL = attr;
+            m_hasPendingErrorEvent = true;
+            errorEventSender().dispatchEventSoon(this);
+        } else
+            m_failedLoadURL = AtomicString();
     } else if (!attr.isNull()) {
         // Fire an error event if the url is empty.
         // FIXME: Should we fire this event asynchronoulsy via errorEventSender()?
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to