Changeset 285823 in webkit


Ignore:
Timestamp:
Nov 15, 2021 12:21:10 PM (8 months ago)
Author:
Chris Dumez
Message:

Cross-Origin-Embedder-Policy: require-corp prevents loading of data URL images
https://bugs.webkit.org/show_bug.cgi?id=233131
<rdar://85236459>

Reviewed by Geoffrey Garen.

Source/WebCore:

When doing an initial data URL <img> load, we properly wouldn't perform a cross-origin resource policy check.
This is per the Fetch specification that says to use a scheme fetch [1] when the request URL is a data URL.
When the protocol is data, the scheme fetch algorithm would return a response without performing an HTTP
Fetch. The HTTP check [2] is the algorithm that actually performs a cross-origin resource policy check, at
step 7.

The issue with our implementation was that data URL <img> loads would perform a cross-origin resource policy
check in the case where the image is loaded from our memory cache, due to a check we had in
CachedResourceLoader::requestResource(). As a result, data URL <img> loads would fail when served from the
memory cache, when CORP is enforced. To address the issue and match the specification, we now disable this
CORP check when the request URL is a data URL.

[1] https://fetch.spec.whatwg.org/#scheme-fetch
[2] https://fetch.spec.whatwg.org/#concept-http-fetch

Test: http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html

  • loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::requestResource):

LayoutTests:

Add layout test coverage. This test is based on a reduce test case from Cameron McCormack.

  • http/wpt/html/cross-origin-embedder-policy/require-corp-data-url-expected.txt: Added.
  • http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html: Added.
  • http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html.headers: Added.
Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r285822 r285823  
     12021-11-15  Chris Dumez  <cdumez@apple.com>
     2
     3        `Cross-Origin-Embedder-Policy: require-corp` prevents loading of data URL images
     4        https://bugs.webkit.org/show_bug.cgi?id=233131
     5        <rdar://85236459>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        Add layout test coverage. This test is based on a reduce test case from Cameron McCormack.
     10
     11        * http/wpt/html/cross-origin-embedder-policy/require-corp-data-url-expected.txt: Added.
     12        * http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html: Added.
     13        * http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html.headers: Added.
     14
    1152021-11-15  Kiet Ho  <tho22@apple.com>
    216
  • trunk/Source/WebCore/ChangeLog

    r285822 r285823  
     12021-11-15  Chris Dumez  <cdumez@apple.com>
     2
     3        `Cross-Origin-Embedder-Policy: require-corp` prevents loading of data URL images
     4        https://bugs.webkit.org/show_bug.cgi?id=233131
     5        <rdar://85236459>
     6
     7        Reviewed by Geoffrey Garen.
     8
     9        When doing an initial data URL <img> load, we properly wouldn't perform a cross-origin resource policy check.
     10        This is per the Fetch specification that says to use a scheme fetch [1] when the request URL is a data URL.
     11        When the protocol is data, the scheme fetch algorithm would return a response without performing an HTTP
     12        Fetch. The HTTP check [2] is the algorithm that actually performs a cross-origin resource policy check, at
     13        step 7.
     14
     15        The issue with our implementation was that data URL <img> loads would perform a cross-origin resource policy
     16        check in the case where the image is loaded from our memory cache, due to a check we had in
     17        CachedResourceLoader::requestResource(). As a result, data URL <img> loads would fail when served from the
     18        memory cache, when CORP is enforced. To address the issue and match the specification, we now disable this
     19        CORP check when the request URL is a data URL.
     20
     21        [1] https://fetch.spec.whatwg.org/#scheme-fetch
     22        [2] https://fetch.spec.whatwg.org/#concept-http-fetch
     23
     24        Test: http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html
     25
     26        * loader/cache/CachedResourceLoader.cpp:
     27        (WebCore::CachedResourceLoader::requestResource):
     28
    1292021-11-15  Kiet Ho  <tho22@apple.com>
    230
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r284080 r285823  
    10151015            }
    10161016        }
    1017         if (request.options().mode == FetchOptions::Mode::NoCors) {
     1017        // Per the Fetch specification, the "cross-origin resource policy check" should only occur in the HTTP Fetch case (https://fetch.spec.whatwg.org/#concept-http-fetch).
     1018        // However, per https://fetch.spec.whatwg.org/#main-fetch, if the request URL's protocol is "data:", then we should perform a scheme fetch which would end up
     1019        // returning a response WITHOUT performing an HTTP fetch (and thus no CORP check).
     1020        if (request.options().mode == FetchOptions::Mode::NoCors && !url.protocolIsData()) {
    10181021            auto coep = document() ? document()->crossOriginEmbedderPolicy().value : CrossOriginEmbedderPolicyValue::UnsafeNone;
    10191022            if (auto error = validateCrossOriginResourcePolicy(coep, *request.origin(), request.resourceRequest().url(), resource->response(), ForNavigation::No))
    10201023                return makeUnexpected(WTFMove(*error));
    1021 
     1024        }
     1025        if (request.options().mode == FetchOptions::Mode::NoCors) {
    10221026            if (auto error = validateRangeRequestedFlag(request.resourceRequest(), resource->response()))
    10231027                return makeUnexpected(WTFMove(*error));
Note: See TracChangeset for help on using the changeset viewer.