Auto merge of #24340 - jdm:image-cache-cors, r=Manishearth

Allow using CORS filtered image responses as WebGL textures

More specifically, this makes the "is this image same origin?" check consider the CORS status of the original response, rather than relying on an overly-strict "is this image's response's URL same-origin with a particular global?" check. To do this, we make the image cache double keyed based on the requested URL as well as the requesting origin, and store the CORS status of the eventual response with the final image that eventually gets sent to the HTMLImageElement consumer.

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #24330 and fix #24368
- [x] There are tests for these changes

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24340)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-10-07 18:39:36 -04:00 committed by GitHub
commit 75548f40c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
109 changed files with 531 additions and 419 deletions

View file

@ -1,6 +1,62 @@
127.0.0.1 web-platform.test
127.0.0.1 www.web-platform.test
127.0.0.1 www1.web-platform.test
127.0.0.1 www2.web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.web-platform.test
127.0.0.1 xn--lve-6lad.web-platform.test
127.0.0.1 www1.xn--n8j6ds53lwwkrqhv28a.web-platform.test
127.0.0.1 xn--lve-6lad.www1.web-platform.test
127.0.0.1 www.www2.not-web-platform.test
127.0.0.1 www2.www2.not-web-platform.test
127.0.0.1 xn--lve-6lad.www.not-web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.not-web-platform.test
127.0.0.1 www.not-web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.www.not-web-platform.test
127.0.0.1 not-web-platform.test
127.0.0.1 www1.www.not-web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.www1.web-platform.test
127.0.0.1 www2.not-web-platform.test
127.0.0.1 www1.not-web-platform.test
127.0.0.1 www1.www1.web-platform.test
127.0.0.1 www2.xn--lve-6lad.web-platform.test
127.0.0.1 www1.xn--n8j6ds53lwwkrqhv28a.not-web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.xn--n8j6ds53lwwkrqhv28a.web-platform.test
127.0.0.1 www1.www2.web-platform.test
127.0.0.1 xn--lve-6lad.xn--n8j6ds53lwwkrqhv28a.not-web-platform.test
127.0.0.1 xn--lve-6lad.xn--lve-6lad.not-web-platform.test
127.0.0.1 www2.www1.not-web-platform.test
127.0.0.1 www2.xn--n8j6ds53lwwkrqhv28a.web-platform.test
127.0.0.1 www.xn--n8j6ds53lwwkrqhv28a.not-web-platform.test
127.0.0.1 web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.xn--lve-6lad.not-web-platform.test
127.0.0.1 xn--lve-6lad.www.web-platform.test
127.0.0.1 www.www.web-platform.test
127.0.0.1 www1.xn--lve-6lad.web-platform.test
127.0.0.1 xn--lve-6lad.www2.web-platform.test
127.0.0.1 www.www2.web-platform.test
127.0.0.1 www2.www.web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.www2.not-web-platform.test
127.0.0.1 www1.www.web-platform.test
127.0.0.1 www.xn--lve-6lad.web-platform.test
127.0.0.1 www.www.not-web-platform.test
127.0.0.1 xn--lve-6lad.xn--lve-6lad.web-platform.test
127.0.0.1 xn--lve-6lad.www1.not-web-platform.test
127.0.0.1 www1.www1.not-web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.xn--n8j6ds53lwwkrqhv28a.not-web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.www2.web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.www1.not-web-platform.test
127.0.0.1 www2.www2.web-platform.test
127.0.0.1 xn--lve-6lad.web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.www.web-platform.test
127.0.0.1 xn--lve-6lad.not-web-platform.test
127.0.0.1 www2.xn--n8j6ds53lwwkrqhv28a.not-web-platform.test
127.0.0.1 www2.xn--lve-6lad.not-web-platform.test
127.0.0.1 xn--n8j6ds53lwwkrqhv28a.xn--lve-6lad.web-platform.test
127.0.0.1 www1.xn--lve-6lad.not-web-platform.test
127.0.0.1 www1.web-platform.test
127.0.0.1 www.www1.web-platform.test
127.0.0.1 www2.web-platform.test
127.0.0.1 www.xn--lve-6lad.not-web-platform.test
127.0.0.1 www.web-platform.test
127.0.0.1 xn--lve-6lad.xn--n8j6ds53lwwkrqhv28a.web-platform.test
127.0.0.1 www1.www2.not-web-platform.test
127.0.0.1 www2.www1.web-platform.test
127.0.0.1 www.www1.not-web-platform.test
127.0.0.1 www.xn--n8j6ds53lwwkrqhv28a.web-platform.test
127.0.0.1 xn--lve-6lad.www2.not-web-platform.test
127.0.0.1 www2.www.not-web-platform.test

View file

@ -290999,6 +290999,12 @@
{}
]
],
"2dcontext/drawing-images-to-the-canvas/drawimage_crossorigin.sub.html": [
[
"2dcontext/drawing-images-to-the-canvas/drawimage_crossorigin.sub.html",
{}
]
],
"2dcontext/drawing-images-to-the-canvas/drawimage_html_image.html": [
[
"2dcontext/drawing-images-to-the-canvas/drawimage_html_image.html",
@ -447926,6 +447932,10 @@
"9f297cacdcd81bef7093f79ebed6992110dab4d7",
"support"
],
"2dcontext/drawing-images-to-the-canvas/drawimage_crossorigin.sub.html": [
"3d57d9f064bec7755a4f735e3fd12850109fcc15",
"testharness"
],
"2dcontext/drawing-images-to-the-canvas/drawimage_html_image.html": [
"a94cfdcd2d66fb667d458a4dff91532fbf3608de",
"testharness"

View file

@ -1,2 +0,0 @@
[floats-in-table-caption-001.html]
expected: FAIL

View file

@ -1,4 +0,0 @@
[inline-negative-margin-001.html]
[#container 1]
expected: FAIL

View file

@ -1,2 +1,2 @@
[abspos-float-with-inline-container.html]
expected: FAIL
expected: TIMEOUT

View file

@ -0,0 +1,2 @@
[white-space-002.xht]
expected: FAIL

View file

@ -0,0 +1,2 @@
[white-space-003.xht]
expected: FAIL

View file

@ -0,0 +1,2 @@
[line-height-204.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[mix-blend-mode-paragraph.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[background-repeat-round-roundup.xht]
expected: FAIL

View file

@ -254,9 +254,6 @@
[Matching font-stretch: '90%' should prefer '90% 100%' over '50% 80%']
expected: FAIL
[Matching font-weight: '400' should prefer '450 460' over '500']
expected: FAIL
[Matching font-style: 'normal' should prefer 'normal' over 'oblique 0deg']
expected: FAIL

View file

@ -1,2 +0,0 @@
[line-break-normal-018.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[line-break-strict-018.xht]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-001.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-002.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-003.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[text-transform-full-size-kana-004.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[trailing-ideographic-space-004.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[word-break-break-all-007.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[word-break-keep-all-006.html]
expected: FAIL

View file

@ -0,0 +1,2 @@
[css-transforms-3d-on-anonymous-block-001.html]
expected: FAIL

View file

@ -1,14 +0,0 @@
[HTMLMediaElement.html]
expected: CRASH
[controls on HTMLMediaElement in video must enqueue an attributeChanged reaction when replacing an existing attribute]
expected: FAIL
[controls on HTMLMediaElement in video must enqueue an attributeChanged reaction when adding a new attribute]
expected: FAIL
[controls on HTMLMediaElement in audio must enqueue an attributeChanged reaction when replacing an existing attribute]
expected: FAIL
[controls on HTMLMediaElement in audio must enqueue an attributeChanged reaction when adding a new attribute]
expected: FAIL

View file

@ -1,2 +0,0 @@
[contenttype_html.html]
expected: CRASH

View file

@ -1,2 +0,0 @@
[contenttype_xml.html]
expected: CRASH

View file

@ -6,7 +6,5 @@
[redirect-to-url-with-credentials]
expected: FAIL
[CORS Image loading after a redirect with a cross origin URL containing credentials]
expected: FAIL
[Frame loading after a redirect with an URL containing credentials]
expected: TIMEOUT

View file

@ -1,4 +0,0 @@
[traverse_the_history_2.html]
[Multiple history traversals, last would be aborted]
expected: FAIL

View file

@ -1,11 +1,7 @@
[form-submission-algorithm.html]
expected: TIMEOUT
[If form's firing submission events is true, then return; 'submit' event]
expected: FAIL
[If form's firing submission events is true, then return; 'invalid' event]
expected: FAIL
[Cannot navigate (after constructing the entry list)]
expected: TIMEOUT

View file

@ -1,9 +1,6 @@
[htmlanchorelement_noopener.html]
type: testharness
expected: ERROR
[Check that rel=noopener with target=_self does a normal load]
expected: FAIL
[Check that targeting of rel=noopener with a given name ignores an existing window with that name]
expected: NOTRUN

View file

@ -0,0 +1,5 @@
[promise-rejection-events-iframe.html]
expected: TIMEOUT
[delayed handling: promise is created in iframe and being rejected elsewhere]
expected: TIMEOUT

View file

@ -0,0 +1,5 @@
[promise-rejection-events-onerror.html]
expected: TIMEOUT
[Throwing inside an unhandledrejection handler invokes the error handler.]
expected: TIMEOUT

View file

@ -1,4 +0,0 @@
[cross-http.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-http.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-http origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-http.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-http origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-http.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-http origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-http.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-http origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-http.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-http origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-http.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-http origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.keep-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and keep-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.no-redirect.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and no-redirect redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to cross-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-http.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-http origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[same-https.swap-origin.http.html]
[Referrer Policy: Expects omitted for img-tag to same-https origin and swap-origin redirection from http context.]
expected: FAIL

View file

@ -1,3 +0,0 @@
[resource_TAO_multi_wildcard.html]
[redirectStart, redirectEnd, domainLookupStart, domainLookupEnd, connectStart, connectEnd, secureConnectionStart, requestStart, and responseStart -- should not be all returned as 0 when the HTTP response has multiple Timing-Allow-Origin header fields and the subsequent field value is separated by a comma, i.e. TAO algorithm passes]
expected: FAIL

View file

@ -0,0 +1,2 @@
[resource_timing_buffer_full_eventually.html]
expected: CRASH

View file

@ -95,3 +95,6 @@
[X SNR (19.538850442445742 dB) is not greater than or equal to 65.737. Got 19.538850442445742.]
expected: FAIL
[X SNR (19.538850442082673 dB) is not greater than or equal to 65.737. Got 19.538850442082673.]
expected: FAIL

View file

@ -1,4 +0,0 @@
[cross_origin.py]
[test_nested_cross_origin_iframe]
expected: FAIL

View file

@ -1,4 +0,0 @@
[iframe.py]
[test_source_origin[cross_origin\]]
expected: FAIL

View file

@ -1,5 +1,4 @@
[005.html]
expected: ERROR
[dedicated worker in shared worker in dedicated worker]
expected: FAIL

View file

@ -1,6 +1,5 @@
[003.html]
type: testharness
expected: ERROR
[shared]
expected: FAIL

View file

@ -0,0 +1,61 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function draw_and_read_image(img, should_throw) {
let c = document.createElement('canvas');
document.body.appendChild(c);
let ctx = c.getContext('2d');
ctx.drawImage(img, 0, 0);
function get_image_data() {
ctx.getImageData(0, 0, 4, 4);
}
if (should_throw) {
assert_throws_dom('SecurityError', get_image_data);
} else {
get_image_data();
}
document.body.removeChild(c);
}
async_test(t => {
let img = new Image();
img.src = "/images/green.png";
img.crossOrigin = "anonymous";
img.onload = t.step_func_done(() => {
draw_and_read_image(img, false);
});
img.onerror = t.unreached_func();
}, "Can get pixels of canvas with same origin image drawn");
async_test(t => {
let img = new Image();
img.src = "http://{{hosts[][www]}}:{{ports[http][0]}}/images/green.png?pipe=header(Access-Control-Allow-Origin,*)";
img.crossOrigin = "anonymous";
img.onload = t.step_func_done(() => {
draw_and_read_image(img, false);
});
img.onerror = t.unreached_func();
}, "Can get pixels of canvas with CORS enabled cross origin image drawn");
async_test(t => {
let img = new Image();
img.src = "http://{{hosts[][www]}}:{{ports[http][0]}}/images/green.png?pipe=header(Access-Control-Allow-Origin,*)";
img.onload = t.step_func_done(() => {
draw_and_read_image(img, true);
});
img.onerror = t.unreached_func();
}, "Can't get pixels of canvas with CORS enabled cross origin image drawn from non-CORS element");
async_test(t => {
let img = new Image();
img.src = "http://{{hosts[][www]}}:{{ports[http][0]}}/images/green.png";
img.onload = t.step_func_done(() => {
draw_and_read_image(img, true);
});
img.onerror = t.unreached_func();
}, "Can't get pixels of canvas with non-CORS enabled cross origin image drawn");
</script>