Changeset 126194 in webkit


Ignore:
Timestamp:
Aug 21, 2012 3:23:00 PM (12 years ago)
Author:
commit-queue@webkit.org
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 <mkwst@chromium.org> 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.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r126192 r126194  
     12012-08-21  Mike West  <mkwst@chromium.org>
     2
     3        Blocking a resource via Content Security Policy should trigger an Error event.
     4        https://bugs.webkit.org/show_bug.cgi?id=89440
     5
     6        Reviewed by Jochen Eisinger.
     7
     8        * http/tests/security/contentSecurityPolicy/image-blocked-expected.txt:
     9        * http/tests/security/contentSecurityPolicy/image-blocked.html:
     10        * http/tests/security/contentSecurityPolicy/register-bypassing-scheme-expected.txt:
     11        * http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html:
     12            Adjusting existing tests to use the error event, as opposed to
     13            hacking around the fact that it wasn't triggered.
     14        * platform/chromium/permissionclient/image-permissions-expected.txt:
     15        * platform/chromium/permissionclient/image-permissions.html:
     16            Error events are now also generated for images blocked by Chromium's
     17            content settings.
     18
    1192012-08-21  Sudarsana Nagineni  <sudarsana.nagineni@linux.intel.com>
    220
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked-expected.txt

    r117006 r126194  
    11CONSOLE 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'".
    22
    3 This test passes if it doesn't alert fail.
     3ALERT: PASS
     4This test passes if it doesn't alert FAIL and does alert PASS.
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/image-blocked.html

    r120174 r126194  
    99</head>
    1010<body>
    11 This test passes if it doesn't alert fail.
    12 <img src="../resources/abe.png" onload="alert('FAIL')">
     11This test passes if it doesn't alert FAIL and does alert PASS.
     12<img src="../resources/abe.png" onload="alert('FAIL')" onerror="alert('PASS')">
    1313</body>
    1414</html>
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme-expected.txt

    r120684 r126194  
    11CONSOLE 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:".
    22
     3ALERT: PASS (1/3)
    34ALERT: PASS (2/3)
    45CONSOLE 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:".
    56
     7ALERT: PASS (3/3)
    68This test ensures that registering a scheme as bypassing CSP actually bypasses CSP. This test passes if three PASSes are generated.
  • trunk/LayoutTests/http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html

    r120684 r126194  
    1111    function test1() {
    1212        var img = document.createElement('img');
    13         img.onload = function () { alert('FAIL'); };
    14         img.onerror = function () { alert('PASS (1/3)'); };
    15         try {
    16             img.src = "../resources/abe.png";
    17         } catch (e) {
    18             alert("PASS (1/3)");
    19         }
    20         test2();
     13        img.onload = function () {
     14            alert('FAIL (1/3)');
     15            test2();
     16        };
     17        img.onerror = function () {
     18            alert('PASS (1/3)');
     19            test2();
     20        };
     21        img.src = "../resources/abe.png";
    2122    }
    2223
     
    2829            test3();
    2930        };
    30         try {
    31             img.src = "../resources/abe.png";
    32         } catch (e) {
    33             alert('FAIL');
     31        img.onerror = function () {
     32            alert('FAIL (2/3)');
    3433            test3();
    35         }
     34        };
     35        img.src = "../resources/abe.png";
    3636    }
    3737
     
    3939        internals.removeURLSchemeRegisteredAsBypassingContentSecurityPolicy('http');
    4040        var img = document.createElement('img');
    41         img.onload = function () { alert('FAIL'); };
    42         img.onerror = function () { alert('PASS (2/3)'); };
    43         try {
    44             img.src = "../resources/abe.png";
    45         } catch (e) {
    46             alert("PASS (3/3)");
    47         }
    48         finishTesting();
     41        img.onload = function () {
     42            alert('FAIL (3/3)');
     43            finishTesting();
     44        };
     45        img.onerror = function () {
     46            alert('PASS (3/3)');
     47            finishTesting();
     48        };
     49        img.src = "../resources/abe.png";
    4950    }
    5051
  • trunk/LayoutTests/platform/chromium/permissionclient/image-permissions-expected.txt

    r95369 r126194  
    66
    77PASS: first image loaded
     8PASS: error event for not cached image
     9PASS: error event for image from cache
    810
  • trunk/LayoutTests/platform/chromium/permissionclient/image-permissions.html

    r124692 r126194  
    2222    // Load an image not in cache.
    2323    var img = document.createElement('img');
    24     img.onerror = function () { log("FAIL: error event for not cached image"); }
     24    img.onerror = function () { log("PASS: error event for not cached image"); }
    2525    img.onload = function () { log("FAIL: not cached image loaded"); }
    2626    img.src = "resources/boston.gif?nocache";
     
    2929    // Load an image from cache.
    3030    var imgFromCache = document.createElement('img');
    31     imgFromCache.onerror = function () { log("FAIL: error event for image from cache"); }
     31    imgFromCache.onerror = function () { log("PASS: error event for image from cache"); }
    3232    imgFromCache.onload = function () { log("FAIL: image from cache loaded"); }
    3333    imgFromCache.src = "resources/boston.gif";
  • trunk/Source/WebCore/ChangeLog

    r126193 r126194  
     12012-08-21  Mike West  <mkwst@chromium.org>
     2
     3        Blocking a resource via Content Security Policy should trigger an Error event.
     4        https://bugs.webkit.org/show_bug.cgi?id=89440
     5
     6        Reviewed by Jochen Eisinger.
     7
     8        If a CSP directive is violated, CachedResourceLoader will trigger a
     9        console error, and return a null image. In that case, we now dispatch
     10        an error on the relevant element.
     11
     12        Adjusted http/tests/security/contentSecurityPolicy/image-blocked.html
     13        and http/tests/security/contentSecurityPolicy/register-bypassing-scheme.html
     14        to test the new behavior.
     15
     16        This has the side-effect of also generating errors for images blocked by
     17        Chromium's content settings. Adjusted
     18        platform/chromium/permissionclient/image-permissions.html to agree with
     19        the new behavior.
     20
     21        * loader/ImageLoader.cpp:
     22        (WebCore::ImageLoader::updateFromElement):
     23
    1242012-08-21  Taiju Tsuiki  <tzik@chromium.org>
    225
  • trunk/Source/WebCore/loader/ImageLoader.cpp

    r123121 r126194  
    198198
    199199        // If we do not have an image here, it means that a cross-site
    200         // violation occurred.
    201         m_failedLoadURL = !newImage ? attr : AtomicString();
     200        // violation occurred, or that the image was blocked via Content
     201        // Security Policy. Either way, trigger an error event.
     202        if (!newImage) {
     203            m_failedLoadURL = attr;
     204            m_hasPendingErrorEvent = true;
     205            errorEventSender().dispatchEventSoon(this);
     206        } else
     207            m_failedLoadURL = AtomicString();
    202208    } else if (!attr.isNull()) {
    203209        // Fire an error event if the url is empty.
Note: See TracChangeset for help on using the changeset viewer.