- Revision
- 285892
- Author
- [email protected]
- Date
- 2021-11-16 14:58:57 -0800 (Tue, 16 Nov 2021)
Log Message
Cherry-pick r285823. rdar://problem/85236459
`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.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285823 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Added Paths
Diff
Modified: branches/safari-612.3.6.1-branch/LayoutTests/ChangeLog (285891 => 285892)
--- branches/safari-612.3.6.1-branch/LayoutTests/ChangeLog 2021-11-16 22:57:24 UTC (rev 285891)
+++ branches/safari-612.3.6.1-branch/LayoutTests/ChangeLog 2021-11-16 22:58:57 UTC (rev 285892)
@@ -1,3 +1,60 @@
+2021-11-16 Russell Epstein <[email protected]>
+
+ Cherry-pick r285823. rdar://problem/85236459
+
+ `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.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285823 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-11-15 Chris Dumez <[email protected]>
+
+ `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.
+
+ 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.
+
2021-11-15 Alan Coon <[email protected]>
Cherry-pick r285728. rdar://problem/85236241
Added: branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url-expected.txt (0 => 285892)
--- branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url-expected.txt (rev 0)
+++ branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url-expected.txt 2021-11-16 22:58:57 UTC (rev 285892)
@@ -0,0 +1,3 @@
+
+PASS Tests that loading of data URL images works when COEP: require-corp is used
+
Added: branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html (0 => 285892)
--- branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html (rev 0)
+++ branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html 2021-11-16 22:58:57 UTC (rev 285892)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<img src=""
+<script>
+async_test((t) => {
+ _onload_ = t.step_func(function() {
+ let img = document.querySelector("img");
+ let clone = img.cloneNode();
+ clone._onload_ = t.step_func_done(() => {
+ });
+ clone._onerror_ = t.unreached_func();
+ document.body.append(clone);
+ t.add_cleanup(() => {
+ img.remove();
+ clone.remove();
+ });
+ });
+}, "Tests that loading of data URL images works when COEP: require-corp is used");
+</script>
+</body>
+</html>
Added: branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html.headers (0 => 285892)
--- branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html.headers (rev 0)
+++ branches/safari-612.3.6.1-branch/LayoutTests/http/wpt/html/cross-origin-embedder-policy/require-corp-data-url.html.headers 2021-11-16 22:58:57 UTC (rev 285892)
@@ -0,0 +1 @@
+Cross-Origin-Embedder-Policy: require-corp
Modified: branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog (285891 => 285892)
--- branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog 2021-11-16 22:57:24 UTC (rev 285891)
+++ branches/safari-612.3.6.1-branch/Source/WebCore/ChangeLog 2021-11-16 22:58:57 UTC (rev 285892)
@@ -1,3 +1,74 @@
+2021-11-16 Russell Epstein <[email protected]>
+
+ Cherry-pick r285823. rdar://problem/85236459
+
+ `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.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@285823 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-11-15 Chris Dumez <[email protected]>
+
+ `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.
+
+ 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):
+
2021-11-15 Alan Coon <[email protected]>
Apply patch. rdar://problem/83971417
Modified: branches/safari-612.3.6.1-branch/Source/WebCore/loader/cache/CachedResourceLoader.cpp (285891 => 285892)
--- branches/safari-612.3.6.1-branch/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2021-11-16 22:57:24 UTC (rev 285891)
+++ branches/safari-612.3.6.1-branch/Source/WebCore/loader/cache/CachedResourceLoader.cpp 2021-11-16 22:58:57 UTC (rev 285892)
@@ -1013,11 +1013,15 @@
return makeUnexpected(WTFMove(*error));
}
}
- if (request.options().mode == FetchOptions::Mode::NoCors) {
+ // 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).
+ // 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
+ // returning a response WITHOUT performing an HTTP fetch (and thus no CORP check).
+ if (request.options().mode == FetchOptions::Mode::NoCors && !url.protocolIsData()) {
auto coep = document() ? document()->crossOriginEmbedderPolicy().value : CrossOriginEmbedderPolicyValue::UnsafeNone;
if (auto error = validateCrossOriginResourcePolicy(coep, *request.origin(), request.resourceRequest().url(), resource->response(), ForNavigation::No))
return makeUnexpected(WTFMove(*error));
-
+ }
+ if (request.options().mode == FetchOptions::Mode::NoCors) {
if (auto error = validateRangeRequestedFlag(request.resourceRequest(), resource->response()))
return makeUnexpected(WTFMove(*error));
}